本文整理汇总了TypeScript中common/util/watcher.Watcher类的典型用法代码示例。如果您正苦于以下问题:TypeScript Watcher类的具体用法?TypeScript Watcher怎么用?TypeScript Watcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Watcher类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
export default function(watcher: Watcher) {
watcher.on(actions.manageCave, async (store, action) => {
const { caveId } = action.payload;
const { cave } = await mcall(messages.FetchCave, {
caveId,
});
const widgetParams = {
cave,
};
const { game, upload } = cave;
const openModal = actions.openModal(
modals.manageCave.make({
wind: "root",
title: `${game.title} - ${formatUploadTitle(upload)}`,
message: "",
widgetParams,
})
);
store.dispatch(openModal);
});
}
示例2: function
export default function(watcher: Watcher) {
watcher.on(actions.clearBrowsingDataRequest, async (store, action) => {
const { wind } = action.payload;
const response = await promisedModal(
store,
modals.clearBrowsingData.make({
wind,
title: ["preferences.advanced.clear_browsing_data"],
message: "",
buttons: [
{
label: ["prompt.clear_browsing_data.clear"],
id: "modal-clear-data",
action: "widgetResponse",
},
"cancel",
],
widgetParams: {},
})
);
if (!response) {
// modal was closed
return;
}
store.dispatch(
actions.clearBrowsingData({
cache: response.cache,
cookies: response.cookies,
})
);
});
}
示例3: function
export default function(watcher: Watcher) {
watcher.on(actions.boot, async (store, action) => {
await initialSetup(store, { retry: false });
});
watcher.on(actions.retrySetup, async (store, action) => {
await initialSetup(store, { retry: true });
});
watcher.on(actions.packageGotVersionPrefix, async (store, action) => {
const { name } = action.payload;
if (name === "butler") {
await refreshButlerd(store);
}
});
}
示例4: function
export default function(watcher: Watcher) {
watcher.on(actions.showDownloadError, async (store, action) => {
const { id } = action.payload;
const { downloads } = store.getState();
const item = downloads.items[id];
if (!item) {
logger.warn(
`can't show download error for item we don't know about! (${id})`
);
return;
}
const operateLogPath = join(item.stagingFolder, "operate-log.json");
let log = "<missing log>";
try {
log = await sf.readFile(operateLogPath, { encoding: "utf8" });
} catch (e) {
logger.warn(`could not read log: ${e.stack}`);
}
await showInstallErrorModal({
store,
e: getDownloadError(item),
log,
game: item.game,
retryAction: () => actions.retryDownload({ id }),
stopAction: () => actions.discardDownload({ id }),
});
});
}
示例5: function
export default function(watcher: Watcher) {
watcher.on(actions.viewCaveDetails, async (store, action) => {
const { caveId } = action.payload;
const { cave } = await mcall(messages.FetchCave, { caveId });
store.dispatch(
actions.openModal(
modals.exploreJson.make({
wind: "root",
title: `Cave details for ${cave.game ? cave.game.title : "?"}`,
message: "Local cave data:",
widgetParams: {
data: cave,
},
buttons: [
{
label: ["prompt.action.ok"],
},
],
})
)
);
});
}
示例6: function
export default function(watcher: Watcher) {
watcher.on(actions.gameUpdateAvailable, async (store, action) => {
const { manualGameUpdates = false } = store.getState().preferences;
if (manualGameUpdates) {
// update will appear as main action
return;
}
const { update } = action.payload;
if (!update.direct) {
// update will appear as main action
return;
}
store.dispatch(
actions.queueGameUpdate({ update, choice: update.choices[0] })
);
});
watcher.on(actions.queueGameUpdate, async (store, action) => {
const { update, choice } = action.payload;
const { game } = update;
const { upload, build } = choice;
await mcall(messages.InstallQueue, {
caveId: update.caveId,
game,
upload,
build,
reason: DownloadReason.Update,
queueDownload: true,
});
store.dispatch(actions.downloadQueued({}));
});
watcher.on(actions.queueAllGameUpdates, async (store, action) => {
const { updates } = store.getState().gameUpdates;
for (const update of Object.values(updates)) {
if (update.direct) {
store.dispatch(
actions.queueGameUpdate({ update, choice: update.choices[0] })
);
}
}
});
}
示例7: function
export default function(watcher: Watcher) {
watcher.on(actions.boot, async (store, action) => {
// load initial locales
const configPayload = await readFile(localesConfigPath);
const config = JSON.parse(configPayload);
store.dispatch(actions.localesConfigLoaded(config));
await loadLocale(store, "en");
});
watcher.onDebounced(
actions.queueLocaleDownload,
2000,
async (store, action) => {
let { lang, implicit } = action.payload;
const downloading = store.getState().i18n.downloading;
if (downloading[lang]) {
return;
}
store.dispatch(actions.localeDownloadStarted({ lang }));
let resources = {};
try {
resources = await doDownloadLocale(lang, resources, { implicit });
} catch (e) {
logger.warn(`Failed downloading locale for ${lang}: ${e.message}`);
} finally {
commitLocale(store, lang, resources);
}
}
);
watcher.on(actions.languageChanged, async (store, action) => {
const { lang } = action.payload;
await loadLocale(store, lang);
});
watcher.on(actions.reloadLocales, async (store, action) => {
const { lang } = store.getState().i18n;
logger.info(`Reloading locales...`);
await loadLocale(store, lang);
});
}
示例8: function
export default function(watcher: Watcher) {
watcher.onDebounced(
actions.tabsChanged,
tabAutoSaveThreshold,
async (store, action) => {
await saveTabs(store);
}
);
}
示例9: function
export default function(watcher: Watcher) {
watcher.on(actions.initiatePurchase, async (store, action) => {
const { game } = action.payload;
const purchaseUrl = game.url + "/purchase";
const loginPurchaseUrl = buildLoginAndReturnUrl(purchaseUrl);
store.dispatch(actions.navigate({ wind: "root", url: loginPurchaseUrl }));
});
}
示例10: function
export default function(watcher: Watcher) {
watcher.on(actions.probeCave, async (store, action) => {
const { caveId } = action.payload;
const caveLogPath = paths.caveLogPath(caveId);
logger.info(`Opening cave log path ${caveLogPath}`);
shell.openItem(caveLogPath);
});
}