本文整理汇总了TypeScript中common/util/watcher.Watcher.on方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Watcher.on方法的具体用法?TypeScript Watcher.on怎么用?TypeScript Watcher.on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common/util/watcher.Watcher
的用法示例。
在下文中一共展示了Watcher.on方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
export default function(watcher: Watcher) {
watcher.on(actions.updatePreferences, async (store, action) => {
const selector = getSelector(store);
selector(store.getState().preferences);
});
}
示例2: function
export default function(watcher: Watcher) {
watcher.on(actions.commandGoBack, async (store, action) => {
const { wind } = action.payload;
const { tab } = store.getState().winds[wind].navigation;
store.dispatch(actions.tabGoBack({ wind, tab }));
});
watcher.on(actions.commandGoForward, async (store, action) => {
const { wind } = action.payload;
const { tab } = store.getState().winds[wind].navigation;
store.dispatch(actions.tabGoForward({ wind, tab }));
});
watcher.on(actions.commandReload, async (store, action) => {
const { wind } = action.payload;
const { tab } = store.getState().winds[wind].navigation;
store.dispatch(actions.tabReloaded({ wind, tab }));
});
watcher.on(actions.openTabBackHistory, async (store, action) => {
const { wind, tab, clientX, clientY } = action.payload;
const space = Space.fromStore(store, wind, tab);
if (!space.canGoBack()) {
return;
}
let startIndex = 0;
let endIndex = space.currentIndex();
if (endIndex - startIndex > shownHistoryItems) {
startIndex = endIndex - shownHistoryItems;
}
const template = makeHistoryTemplate({
i18n: store.getState().i18n,
wind,
space,
startIndex,
endIndex,
dir: -1,
});
store.dispatch(
actions.popupContextMenu({ wind, clientX, clientY, template })
);
});
watcher.on(actions.openTabForwardHistory, async (store, action) => {
const { wind, tab, clientX, clientY } = action.payload;
const space = Space.fromStore(store, wind, tab);
if (!space.canGoForward()) {
return;
}
let startIndex = space.currentIndex() + 1;
let endIndex = space.history().length;
if (endIndex - startIndex > shownHistoryItems) {
endIndex = startIndex + shownHistoryItems;
}
const template = makeHistoryTemplate({
i18n: store.getState().i18n,
wind,
space,
startIndex,
endIndex,
dir: 1,
});
store.dispatch(
actions.popupContextMenu({ wind, clientX, clientY, template })
);
});
watcher.on(actions.navigateTab, async (store, action) => {
const { background } = action.payload;
if (background) {
store.dispatch(actions.navigate(action.payload));
} else {
const { background, ...rest } = action.payload;
store.dispatch(
actions.evolveTab({
...rest,
replace: false,
})
);
}
});
watcher.on(actions.navigate, async (store, action) => {
let { url, resource, wind, background, replace } = action.payload;
logger.debug(`Navigating to ${url} ${background ? "(in background)" : ""}`);
if (opensInWindow(url)) {
store.dispatch(
actions.openWind({
initialURL: url,
role: "secondary",
})
);
return;
}
//.........这里部分代码省略.........
示例3: function
export default function(watcher: Watcher) {
watcher.on(actions.loginWithPassword, async (store, action) => {
const { username, password } = action.payload;
logger.info(`Attempting password login for user ${username}`);
store.dispatch(actions.attemptLogin({}));
try {
// integration tests for the integration test goddess
if (username === "#api-key") {
logger.info(`Doing direct API key login...`);
const t1 = Date.now();
const { profile } = await withTimeout(
"API key login",
LOGIN_TIMEOUT,
mcall(messages.ProfileLoginWithAPIKey, {
apiKey: password,
})
);
const t2 = Date.now();
logger.debug(
`ProfileLoginWithAPIKey call succeeded in ${elapsed(t1, t2)}`
);
await loginSucceeded(store, profile);
return;
}
logger.info(`Doing username/password login...`);
const t1 = Date.now();
const { profile, cookie } = await mcall(
messages.ProfileLoginWithPassword,
{
username,
password,
},
client => {
logger.debug(`Setting up handlers for TOTP & captcha`);
client.on(
messages.ProfileRequestCaptcha,
async ({ recaptchaUrl }) => {
logger.info(`Showing captcha`);
const modalRes = await promisedModal(
store,
modals.recaptchaInput.make({
wind: "root",
title: "Captcha",
message: "",
widgetParams: {
url: recaptchaUrl || urls.itchio + "/captcha",
},
fullscreen: true,
})
);
if (modalRes) {
logger.info(`Captcha solved`);
return { recaptchaResponse: modalRes.recaptchaResponse };
} else {
// abort
logger.info(`Captcha cancelled`);
return { recaptchaResponse: null };
}
}
);
client.on(messages.ProfileRequestTOTP, async () => {
logger.info(`Showing TOTP`);
const modalRes = await promisedModal(
store,
modals.twoFactorInput.make({
wind: "root",
title: ["login.two_factor.title"],
message: "",
widgetParams: {
username,
},
})
);
if (modalRes) {
logger.info(`TOTP answered`);
return { code: modalRes.totpCode };
} else {
// abort
logger.info(`TOTP cancelled`);
return { code: null };
}
});
}
);
if (cookie) {
try {
logger.info(`Setting cookies...`);
await setCookie(profile, cookie);
} catch (e) {
logger.error(`Could not set cookie: ${e.stack}`);
}
}
//.........这里部分代码省略.........
示例4: function
export default function(watcher: Watcher) {
watcher.on(actions.tick, async (store, action) => {
const rs = store.getState();
const { nextComponentsUpdateCheck } = rs.systemTasks;
let componentCheckPastDue = Date.now() > nextComponentsUpdateCheck;
let setupDone = rs.setup.done;
let shouldUpdateNow = setupDone && componentCheckPastDue;
if (!shouldUpdateNow) {
return;
}
rescheduleComponentsUpdate(store);
store.dispatch(actions.checkForComponentUpdates({}));
});
watcher.on(actions.checkForComponentUpdates, async (store, action) => {
rescheduleComponentsUpdate(store);
await manager.upgrade();
});
watcher.on(actions.relaunchRequest, async (store, action) => {
const rs = store.getState();
const pkg = rs.broth.packages[rs.system.appName];
if (pkg.stage !== "need-restart") {
return;
}
const version = pkg.availableVersion;
const restart = t(rs.i18n, ["prompt.self_update_ready.action.restart"]);
store.dispatch(
actions.openModal(
modalWidgets.naked.make({
window: "root",
title: ["prompt.self_update.title", { version }],
message: ["prompt.self_update_ready.message", { restart }],
buttons: [
{
label: ["prompt.self_update_ready.action.restart"],
action: actions.relaunch({}),
},
{
label: ["prompt.self_update_ready.action.snooze"],
action: actions.closeModal({ window: "root" }),
},
],
widgetParams: null,
})
)
);
});
watcher.on(actions.relaunch, async (store, action) => {
const rs = store.getState();
const pkg = rs.broth.packages["itch-setup"];
if (pkg.stage !== "idle") {
logger.warn(`itch-setup: wanted pkg stage idle but got '${pkg.stage}'`);
return;
}
const prefix = pkg.versionPrefix;
if (!prefix) {
logger.warn(`itch-setup: no prefix (not installed yet?)`);
return;
}
const command = ospath.join(prefix, "itch-setup");
const args: string[] = [
"--appname",
rs.system.appName,
"--relaunch",
"--relaunch-pid",
`${process.pid}`,
];
const stdio: any[] = ["ignore", "ignore", "ignore"];
try {
fs.unlinkSync(relaunchLogPath());
} catch (e) {}
let out = -1;
let err = -1;
const logPath = relaunchLogPath();
try {
if (fs.existsSync(logPath)) {
fs.unlinkSync(logPath);
}
out = fs.openSync(logPath, "a");
stdio[1] = out;
err = fs.openSync(logPath, "a");
stdio[2] = err;
} catch (e) {
logger.warn(`Could not set up stdout/stderr for relaunch: ${e.stack}`);
if (out != -1) {
fs.closeSync(out);
}
if (err != -1) {
fs.closeSync(err);
}
//.........这里部分代码省略.........
示例5: function
export default function(watcher: Watcher) {
// changing tabs? it's a fetching
watcher.on(actions.tabChanged, async (store, action) => {
const { window, tab } = action.payload;
queueFetch(store, window, tab, FetchReason.TabChanged);
});
watcher.on(actions.tabsChanged, async (store, action) => {
const { window } = action.payload;
queueCleanup(store, window);
});
// tab navigated to something else? let's fetch
watcher.on(actions.evolveTab, async (store, action) => {
const { onlyParamsChange } = action.payload;
const reason = onlyParamsChange
? FetchReason.ParamsChanged
: FetchReason.TabEvolved;
queueFetch(store, action.payload.window, action.payload.tab, reason);
});
watcher.on(actions.tabGoBack, async (store, action) => {
queueFetch(
store,
action.payload.window,
action.payload.tab,
FetchReason.TabEvolved
);
});
watcher.on(actions.tabGoForward, async (store, action) => {
queueFetch(
store,
action.payload.window,
action.payload.tab,
FetchReason.TabEvolved
);
});
// tab reloaded by user? let's fetch!
watcher.on(actions.tabReloaded, async (store, action) => {
queueFetch(
store,
action.payload.window,
action.payload.tab,
FetchReason.TabReloaded
);
});
// window gaining focus? fetch away!
watcher.on(actions.windowFocusChanged, async (store, action) => {
if (action.payload.focused) {
const currentTab = store.getState().windows["root"].navigation.tab;
queueFetch(store, "root", currentTab, FetchReason.WindowFocused);
}
});
watcher.on(actions.commonsUpdated, async (store, action) => {
const currentTab = store.getState().windows["root"].navigation.tab;
queueFetch(store, "root", currentTab, FetchReason.CommonsChanged);
});
watcher.on(actions.windowClosed, async (store, action) => {
const { window } = action.payload;
delete fes[window];
});
const watchedPreferences = [
"onlyCompatibleGames",
"onlyInstalledGames",
"onlyOwnedGames",
];
watcher.on(actions.updatePreferences, async (store, action) => {
// FIXME: multiwindow
const prefs = action.payload;
if (some(watchedPreferences, k => prefs.hasOwnProperty(k))) {
const currentTabId = store.getState().windows["root"].navigation.tab;
queueFetch(store, "root", currentTabId, FetchReason.ParamsChanged);
}
});
}
示例6: function
export default function(watcher: Watcher) {
if (SKIP_GAME_UPDATES) {
logger.debug(
"Skipping game update check as requested per environment variable"
);
} else {
watcher.on(actions.tick, async (store, action) => {
const { nextGameUpdateCheck } = store.getState().systemTasks;
if (Date.now() <= nextGameUpdateCheck) {
// it's not our time... yet!
return;
}
logger.info("Regularly scheduled check for game updates...");
store.dispatch(actions.checkForGameUpdates({}));
});
}
watcher.on(actions.checkForGameUpdates, async (store, action) => {
reschedule(store);
if (!store.getState().setup.done) {
return;
}
store.dispatch(
actions.gameUpdateCheckStatus({
checking: true,
progress: 0,
})
);
try {
store.dispatch(
actions.gameUpdateCheckStatus({
checking: true,
progress: 0,
})
);
// TODO: let butler page through the caves instead,
// this is too much back and forth
const { caves } = await call(messages.FetchCaves, {});
if (isEmpty(caves)) {
return;
}
logger.info(`Checking updates for ${caves.length} games`);
let items: CheckUpdateItem[] = [];
for (const cave of caves) {
try {
items.push(await prepareUpdateItem(cave));
} catch (e) {
logger.error(
`Won't be able to check ${cave.id} for upgrade: ${e.stack}`
);
}
}
try {
await performUpdateCheck(store, items);
} catch (e) {
logger.error(
`While performing ${items.length} update checks: ${e.stack}`
);
}
} finally {
store.dispatch(
actions.gameUpdateCheckStatus({
checking: false,
progress: -1,
})
);
}
});
watcher.on(actions.checkForGameUpdate, async (store, action) => {
const { caveId, noisy = false } = action.payload;
if (noisy) {
logger.info(`Looking for updates for cave ${caveId}`);
}
const { cave } = await call(messages.FetchCave, { caveId });
const item = await prepareUpdateItem(cave);
let res: CheckUpdateResult;
try {
res = await performUpdateCheck(store, [item]);
} catch (e) {
logger.error(`While checking for game update: ${e.stack}`);
if (!res) {
res = {
updates: [],
warnings: [String(e)],
};
}
}
//.........这里部分代码省略.........