mirror of
https://github.com/modernw/App-Installer-For-Windows-8.x-Reset.git
synced 2026-06-19 05:40:12 +10:00
Update and fix bugs.
This commit is contained in:
@@ -0,0 +1,326 @@
|
||||
(function(global) {
|
||||
"use strict";
|
||||
/**
|
||||
* DomEvent 命名空间
|
||||
* @namespace DomEvent
|
||||
*/
|
||||
if (!global.DomEvent) global.DomEvent = {};
|
||||
/**
|
||||
* DOM 事件监控类型常量
|
||||
* @readonly
|
||||
* @enum {string}
|
||||
*/
|
||||
global.DomEvent.Types = Object.freeze({
|
||||
resize: "resize", // 尺寸变化
|
||||
position: "position", // 位置变化
|
||||
attribute: "attribute", // 属性变化
|
||||
child: "child", // 子节点变化
|
||||
text: "text", // 文本内容变化
|
||||
attach: "attach", // 节点附加到 DOM
|
||||
detach: "detach", // 节点从 DOM 移除
|
||||
visible: "visible", // 可见性变化
|
||||
scrollresize: "scrollresize" // 滚动尺寸变化
|
||||
});
|
||||
})(window);
|
||||
|
||||
(function(global) {
|
||||
"use strict";
|
||||
if (!global.DomEvent) global.DomEvent = {};
|
||||
if (!global.DomEvent.Types) throw new Error("DomEvent.Types must be defined first.");
|
||||
var Types = global.DomEvent.Types;
|
||||
/**
|
||||
* DOM 节点监控器
|
||||
* @namespace DomEvent.Monitor
|
||||
*/
|
||||
var Monitor = (function() {
|
||||
var registry = {}; // 存储所有节点及对应事件
|
||||
var polling = false; // 是否正在轮询
|
||||
var loopTimer = null; // 定时器
|
||||
var interval = 120; // 轮询间隔 ms
|
||||
// 初始化 registry,每种事件类型对应 Map
|
||||
Object.keys(Types).forEach(function(key) {
|
||||
registry[Types[key]] = new Map();
|
||||
});
|
||||
/**
|
||||
* 获取元素快照
|
||||
* @param {HTMLElement} el DOM 元素
|
||||
* @returns {Object} 元素快照对象
|
||||
*/
|
||||
function getSnapshot(el) {
|
||||
return {
|
||||
rect: el.getBoundingClientRect(),
|
||||
text: el.textContent,
|
||||
attr: el.attributes.length,
|
||||
child: el.childNodes.length,
|
||||
attached: document.body.contains(el),
|
||||
visible: !!(el.offsetWidth || el.offsetHeight),
|
||||
scrollWidth: el.scrollWidth,
|
||||
scrollHeight: el.scrollHeight
|
||||
};
|
||||
}
|
||||
/**
|
||||
* 判断元素快照是否发生变化
|
||||
* @param {string} type 事件类型
|
||||
* @param {Object} oldSnap 旧快照
|
||||
* @param {Object} newSnap 新快照
|
||||
* @returns {boolean} 是否发生变化
|
||||
*/
|
||||
function hasChanged(type, oldSnap, newSnap) {
|
||||
switch (type) {
|
||||
case Types.resize:
|
||||
return oldSnap.rect.width !== newSnap.rect.width ||
|
||||
oldSnap.rect.height !== newSnap.rect.height;
|
||||
case Types.position:
|
||||
return oldSnap.rect.top !== newSnap.rect.top ||
|
||||
oldSnap.rect.left !== newSnap.rect.left;
|
||||
case Types.attribute:
|
||||
return oldSnap.attr !== newSnap.attr;
|
||||
case Types.child:
|
||||
return oldSnap.child !== newSnap.child;
|
||||
case Types.text:
|
||||
return oldSnap.text !== newSnap.text;
|
||||
case Types.attach:
|
||||
return !oldSnap.attached && newSnap.attached;
|
||||
case Types.detach:
|
||||
return oldSnap.attached && !newSnap.attached;
|
||||
case Types.visible:
|
||||
return oldSnap.visible !== newSnap.visible;
|
||||
case Types.scrollresize:
|
||||
return oldSnap.scrollWidth !== newSnap.scrollWidth ||
|
||||
oldSnap.scrollHeight !== newSnap.scrollHeight;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 执行轮询检测
|
||||
* @private
|
||||
*/
|
||||
function poll() {
|
||||
Object.keys(registry).forEach(function(type) {
|
||||
registry[type].forEach(function(data, el) {
|
||||
if (!document.body.contains(el)) {
|
||||
registry[type].delete(el);
|
||||
return;
|
||||
}
|
||||
var newSnap = getSnapshot(el);
|
||||
if (hasChanged(type, data.snapshot, newSnap)) {
|
||||
data.snapshot = newSnap;
|
||||
data.handlers.forEach(function(handler) {
|
||||
try {
|
||||
handler.call(el, {
|
||||
type: type,
|
||||
rect: newSnap.rect,
|
||||
text: newSnap.text,
|
||||
visible: newSnap.visible
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 启动轮询
|
||||
* @private
|
||||
*/
|
||||
function start() {
|
||||
if (polling) return;
|
||||
polling = true;
|
||||
|
||||
function loop() {
|
||||
poll();
|
||||
loopTimer = setTimeout(loop, interval);
|
||||
}
|
||||
loop();
|
||||
}
|
||||
/**
|
||||
* 检查是否有节点存在,空则停止轮询
|
||||
* @private
|
||||
*/
|
||||
function stopIfEmpty() {
|
||||
var hasAny = Object.keys(registry).some(function(type) {
|
||||
return registry[type].size > 0;
|
||||
});
|
||||
if (!hasAny) {
|
||||
clearTimeout(loopTimer);
|
||||
polling = false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 监听指定元素的事件
|
||||
* @param {HTMLElement} el DOM 元素
|
||||
* @param {string} type 事件类型
|
||||
* @param {Function} handler 回调函数
|
||||
*/
|
||||
function observe(el, type, handler) {
|
||||
if (!registry[type])
|
||||
throw new Error("Unsupported type: " + type);
|
||||
|
||||
var map = registry[type];
|
||||
if (!map.has(el)) {
|
||||
map.set(el, {
|
||||
snapshot: getSnapshot(el),
|
||||
handlers: new Set()
|
||||
});
|
||||
}
|
||||
map.get(el).handlers.add(handler);
|
||||
start();
|
||||
}
|
||||
/**
|
||||
* 移除指定元素的事件监听
|
||||
* @param {HTMLElement} el DOM 元素
|
||||
* @param {string} type 事件类型
|
||||
* @param {Function} [handler] 回调函数,可选,未指定则移除所有
|
||||
*/
|
||||
function remove(el, type, handler) {
|
||||
if (!registry[type]) return;
|
||||
var map = registry[type];
|
||||
if (!map.has(el)) return;
|
||||
|
||||
if (handler) {
|
||||
map.get(el).handlers.delete(handler);
|
||||
} else {
|
||||
map.delete(el);
|
||||
}
|
||||
|
||||
if (map.has(el) && map.get(el).handlers.size === 0) {
|
||||
map.delete(el);
|
||||
}
|
||||
stopIfEmpty();
|
||||
}
|
||||
/**
|
||||
* 移除元素的所有事件监听
|
||||
* @param {HTMLElement} el DOM 元素
|
||||
*/
|
||||
function removeAll(el) {
|
||||
Object.keys(registry).forEach(function(type) {
|
||||
registry[type].delete(el);
|
||||
});
|
||||
stopIfEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空所有监听
|
||||
*/
|
||||
function clear() {
|
||||
Object.keys(registry).forEach(function(type) {
|
||||
registry[type].clear();
|
||||
});
|
||||
stopIfEmpty();
|
||||
}
|
||||
return {
|
||||
observe: observe,
|
||||
remove: remove,
|
||||
removeAll: removeAll,
|
||||
clear: clear
|
||||
};
|
||||
})();
|
||||
global.DomEvent.Monitor = Monitor;
|
||||
})(window);
|
||||
(function(global) {
|
||||
"use strict";
|
||||
if (!global.DomEvent) global.DomEvent = {};
|
||||
/**
|
||||
* DOM 事件工具方法
|
||||
* @namespace DomEvent.Utils
|
||||
*/
|
||||
var Utils = {};
|
||||
var eventStore = new WeakMap();
|
||||
/**
|
||||
* 添加原生事件监听
|
||||
* @param {HTMLElement} el DOM 元素
|
||||
* @param {string} type 事件类型
|
||||
* @param {Function} handler 回调函数
|
||||
* @param {boolean} [capture=false] 是否捕获
|
||||
*/
|
||||
Utils.add = function(el, type, handler, capture) {
|
||||
capture = !!capture;
|
||||
el.addEventListener(type, handler, capture);
|
||||
if (!eventStore.has(el)) eventStore.set(el, []);
|
||||
eventStore.get(el).push({
|
||||
type: type,
|
||||
handler: handler,
|
||||
capture: capture
|
||||
});
|
||||
};
|
||||
/**
|
||||
* 移除原生事件监听
|
||||
* @param {HTMLElement} el DOM 元素
|
||||
* @param {string} type 事件类型
|
||||
* @param {Function} handler 回调函数
|
||||
* @param {boolean} [capture=false] 是否捕获
|
||||
*/
|
||||
Utils.remove = function(el, type, handler, capture) {
|
||||
capture = !!capture;
|
||||
el.removeEventListener(type, handler, capture);
|
||||
if (!eventStore.has(el)) return;
|
||||
|
||||
var list = eventStore.get(el);
|
||||
eventStore.set(list.filter(function(item) {
|
||||
return !(item.type === type && item.handler === handler);
|
||||
}));
|
||||
};
|
||||
/**
|
||||
* 移除元素的所有事件监听
|
||||
* @param {HTMLElement} el DOM 元素
|
||||
*/
|
||||
Utils.removeAll = function(el) {
|
||||
if (!eventStore.has(el)) return;
|
||||
var list = eventStore.get(el);
|
||||
list.forEach(function(item) {
|
||||
el.removeEventListener(item.type, item.handler, item.capture);
|
||||
});
|
||||
eventStore.delete(el);
|
||||
};
|
||||
/**
|
||||
* 清空所有事件监听
|
||||
*/
|
||||
Utils.clearAll = function() {
|
||||
eventStore = new WeakMap();
|
||||
};
|
||||
/**
|
||||
* 节流函数
|
||||
* @param {Function} fn 原函数
|
||||
* @param {Number} delay 节流间隔 ms
|
||||
* @returns {Function} 包装后的函数
|
||||
*/
|
||||
Utils.throttle = function(fn, delay) {
|
||||
var last = 0;
|
||||
var timer = null;
|
||||
return function() {
|
||||
var context = this;
|
||||
var args = arguments;
|
||||
var now = Date.now();
|
||||
if (now - last >= delay) {
|
||||
last = now;
|
||||
fn.apply(context, args);
|
||||
} else if (!timer) {
|
||||
timer = setTimeout(function() {
|
||||
last = Date.now();
|
||||
timer = null;
|
||||
fn.apply(context, args);
|
||||
}, delay - (now - last));
|
||||
}
|
||||
};
|
||||
};
|
||||
/**
|
||||
* 防抖函数
|
||||
* @param {Function} fn 原函数
|
||||
* @param {Number} delay 防抖延迟 ms
|
||||
* @returns {Function} 包装后的函数
|
||||
*/
|
||||
Utils.debounce = function(fn, delay) {
|
||||
var timer = null;
|
||||
return function() {
|
||||
var context = this;
|
||||
var args = arguments;
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(function() {
|
||||
fn.apply(context, args);
|
||||
}, delay);
|
||||
};
|
||||
};
|
||||
global.DomEvent.Utils = Utils;
|
||||
})(window);
|
||||
@@ -127,21 +127,24 @@
|
||||
|
||||
function initLoaderPage() {
|
||||
var page = document.getElementById("page-load");
|
||||
var prefixs = ["ins", "reg", "sta"];
|
||||
var prefixs = ["ins", "reg", "sta", "upd"];
|
||||
var opdict = {
|
||||
ins: Package.manager.add,
|
||||
reg: Package.manager.register,
|
||||
sta: Package.manager.stage
|
||||
sta: Package.manager.stage,
|
||||
upd: Package.manager.update
|
||||
};
|
||||
var ingdict = {
|
||||
ins: strres.get("MANAGER_LOAD_INSTALL_ING"),
|
||||
reg: strres.get("MANAGER_LOAD_REGISTER_ING"),
|
||||
sta: strres.get("MANAGER_LOAD_STAGE_ING")
|
||||
sta: strres.get("MANAGER_LOAD_STAGE_ING"),
|
||||
upd: strres.get("MANAGER_LOAD_UPDATE_ING")
|
||||
};
|
||||
var sdict = {
|
||||
ins: strres.get("MANAGER_LOAD_INSTALL_SUCCEED"),
|
||||
reg: strres.get("MANAGER_LOAD_REGISTER_SUCCEED"),
|
||||
sta: strres.get("MANAGER_LOAD_STAGE_SUCCEED")
|
||||
sta: strres.get("MANAGER_LOAD_STAGE_SUCCEED"),
|
||||
upd: strres.get("MANAGER_LOAD_UPDATE_SUCCEED")
|
||||
}
|
||||
var explorer = external.Storage.Explorer;
|
||||
prefixs.forEach(function(prefix) {
|
||||
@@ -195,7 +198,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
if (prefix === "ins" || prefix === "sta") explorer.file(
|
||||
if (prefix === "ins" || prefix === "sta" || prefix === "upd") explorer.file(
|
||||
external.String.format("{0}|{1}|{2}|{3}",
|
||||
strres.get("MANAGER_LOAD_INS_OR_STA_FILTERDISPLAY"),
|
||||
"*.appx;*.appxbundle;*.msix;*.msixbundle",
|
||||
|
||||
@@ -225,39 +225,55 @@
|
||||
data.Properties.LogoBase64 === null || data.Properties.LogoBase64 === "" || data.Properties.LogoBase64 === void 0
|
||||
) {
|
||||
promises.push(function(item, arr) {
|
||||
var ispush = false;
|
||||
return Package.reader.readFromInstallLocation(item.InstallLocation, true).then(function(result) {
|
||||
try {
|
||||
arr.push(processData(result.json, item));
|
||||
ispush = true;
|
||||
} catch (e) {
|
||||
if (ispush) return;
|
||||
item.BackgroundColor = "transparent";
|
||||
arr.push(item);
|
||||
ispush = true;
|
||||
}
|
||||
}, function(result) {
|
||||
try {
|
||||
if (ispush) return;
|
||||
arr.push(processData(result.json, item));
|
||||
ispush = true;
|
||||
} catch (e) {
|
||||
if (ispush) return;
|
||||
item.BackgroundColor = "transparent";
|
||||
arr.push(item);
|
||||
ispush = true;
|
||||
}
|
||||
});
|
||||
}(data, newDatas));
|
||||
} else {
|
||||
promises.push(function(item, arr) {
|
||||
var ispush = false;
|
||||
return Package.reader.readFromInstallLocation(item.InstallLocation, false).then(function(result) {
|
||||
try {
|
||||
item.BackgroundColor = result.json.applications[0].BackgroundColor;
|
||||
arr.push(item);
|
||||
ispush = true;
|
||||
} catch (e) {
|
||||
if (ispush) return;
|
||||
item.BackgroundColor = "transparent";
|
||||
arr.push(item);
|
||||
ispush = true;
|
||||
}
|
||||
}, function(result) {
|
||||
try {
|
||||
if (ispush) return;
|
||||
item.BackgroundColor = result.json.applications[0].BackgroundColor;
|
||||
arr.push(item);
|
||||
ispush = true;
|
||||
} catch (e) {
|
||||
if (ispush) return;
|
||||
item.BackgroundColor = "transparent";
|
||||
arr.push(item);
|
||||
ispush = true;
|
||||
}
|
||||
});
|
||||
}(data, newDatas));
|
||||
@@ -383,6 +399,15 @@
|
||||
set.getKey("PackageManager:ShowFrameworks").set(showFrameworks.checked);
|
||||
});
|
||||
refreshButton.addEventListener("click", refreshAppList2);
|
||||
var appShellButton = new AppBar.Command();
|
||||
appShellButton.icon = "";
|
||||
appShellButton.label = "Applications";
|
||||
appShellButton.element.style.display = "none";
|
||||
appShellButton.addEventListener("click", function() {
|
||||
appbarControl.hide();
|
||||
external.Process.run("shell:::{4234d49b-0245-4df3-b780-3893943456e1}", "", 1, false, "");
|
||||
});
|
||||
appbarControl.add(appShellButton);
|
||||
appbarControl.add(refreshButton);
|
||||
refreshAppList2();
|
||||
var appDetailPage = document.getElementById("page-appinfo");
|
||||
|
||||
@@ -410,6 +410,8 @@
|
||||
if (pkgSupportVer.major == 6 && pkgSupportVer.minor == 3 && pkgSupportVer.build == 1) {
|
||||
if (pkginfo.identity.architecture & (4 | 8)) {
|
||||
ret.osminversionSupport = true;
|
||||
} else if (systemSupportVer.major >= 10) {
|
||||
ret.osminversionSupport = false;
|
||||
}
|
||||
} else {
|
||||
ret.osminversionSupport = true;
|
||||
|
||||
+287
-10
@@ -1,11 +1,51 @@
|
||||
/// <reference path="//Microsoft.WinJS.2.0/js/base.js" />
|
||||
(function(global) {
|
||||
"use strict";
|
||||
|
||||
function PromisePolyfill(pfExecutor) {
|
||||
/**
|
||||
* PromisePolyfill 构造函数。
|
||||
*
|
||||
* 模拟 WinJS.Promise 的构造形式:
|
||||
* new PromisePolyfill(init, oncancel)
|
||||
*
|
||||
* @constructor
|
||||
* @param {function(function(any):void,function(any):void,function(any):void):void} pfInit
|
||||
* Promise 初始化函数。
|
||||
* 该函数在 Promise 创建时立即执行,并接收三个回调:
|
||||
* - complete(value) : 完成 Promise
|
||||
* - error(reason) : 使 Promise 失败
|
||||
* - progress(value) : 发送进度通知(当前实现为占位)
|
||||
*
|
||||
* @param {function():void} [pfOnCancel]
|
||||
* Promise 取消回调。当调用 promise.cancel() 时执行。
|
||||
*
|
||||
* @example
|
||||
* var p = new PromisePolyfill(
|
||||
* function (complete, error, progress) {
|
||||
* setTimeout(function () {
|
||||
* complete("done");
|
||||
* }, 1000);
|
||||
* },
|
||||
* function () {
|
||||
* console.log("Promise canceled");
|
||||
* }
|
||||
* );
|
||||
*/
|
||||
function PromisePolyfill(pfInit, pfOnCancel) {
|
||||
/// <param name="pfInit" type="Function">
|
||||
/// Promise 初始化函数。
|
||||
/// 形参签名:
|
||||
/// function(
|
||||
/// complete : function(any):void,
|
||||
/// error : function(any):void,
|
||||
/// progress : function(any):void
|
||||
/// )
|
||||
/// </param>
|
||||
/// <param name="pfOnCancel" type="Function" optional="true">
|
||||
/// Promise 取消回调函数。当 promise.cancel() 被调用时执行。
|
||||
/// </param>
|
||||
var swState = "pending"; // "fulfilled" | "rejected"
|
||||
var vValue = undefined;
|
||||
var aHandlers = [];
|
||||
var pfOnCancel = null;
|
||||
|
||||
function invokeHandlers() {
|
||||
if (swState === "pending") return;
|
||||
@@ -20,7 +60,11 @@
|
||||
aHandlers.push(hHandler);
|
||||
return;
|
||||
}
|
||||
var pfCallback = swState === "fulfilled" ? hHandler.onFulfilled : hHandler.onRejected;
|
||||
|
||||
var pfCallback = swState === "fulfilled" ?
|
||||
hHandler.onFulfilled :
|
||||
hHandler.onRejected;
|
||||
|
||||
if (!pfCallback) {
|
||||
if (swState === "fulfilled") {
|
||||
hHandler.resolve(vValue);
|
||||
@@ -29,6 +73,7 @@
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
var vResult = pfCallback(vValue);
|
||||
hHandler.resolve(vResult);
|
||||
@@ -39,7 +84,10 @@
|
||||
|
||||
function resolve(vResult) {
|
||||
try {
|
||||
if (vResult === self) throw new TypeError("A promise cannot be resolved with itself.");
|
||||
|
||||
if (vResult === self)
|
||||
throw new TypeError("A promise cannot be resolved with itself.");
|
||||
|
||||
if (vResult && (typeof vResult === "object" || typeof vResult === "function")) {
|
||||
var pfThen = vResult.then;
|
||||
if (typeof pfThen === "function") {
|
||||
@@ -47,9 +95,11 @@
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
swState = "fulfilled";
|
||||
vValue = vResult;
|
||||
invokeHandlers();
|
||||
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
@@ -58,56 +108,105 @@
|
||||
function reject(vReason) {
|
||||
swState = "rejected";
|
||||
vValue = vReason;
|
||||
|
||||
if (typeof PromisePolyfill.onerror === "function") {
|
||||
PromisePolyfill.onerror(vReason);
|
||||
}
|
||||
|
||||
invokeHandlers();
|
||||
}
|
||||
|
||||
// WinJS Promise progress(当前仅占位)
|
||||
function progress(vProgress) {
|
||||
// 当前 polyfill 未实现 progress 传播
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
try {
|
||||
pfExecutor(resolve, reject, function(pfCancel) {
|
||||
pfOnCancel = pfCancel;
|
||||
});
|
||||
if (typeof pfInit === "function") {
|
||||
pfInit(resolve, reject, progress);
|
||||
}
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
|
||||
this.then = function(pfOnFulfilled, pfOnRejected) {
|
||||
|
||||
return new PromisePolyfill(function(resolve, reject) {
|
||||
|
||||
handle({
|
||||
onFulfilled: pfOnFulfilled,
|
||||
onRejected: pfOnRejected,
|
||||
resolve: resolve,
|
||||
reject: reject
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
this["catch"] = function(pfOnRejected) {
|
||||
return this.then(null, pfOnRejected);
|
||||
};
|
||||
|
||||
this.done = function(pfOnFulfilled, pfOnRejected) {
|
||||
|
||||
this.then(pfOnFulfilled, pfOnRejected)["catch"](function(ex) {
|
||||
setTimeout(function() { throw ex; }, 0);
|
||||
|
||||
setTimeout(function() {
|
||||
throw ex;
|
||||
}, 0);
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
this.cancel = function() {
|
||||
|
||||
if (pfOnCancel) {
|
||||
try { pfOnCancel(); } catch (ex) {}
|
||||
try {
|
||||
pfOnCancel();
|
||||
} catch (ex) {}
|
||||
}
|
||||
|
||||
reject(new Error("Promise was canceled"));
|
||||
|
||||
};
|
||||
|
||||
this._oncancel = pfOnCancel;
|
||||
this._state = swState;
|
||||
this._value = vValue;
|
||||
}
|
||||
/**
|
||||
* 检查对象是否为 PromisePolyfill 实例
|
||||
* @param {any} vObj 待检查对象
|
||||
* @returns {boolean} 是否为 PromisePolyfill 实例
|
||||
*/
|
||||
PromisePolyfill.is = function(vObj) {
|
||||
return vObj instanceof PromisePolyfill;
|
||||
};
|
||||
/**
|
||||
* 创建一个已完成的 PromisePolyfill
|
||||
* @param {any} vValue 要返回的值
|
||||
* @returns {PromisePolyfill} 已完成的 PromisePolyfill
|
||||
*/
|
||||
PromisePolyfill.resolve = function(vValue) {
|
||||
return new PromisePolyfill(function(resolve) { resolve(vValue); });
|
||||
};
|
||||
/**
|
||||
* 创建一个已拒绝的 PromisePolyfill
|
||||
* @param {any} vReason 拒绝原因
|
||||
* @returns {PromisePolyfill} 已拒绝的 PromisePolyfill
|
||||
*/
|
||||
PromisePolyfill.reject = function(vReason) {
|
||||
return new PromisePolyfill(function(resolve, reject) { reject(vReason); });
|
||||
};
|
||||
/**
|
||||
* 等待所有 Promise 完成
|
||||
* @param {Array<PromisePolyfill|any>} aPromises 待处理的 Promise 或普通值数组
|
||||
* @returns {PromisePolyfill<Array<any>>} 返回包含所有结果的 Promise
|
||||
*/
|
||||
PromisePolyfill.all = function(aPromises) {
|
||||
return new PromisePolyfill(function(resolve, reject) {
|
||||
var nRemaining = aPromises.length;
|
||||
@@ -126,6 +225,11 @@
|
||||
}
|
||||
});
|
||||
};
|
||||
/**
|
||||
* 竞速 Promise,谁先完成就返回谁的结果
|
||||
* @param {Array<PromisePolyfill|any>} aPromises 待处理的 Promise 或普通值数组
|
||||
* @returns {PromisePolyfill<any>} 最先完成的 Promise 的值
|
||||
*/
|
||||
PromisePolyfill.race = function(aPromises) {
|
||||
return new PromisePolyfill(function(resolve, reject) {
|
||||
for (var i = 0; i < aPromises.length; i++) {
|
||||
@@ -133,9 +237,19 @@
|
||||
}
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Promise join,同 all
|
||||
* @param {Array<PromisePolyfill|any>} aPromises 待处理的 Promise 或普通值数组
|
||||
* @returns {PromisePolyfill<Array<any>>} 返回包含所有结果的 Promise
|
||||
*/
|
||||
PromisePolyfill.join = function(aPromises) {
|
||||
return PromisePolyfill.all(aPromises);
|
||||
};
|
||||
/**
|
||||
* 任意 Promise 完成即返回
|
||||
* @param {Array<PromisePolyfill|any>} aPromises 待处理的 Promise 或普通值数组
|
||||
* @returns {PromisePolyfill<any>} 最先完成的 Promise 的值,若都失败则 reject 一个错误数组
|
||||
*/
|
||||
PromisePolyfill.any = function(aPromises) {
|
||||
return new PromisePolyfill(function(resolve, reject) {
|
||||
var nRemaining = aPromises.length;
|
||||
@@ -156,6 +270,12 @@
|
||||
}
|
||||
});
|
||||
};
|
||||
/**
|
||||
* 给 Promise 添加超时处理
|
||||
* @param {PromisePolyfill|any} pPromise 要处理的 Promise
|
||||
* @param {number} nMilliseconds 超时时间(毫秒)
|
||||
* @returns {PromisePolyfill<any>} 超时或原 Promise 完成后 resolve/reject
|
||||
*/
|
||||
PromisePolyfill.timeout = function(pPromise, nMilliseconds) {
|
||||
return new PromisePolyfill(function(resolve, reject) {
|
||||
var hTimer = setTimeout(function() {
|
||||
@@ -179,6 +299,12 @@
|
||||
PromisePolyfill.wrapError = function(vError) {
|
||||
return PromisePolyfill.reject(vError);
|
||||
};
|
||||
/**
|
||||
* 将数组的每个值依次执行回调
|
||||
* @param {Array<any>} aValues 数组
|
||||
* @param {function(any, number): any | PromisePolyfill<any>} pfCallback 回调函数
|
||||
* @returns {PromisePolyfill<Array<any>>} 所有回调完成的结果数组
|
||||
*/
|
||||
PromisePolyfill.thenEach = function(aValues, pfCallback) {
|
||||
var aPromises = [];
|
||||
for (var i = 0; i < aValues.length; i++) {
|
||||
@@ -187,10 +313,20 @@
|
||||
return PromisePolyfill.all(aPromises);
|
||||
};
|
||||
var hListeners = {};
|
||||
/**
|
||||
* 全局事件注册
|
||||
* @param {string} sType 事件类型
|
||||
* @param {function(any):void} pfHandler 回调函数
|
||||
*/
|
||||
PromisePolyfill.addEventListener = function(sType, pfHandler) {
|
||||
if (!hListeners[sType]) hListeners[sType] = [];
|
||||
hListeners[sType].push(pfHandler);
|
||||
};
|
||||
/**
|
||||
* 全局事件移除
|
||||
* @param {string} sType 事件类型
|
||||
* @param {function(any):void} pfHandler 回调函数
|
||||
*/
|
||||
PromisePolyfill.removeEventListener = function(sType, pfHandler) {
|
||||
if (!hListeners[sType]) return;
|
||||
var aList = hListeners[sType];
|
||||
@@ -201,6 +337,11 @@
|
||||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* 全局事件派发
|
||||
* @param {string} sType 事件类型
|
||||
* @param {any} vDetail 事件详情
|
||||
*/
|
||||
PromisePolyfill.dispatchEvent = function(sType, vDetail) {
|
||||
if (!hListeners[sType]) return;
|
||||
var aList = hListeners[sType].slice();
|
||||
@@ -210,6 +351,142 @@
|
||||
};
|
||||
PromisePolyfill.supportedForProcessing = true;
|
||||
PromisePolyfill.onerror = null;
|
||||
/**
|
||||
* 创建一个在指定毫秒数后完成的 Promise。
|
||||
*
|
||||
* @param {number} nMilliseconds
|
||||
* 延迟时间(毫秒)。
|
||||
*
|
||||
* @returns {PromisePolyfill}
|
||||
* 返回 Promise,在延迟结束后完成。
|
||||
*
|
||||
* @example
|
||||
* WinJS.Promise.delay(500).then(function () {
|
||||
* console.log("500ms elapsed");
|
||||
* });
|
||||
*/
|
||||
PromisePolyfill.delay = function(nMilliseconds) {
|
||||
/// <param name="nMilliseconds" type="Number">
|
||||
/// 延迟时间(毫秒)。
|
||||
/// </param>
|
||||
/// <returns type="PromisePolyfill"/>
|
||||
var hTimer = null;
|
||||
return new PromisePolyfill(
|
||||
function(complete, error, progress) {
|
||||
hTimer = setTimeout(function() {
|
||||
complete();
|
||||
}, nMilliseconds);
|
||||
},
|
||||
function() {
|
||||
if (hTimer !== null) {
|
||||
clearTimeout(hTimer);
|
||||
hTimer = null;
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
/**
|
||||
* 创建一个循环执行的 Promise,类似 setInterval。
|
||||
*
|
||||
* 该 Promise 不会自动完成,除非:
|
||||
* 1. 调用 promise.cancel()
|
||||
* 2. callback 抛出异常
|
||||
*
|
||||
* @param {function(): (any|PromisePolyfill|WinJS.Promise)} pfCallback
|
||||
* 每次循环执行的回调函数。可以返回 Promise。
|
||||
*
|
||||
* @param {number} nDelay
|
||||
* 每次执行之间的间隔时间(毫秒)。
|
||||
*
|
||||
* @returns {PromisePolyfill}
|
||||
* 返回 Promise 对象,可通过 cancel() 停止循环。
|
||||
*
|
||||
* @example
|
||||
* var p = WinJS.Promise.interval(function () {
|
||||
* console.log("tick");
|
||||
* }, 1000);
|
||||
*
|
||||
* setTimeout(function () {
|
||||
* p.cancel();
|
||||
* }, 5000);
|
||||
*/
|
||||
PromisePolyfill.interval = function(pfCallback, nDelay) {
|
||||
|
||||
/// <param name="pfCallback" type="Function">
|
||||
/// 每次间隔执行的函数。可以返回 Promise。
|
||||
/// </param>
|
||||
/// <param name="nDelay" type="Number">
|
||||
/// 执行间隔(毫秒)。
|
||||
/// </param>
|
||||
/// <returns type="PromisePolyfill"/>
|
||||
|
||||
var bCanceled = false;
|
||||
|
||||
return new PromisePolyfill(
|
||||
|
||||
function(complete, error, progress) {
|
||||
|
||||
function loop() {
|
||||
|
||||
if (bCanceled) {
|
||||
complete();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
var vResult = pfCallback();
|
||||
|
||||
if (vResult && typeof vResult.then === "function") {
|
||||
|
||||
vResult.then(waitNext, error);
|
||||
|
||||
} else {
|
||||
|
||||
waitNext();
|
||||
|
||||
}
|
||||
|
||||
} catch (ex) {
|
||||
|
||||
error(ex);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function waitNext() {
|
||||
|
||||
if (bCanceled) {
|
||||
complete();
|
||||
return;
|
||||
}
|
||||
|
||||
setTimeout(loop, nDelay);
|
||||
|
||||
}
|
||||
|
||||
loop();
|
||||
|
||||
},
|
||||
|
||||
function() {
|
||||
|
||||
bCanceled = true;
|
||||
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
};
|
||||
if (typeof global.Promise !== "undefined") {
|
||||
global.Promise.delay = PromisePolyfill.delay;
|
||||
global.Promise.interval = PromisePolyfill.interval;
|
||||
}
|
||||
if (typeof global.WinJS !== "undefined" && typeof global.WinJS.Promise !== "undefined") {
|
||||
global.WinJS.Promise.delay = PromisePolyfill.delay;
|
||||
global.WinJS.Promise.interval = PromisePolyfill.interval;
|
||||
}
|
||||
if (typeof global.Promise !== "undefined") {
|
||||
var p = global.Promise;
|
||||
if (!p.join) p.join = p.all;
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
(function(global) {
|
||||
var strres = external.StringResources;
|
||||
var conf = external.Config.current;
|
||||
var set = conf.getSection("Settings");
|
||||
|
||||
function createLocalizedCompare(locale) {
|
||||
return function(a, b) {
|
||||
a = a || "";
|
||||
b = b || "";
|
||||
|
||||
return a.localeCompare(b, locale, {
|
||||
numeric: true, // 2 < 10
|
||||
sensitivity: "base" // 不区分大小写 / 重音
|
||||
});
|
||||
};
|
||||
}
|
||||
var pagemgr = new PageManager();
|
||||
OnLoad.add(function() {
|
||||
var mgr = Package.manager;
|
||||
var nstr = Bridge.NString;
|
||||
var datasrc = new DataView.DataSource();
|
||||
datasrc.setKeySelector(function(item) {
|
||||
if (item === null || item === void 0) return null;
|
||||
return Bridge.String.tolower(Bridge.String.trim(item.Identity.FullName));
|
||||
});
|
||||
var themeColor = Bridge.UI.themeColor;
|
||||
var appbar = document.getElementById("appBar");
|
||||
var appbarControl = new AppBar.AppBar(appbar);
|
||||
appbarControl.enabled = false;
|
||||
pagemgr.register("reader", document.getElementById("tag-reader"), document.getElementById("page-reader"));
|
||||
pagemgr.go("reader");
|
||||
});
|
||||
})(this);
|
||||
Reference in New Issue
Block a user