当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Watcher.onStateChange方法代码示例

本文整理汇总了TypeScript中common/util/watcher.Watcher.onStateChange方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Watcher.onStateChange方法的具体用法?TypeScript Watcher.onStateChange怎么用?TypeScript Watcher.onStateChange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common/util/watcher.Watcher的用法示例。


在下文中一共展示了Watcher.onStateChange方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

export default function(watcher: Watcher, runtime: IRuntime) {
  watcher.onStateChange({
    makeSelector: (store, schedule) => {
      let templateSelector = createSelector(
        (rs: IRootState) => rs.system.appVersion,
        (rs: IRootState) => rs.profile.credentials,
        (rs: IRootState) => rs.preferences.enableTabs,
        (appVersion, credentials, enableTabs) => {
          return computeMenuTemplate(
            appVersion,
            credentials,
            enableTabs,
            runtime
          );
        }
      );

      return createSelector(
        templateSelector,
        (rs: IRootState) => rs.i18n,
        (rs: IRootState) => getNativeState(rs, "root").id,
        (template, i18n, mainWindowId) => {
          schedule.dispatch(actions.menuChanged({ template }));
          const fleshed = fleshOutTemplate("root", store, runtime, template);
          const menu = Menu.buildFromTemplate(fleshed);
          setItchAppMenu(mainWindowId, runtime, menu);
        }
      );
    },
  });
}
开发者ID:HorrerGames,项目名称:itch,代码行数:31,代码来源:menu.ts

示例2: makeSubWatcher

function makeSubWatcher(rs: RootState) {
  const watcher = new Watcher(mainLogger);
  for (const window of Object.keys(rs.winds)) {
    watcher.onStateChange({
      makeSelector: (store, schedule) => {
        const getI18n = (rs: RootState) => rs.i18n;
        const getID = (rs: RootState) => rs.winds[window].navigation.tab;
        const getTabInstance = (rs: RootState) => rs.winds[window].tabInstances;

        const getSpace = createSelector(getID, getTabInstance, (id, tabData) =>
          Space.fromInstance(id, tabData[id])
        );

        return createSelector(getI18n, getSpace, (i18n, sp) => {
          const nativeWindow = getNativeWindow(store.getState(), window);
          if (nativeWindow && !nativeWindow.isDestroyed()) {
            const label = t(i18n, sp.label());
            let title: string;
            if (label) {
              title = `${label} - ${app.getName()}`;
            } else {
              title = `${app.getName()}`;
            }
            nativeWindow.setTitle(title);
          }
        });
      },
    });
  }
  return watcher;
}
开发者ID:itchio,项目名称:itch,代码行数:31,代码来源:winds.ts

示例3: function

export default function(watcher: Watcher) {
  watcher.onStateChange({
    makeSelector: (store, schedule) =>
      createSelector(
        (rs: RootState) => rs.system.sniffedLanguage,
        (rs: RootState) => rs.preferences.lang,
        (sniffedLang, preferenceLang) => {
          const lang = preferenceLang || sniffedLang || fallbackLang;
          schedule.dispatch(actions.languageChanged({ lang }));
        }
      ),
  });
}
开发者ID:itchio,项目名称:itch,代码行数:13,代码来源:i18n.ts

示例4: makeSubWatcher

function makeSubWatcher(rs: IRootState) {
  const watcher = new Watcher();
  for (const window of Object.keys(rs.windows)) {
    watcher.onStateChange({
      makeSelector: (store, schedule) =>
        createSelector(
          (rs: IRootState) => rs.windows[window].navigation.tab,
          tab => schedule.dispatch(actions.tabChanged({ window, tab }))
        ),
    });

    watcher.onStateChange({
      makeSelector: (store, schedule) =>
        createSelector(
          (rs: IRootState) => rs.windows[window].navigation.openTabs,
          (rs: IRootState) => rs.windows[window].tabInstances,
          (rs: IRootState) => rs.windows[window].navigation.tab,
          (openTabs, tabInstances, tab) =>
            schedule.dispatch(actions.tabsChanged({ window }))
        ),
    });
  }
  return watcher;
}
开发者ID:HorrerGames,项目名称:itch,代码行数:24,代码来源:navigation.ts

示例5: function

export default function(watcher: Watcher) {
  watcher.onStateChange({
    makeSelector: (store, schedule) =>
      createSelector(
        (rs: IRootState) => rs.i18n,
        i18n => {
          schedule(() => refreshTray(store, i18n));
        }
      ),
  });

  watcher.on(actions.notify, async (store, action) => {
    const { onClick } = action.payload;
    rememberNotificationAction(onClick);
  });
}
开发者ID:HorrerGames,项目名称:itch,代码行数:16,代码来源:tray.ts

示例6: function

export default function(watcher: Watcher, runtime: Runtime) {
  watcher.onStateChange({
    makeSelector: (store, schedule) => {
      let templateSelector = createSelector(
        (rs: RootState) => rs.system.appVersion,
        (rs: RootState) => rs.profile.profile,
        (rs: RootState) => rs.preferences.enableTabs,
        (appVersion, credentials, enableTabs) => {
          return computeMenuTemplate(
            appVersion,
            credentials,
            enableTabs,
            runtime
          );
        }
      );

      return createSelector(
        templateSelector,
        (rs: RootState) => rs.i18n,
        (rs: RootState) => {
          let res = [];
          for (const k of Object.keys(rs.winds)) {
            res.push(rs.winds[k].native.id);
          }
          // this little trick is here for memoization! dumb, I know :)
          return JSON.stringify(res);
        },
        (template, i18n, nativeIDsPayload) => {
          schedule.dispatch(actions.menuChanged({ template }));
          const fleshed = fleshOutTemplate("root", store, runtime, template);
          const menu = Menu.buildFromTemplate(fleshed);
          setItchAppMenu(nativeIDsPayload, runtime, menu);
        }
      );
    },
  });
}
开发者ID:itchio,项目名称:itch,代码行数:38,代码来源:menu.ts

示例7: function

export default function(watcher: Watcher) {
  watcher.onStateChange({
    makeSelector: (store, schedule) => {
      const getI18n = (rs: IRootState) => rs.i18n;
      const getID = (rs: IRootState) => rs.windows["root"].navigation.tab;
      const getTabInstance = (rs: IRootState) =>
        rs.windows["root"].tabInstances;

      const getSpace = createSelector(getID, getTabInstance, (id, tabData) =>
        Space.fromInstance(tabData[id])
      );

      return createSelector(getI18n, getSpace, (i18n, sp) => {
        updateTitle(store, t(i18n, sp.label()) + " - itch");
      });
    },
  });

  watcher.on(actions.preboot, async (store, action) => {
    await createRootWindow(store);
  });

  watcher.on(actions.preferencesLoaded, async (store, action) => {
    const hidden = action.payload.openAsHidden;
    if (!hidden) {
      store.dispatch(actions.focusWindow({ window: "root" }));
    }

    screen.on("display-added", () => ensureMainWindowInsideDisplay(store));
    screen.on("display-removed", () => ensureMainWindowInsideDisplay(store));
    screen.on("display-metrics-changed", () =>
      ensureMainWindowInsideDisplay(store)
    );
  });

  watcher.on(actions.focusWindow, async (store, action) => {
    const { window } = action.payload;
    const nativeWindow = getNativeWindow(store.getState(), window);
    const { toggle } = action.payload;

    if (nativeWindow) {
      if (toggle && nativeWindow.isVisible()) {
        nativeWindow.hide();
      } else {
        nativeWindow.show();
        if (window === "root") {
          const maximized = config.get(MAXIMIZED_CONFIG_KEY) || false;
          if (maximized && !macOs) {
            nativeWindow.maximize();
          }

          if (!maximized) {
            ensureWindowInsideDisplay(nativeWindow);
          }
        }
      }
    }
  });

  watcher.on(actions.hideWindow, async (store, action) => {
    hideWindow();
  });

  watcher.on(actions.minimizeWindow, async (store, action) => {
    minimizeWindow();
  });

  watcher.on(actions.toggleMaximizeWindow, async (store, action) => {
    toggleMaximizeWindow();
  });

  watcher.on(actions.commandBack, async (store, action) => {
    exitFullScreen();
  });

  watcher.on(actions.windowBoundsChanged, async (store, action) => {
    const { window, bounds } = action.payload;
    if (window === "root") {
      config.set(BOUNDS_CONFIG_KEY, bounds);
    }
  });

  watcher.on(actions.closeTabOrAuxWindow, async (store, action) => {
    const { window } = action.payload;
    store.dispatch(actions.closeCurrentTab({ window }));
  });

  watcher.on(actions.quitWhenMain, async (store, action) => {
    const mainId = getNativeState(store.getState(), "root").id;
    const focused = BrowserWindow.getFocusedWindow();

    if (focused) {
      if (focused.id === mainId) {
        store.dispatch(actions.quit({}));
      } else {
        focused.close();
      }
    }
  });

//.........这里部分代码省略.........
开发者ID:HorrerGames,项目名称:itch,代码行数:101,代码来源:main-window.ts


注:本文中的common/util/watcher.Watcher.onStateChange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。