1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Use getSyncStartableStoppable in as many places as possible

- Used to fix danging promises during quit

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-11-02 16:11:32 -04:00
parent 518908ba61
commit 1a9485ab60
26 changed files with 54 additions and 63 deletions

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { getStartableStoppable } from "../get-startable-stoppable"; import { getSyncStartableStoppable } from "../get-startable-stoppable";
import { disposer } from "../index"; import { disposer } from "../index";
import { messageChannelListenerInjectionToken } from "./message-channel-listener-injection-token"; import { messageChannelListenerInjectionToken } from "./message-channel-listener-injection-token";
import { enlistMessageChannelListenerInjectionToken } from "./enlist-message-channel-listener-injection-token"; import { enlistMessageChannelListenerInjectionToken } from "./enlist-message-channel-listener-injection-token";
@ -15,7 +15,7 @@ const listeningOnMessageChannelsInjectable = getInjectable({
const enlistMessageChannelListener = di.inject(enlistMessageChannelListenerInjectionToken); const enlistMessageChannelListener = di.inject(enlistMessageChannelListenerInjectionToken);
const messageChannelListeners = di.injectMany(messageChannelListenerInjectionToken); const messageChannelListeners = di.injectMany(messageChannelListenerInjectionToken);
return getStartableStoppable("listening-on-channels", () => ( return getSyncStartableStoppable("listening-on-channels", () => (
disposer(messageChannelListeners.map(enlistMessageChannelListener)) disposer(messageChannelListeners.map(enlistMessageChannelListener))
)); ));
}, },

View File

@ -4,7 +4,7 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { autorun } from "mobx"; import { autorun } from "mobx";
import { getStartableStoppable } from "../../../common/utils/get-startable-stoppable"; import { getSyncStartableStoppable } from "../../../common/utils/get-startable-stoppable";
import populateApplicationMenuInjectable from "./populate-application-menu.injectable"; import populateApplicationMenuInjectable from "./populate-application-menu.injectable";
import applicationMenuItemCompositeInjectable from "./application-menu-item-composite.injectable"; import applicationMenuItemCompositeInjectable from "./application-menu-item-composite.injectable";
@ -15,7 +15,7 @@ const applicationMenuReactivityInjectable = getInjectable({
const applicationMenuItemComposite = di.inject(applicationMenuItemCompositeInjectable); const applicationMenuItemComposite = di.inject(applicationMenuItemCompositeInjectable);
const populateApplicationMenu = di.inject(populateApplicationMenuInjectable); const populateApplicationMenu = di.inject(populateApplicationMenuInjectable);
return getStartableStoppable("application-menu-reactivity", () => return getSyncStartableStoppable("application-menu-reactivity", () =>
autorun(() => populateApplicationMenu(applicationMenuItemComposite.get()), { autorun(() => populateApplicationMenu(applicationMenuItemComposite.get()), {
delay: 100, delay: 100,
}), }),

View File

@ -16,8 +16,8 @@ const startApplicationMenuInjectable = getInjectable({
return { return {
id: "start-application-menu", id: "start-application-menu",
run: async () => { run: () => {
await applicationMenu.start(); applicationMenu.start();
}, },
}; };
}, },

View File

@ -16,8 +16,8 @@ const stopApplicationMenuInjectable = getInjectable({
return { return {
id: "stop-application-menu", id: "stop-application-menu",
run: async () => { run: () => {
await applicationMenu.stop(); applicationMenu.stop();
}, },
}; };
}, },

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { getStartableStoppable } from "../../../../../common/utils/get-startable-stoppable"; import { getSyncStartableStoppable } from "../../../../../common/utils/get-startable-stoppable";
import processCheckingForUpdatesInjectable from "../../../main/process-checking-for-updates.injectable"; import processCheckingForUpdatesInjectable from "../../../main/process-checking-for-updates.injectable";
import withOrphanPromiseInjectable from "../../../../../common/utils/with-orphan-promise/with-orphan-promise.injectable"; import withOrphanPromiseInjectable from "../../../../../common/utils/with-orphan-promise/with-orphan-promise.injectable";
@ -14,13 +14,12 @@ const periodicalCheckForUpdatesInjectable = getInjectable({
const withOrphanPromise = di.inject(withOrphanPromiseInjectable); const withOrphanPromise = di.inject(withOrphanPromiseInjectable);
const processCheckingForUpdates = withOrphanPromise(di.inject(processCheckingForUpdatesInjectable)); const processCheckingForUpdates = withOrphanPromise(di.inject(processCheckingForUpdatesInjectable));
return getStartableStoppable("periodical-check-for-updates", () => { return getSyncStartableStoppable("periodical-check-for-updates", () => {
const TWO_HOURS = 1000 * 60 * 60 * 2; const TWO_HOURS = 1000 * 60 * 60 * 2;
processCheckingForUpdates("periodic"); processCheckingForUpdates("periodic");
const intervalId = setInterval(() => { const intervalId = setInterval(() => {
processCheckingForUpdates("periodic"); processCheckingForUpdates("periodic");
}, TWO_HOURS); }, TWO_HOURS);

View File

@ -16,9 +16,9 @@ const startCheckingForUpdatesInjectable = getInjectable({
return { return {
id: "start-checking-for-updates", id: "start-checking-for-updates",
run: async () => { run: () => {
if (updatingIsEnabled && !periodicalCheckForUpdates.started) { if (updatingIsEnabled && !periodicalCheckForUpdates.started) {
await periodicalCheckForUpdates.start(); periodicalCheckForUpdates.start();
} }
}, },
}; };

View File

@ -14,9 +14,9 @@ const stopCheckingForUpdatesInjectable = getInjectable({
return { return {
id: "stop-checking-for-updates", id: "stop-checking-for-updates",
run: async () => { run: () => {
if (periodicalCheckForUpdates.started) { if (periodicalCheckForUpdates.started) {
await periodicalCheckForUpdates.stop(); periodicalCheckForUpdates.stop();
} }
}, },
}; };

View File

@ -4,7 +4,7 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { autorun } from "mobx"; import { autorun } from "mobx";
import { getStartableStoppable } from "../../../../common/utils/get-startable-stoppable"; import { getSyncStartableStoppable } from "../../../../common/utils/get-startable-stoppable";
import setUpdateOnQuitInjectable from "../../../../main/electron-app/features/set-update-on-quit.injectable"; import setUpdateOnQuitInjectable from "../../../../main/electron-app/features/set-update-on-quit.injectable";
import selectedUpdateChannelInjectable from "../../common/selected-update-channel/selected-update-channel.injectable"; import selectedUpdateChannelInjectable from "../../common/selected-update-channel/selected-update-channel.injectable";
import type { ReleaseChannel, UpdateChannel } from "../../common/update-channels"; import type { ReleaseChannel, UpdateChannel } from "../../common/update-channels";
@ -18,7 +18,7 @@ const watchIfUpdateShouldHappenOnQuitInjectable = getInjectable({
const selectedUpdateChannel = di.inject(selectedUpdateChannelInjectable); const selectedUpdateChannel = di.inject(selectedUpdateChannelInjectable);
const discoveredVersionState = di.inject(discoveredUpdateVersionInjectable); const discoveredVersionState = di.inject(discoveredUpdateVersionInjectable);
return getStartableStoppable("watch-if-update-should-happen-on-quit", () => return getSyncStartableStoppable("watch-if-update-should-happen-on-quit", () =>
autorun(() => { autorun(() => {
const sufficientlyStableUpdateChannels = getSufficientlyStableUpdateChannels(selectedUpdateChannel.value.get()); const sufficientlyStableUpdateChannels = getSufficientlyStableUpdateChannels(selectedUpdateChannel.value.get());
const updateIsDiscoveredFromChannel = discoveredVersionState.value.get()?.updateChannel; const updateIsDiscoveredFromChannel = discoveredVersionState.value.get()?.updateChannel;

View File

@ -4,7 +4,7 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { startCatalogSyncToRenderer } from "../catalog-pusher"; import { startCatalogSyncToRenderer } from "../catalog-pusher";
import { getStartableStoppable } from "../../common/utils/get-startable-stoppable"; import { getSyncStartableStoppable } from "../../common/utils/get-startable-stoppable";
import catalogEntityRegistryInjectable from "../catalog/entity-registry.injectable"; import catalogEntityRegistryInjectable from "../catalog/entity-registry.injectable";
const catalogSyncToRendererInjectable = getInjectable({ const catalogSyncToRendererInjectable = getInjectable({
@ -13,7 +13,7 @@ const catalogSyncToRendererInjectable = getInjectable({
instantiate: (di) => { instantiate: (di) => {
const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable); const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable);
return getStartableStoppable("catalog-sync", () => return getSyncStartableStoppable("catalog-sync", () =>
startCatalogSyncToRenderer(catalogEntityRegistry), startCatalogSyncToRenderer(catalogEntityRegistry),
); );
}, },

View File

@ -14,9 +14,9 @@ const startCatalogSyncInjectable = getInjectable({
return { return {
id: "start-catalog-sync", id: "start-catalog-sync",
run: async () => { run: () => {
if (!catalogSyncToRenderer.started) { if (!catalogSyncToRenderer.started) {
await catalogSyncToRenderer.start(); catalogSyncToRenderer.start();
} }
}, },
}; };

View File

@ -14,9 +14,9 @@ const stopCatalogSyncInjectable = getInjectable({
return { return {
id: "stop-catalog-sync", id: "stop-catalog-sync",
run: async () => { run: () => {
if (catalogSyncToRenderer.started) { if (catalogSyncToRenderer.started) {
await catalogSyncToRenderer.stop(); catalogSyncToRenderer.stop();
} }
}, },
}; };

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { getStartableStoppable } from "../../../common/utils/get-startable-stoppable"; import { getSyncStartableStoppable } from "../../../common/utils/get-startable-stoppable";
import operatingSystemThemeStateInjectable from "../../theme/operating-system-theme-state.injectable"; import operatingSystemThemeStateInjectable from "../../theme/operating-system-theme-state.injectable";
import nativeThemeInjectable from "./native-theme.injectable"; import nativeThemeInjectable from "./native-theme.injectable";
import getElectronThemeInjectable from "./get-electron-theme.injectable"; import getElectronThemeInjectable from "./get-electron-theme.injectable";
@ -16,11 +16,9 @@ const syncThemeFromOperatingSystemInjectable = getInjectable({
const nativeTheme = di.inject(nativeThemeInjectable); const nativeTheme = di.inject(nativeThemeInjectable);
const getElectronTheme = di.inject(getElectronThemeInjectable); const getElectronTheme = di.inject(getElectronThemeInjectable);
return getStartableStoppable("sync-theme-from-operating-system", () => { return getSyncStartableStoppable("sync-theme-from-operating-system", () => {
const updateThemeState = () => { const updateThemeState = () => {
const newTheme = getElectronTheme(); currentThemeState.set(getElectronTheme());
currentThemeState.set(newTheme);
}; };
nativeTheme.on("updated", updateThemeState); nativeTheme.on("updated", updateThemeState);

View File

@ -16,14 +16,8 @@ const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
instantiate: (di) => { instantiate: (di) => {
const runMany = runManySyncFor(di); const runMany = runManySyncFor(di);
const runRunnablesBeforeQuitOfFrontEnd = runMany(beforeQuitOfFrontEndInjectionToken);
const runRunnablesBeforeQuitOfFrontEnd = runMany( const runRunnablesBeforeQuitOfBackEnd = runMany(beforeQuitOfBackEndInjectionToken);
beforeQuitOfFrontEndInjectionToken,
);
const runRunnablesBeforeQuitOfBackEnd = runMany(
beforeQuitOfBackEndInjectionToken,
);
return { return {
id: "setup-closing-of-application", id: "setup-closing-of-application",

View File

@ -4,7 +4,7 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { reaction } from "mobx"; import { reaction } from "mobx";
import { getStartableStoppable } from "../../../common/utils/get-startable-stoppable"; import { getSyncStartableStoppable } from "../../../common/utils/get-startable-stoppable";
import { setNativeThemeChannel } from "../../../common/ipc/native-theme"; import { setNativeThemeChannel } from "../../../common/ipc/native-theme";
import operatingSystemThemeInjectable from "../operating-system-theme.injectable"; import operatingSystemThemeInjectable from "../operating-system-theme.injectable";
import broadcastMessageInjectable from "../../../common/ipc/broadcast-message.injectable"; import broadcastMessageInjectable from "../../../common/ipc/broadcast-message.injectable";
@ -16,7 +16,7 @@ const broadcastThemeChangeInjectable = getInjectable({
const currentTheme = di.inject(operatingSystemThemeInjectable); const currentTheme = di.inject(operatingSystemThemeInjectable);
const broadcastMessage = di.inject(broadcastMessageInjectable); const broadcastMessage = di.inject(broadcastMessageInjectable);
return getStartableStoppable("broadcast-theme-change", () => return getSyncStartableStoppable("broadcast-theme-change", () =>
reaction(() => currentTheme.get(), (theme) => { reaction(() => currentTheme.get(), (theme) => {
broadcastMessage(setNativeThemeChannel, theme); broadcastMessage(setNativeThemeChannel, theme);
}), }),

View File

@ -14,8 +14,8 @@ const startBroadcastingThemeChangeInjectable = getInjectable({
return { return {
id: "start-broadcasting-theme-change", id: "start-broadcasting-theme-change",
run: async () => { run: () => {
await broadcastThemeChange.start(); broadcastThemeChange.start();
}, },
}; };
}, },

View File

@ -14,8 +14,8 @@ const stopBroadcastingThemeChangeInjectable = getInjectable({
return { return {
id: "stop-broadcasting-theme-change", id: "stop-broadcasting-theme-change",
run: async () => { run: () => {
await broadcastThemeChange.stop(); broadcastThemeChange.stop();
}, },
}; };
}, },

View File

@ -14,8 +14,8 @@ const startSyncingThemeFromOperatingSystemInjectable = getInjectable({
return { return {
id: "start-syncing-theme-from-operating-system", id: "start-syncing-theme-from-operating-system",
run: async () => { run: () => {
await syncTheme.start(); syncTheme.start();
}, },
}; };
}, },

View File

@ -14,8 +14,8 @@ const stopSyncingThemeFromOperatingSystemInjectable = getInjectable({
return { return {
id: "stop-syncing-theme-from-operating-system", id: "stop-syncing-theme-from-operating-system",
run: async () => { run: () => {
await syncTheme.stop(); syncTheme.stop();
}, },
}; };
}, },

View File

@ -4,7 +4,7 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { reaction } from "mobx"; import { reaction } from "mobx";
import { getStartableStoppable } from "../../../common/utils/get-startable-stoppable"; import { getSyncStartableStoppable } from "../../../common/utils/get-startable-stoppable";
import electronTrayInjectable from "../electron-tray/electron-tray.injectable"; import electronTrayInjectable from "../electron-tray/electron-tray.injectable";
import trayIconInjectable from "./tray-icon.injectable"; import trayIconInjectable from "./tray-icon.injectable";
@ -15,7 +15,7 @@ const reactiveTrayMenuIconInjectable = getInjectable({
const trayMenuIcon = di.inject(trayIconInjectable); const trayMenuIcon = di.inject(trayIconInjectable);
const electronTray = di.inject(electronTrayInjectable); const electronTray = di.inject(electronTrayInjectable);
return getStartableStoppable("reactive-tray-menu-icon", () => ( return getSyncStartableStoppable("reactive-tray-menu-icon", () => (
reaction( reaction(
() => trayMenuIcon.get(), () => trayMenuIcon.get(),
icon => { icon => {

View File

@ -15,8 +15,8 @@ const startReactiveTrayMenuIconInjectable = getInjectable({
return { return {
id: "start-reactive-tray-menu-icon", id: "start-reactive-tray-menu-icon",
run: async () => { run: () => {
await reactiveTrayMenuIcon.start(); reactiveTrayMenuIcon.start();
}, },
runAfter: di.inject(startTrayInjectable), runAfter: di.inject(startTrayInjectable),

View File

@ -14,8 +14,8 @@ const stopReactiveTrayMenuIconInjectable = getInjectable({
return { return {
id: "stop-reactive-tray-menu-icon", id: "stop-reactive-tray-menu-icon",
run: async () => { run: () => {
await reactiveTrayMenuIcon.stop(); reactiveTrayMenuIcon.stop();
}, },
}; };
}, },

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { getStartableStoppable } from "../../../common/utils/get-startable-stoppable"; import { getSyncStartableStoppable } from "../../../common/utils/get-startable-stoppable";
import { reaction } from "mobx"; import { reaction } from "mobx";
import type { MinimalTrayMenuItem } from "../electron-tray/electron-tray.injectable"; import type { MinimalTrayMenuItem } from "../electron-tray/electron-tray.injectable";
import electronTrayInjectable from "../electron-tray/electron-tray.injectable"; import electronTrayInjectable from "../electron-tray/electron-tray.injectable";
@ -17,7 +17,7 @@ const reactiveTrayMenuItemsInjectable = getInjectable({
const electronTray = di.inject(electronTrayInjectable); const electronTray = di.inject(electronTrayInjectable);
const reactiveItems = di.inject(trayMenuItemsInjectable); const reactiveItems = di.inject(trayMenuItemsInjectable);
return getStartableStoppable("reactive-tray-menu-items", () => return getSyncStartableStoppable("reactive-tray-menu-items", () =>
reaction( reaction(
(): MinimalTrayMenuItem[] => reactiveItems.get().map(toNonReactiveItem), (): MinimalTrayMenuItem[] => reactiveItems.get().map(toNonReactiveItem),

View File

@ -15,8 +15,8 @@ const startReactiveTrayMenuItemsInjectable = getInjectable({
return { return {
id: "start-reactive-tray-menu-items", id: "start-reactive-tray-menu-items",
run: async () => { run: () => {
await reactiveTrayMenuItems.start(); reactiveTrayMenuItems.start();
}, },
runAfter: di.inject(startTrayInjectable), runAfter: di.inject(startTrayInjectable),

View File

@ -14,8 +14,8 @@ const stopReactiveTrayMenuItemsInjectable = getInjectable({
return { return {
id: "stop-reactive-tray-menu-items", id: "stop-reactive-tray-menu-items",
run: async () => { run: () => {
await reactiveTrayMenuItems.stop(); reactiveTrayMenuItems.stop();
}, },
}; };
}, },

View File

@ -5,7 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { disposer } from "../../../../common/utils"; import { disposer } from "../../../../common/utils";
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token"; import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
import { getStartableStoppable } from "../../../../common/utils/get-startable-stoppable"; import { getSyncStartableStoppable } from "../../../../common/utils/get-startable-stoppable";
import enlistRequestChannelListenerInjectable from "./enlist-request-channel-listener.injectable"; import enlistRequestChannelListenerInjectable from "./enlist-request-channel-listener.injectable";
import { requestChannelListenerInjectionToken } from "./listener-tokens"; import { requestChannelListenerInjectionToken } from "./listener-tokens";
@ -15,7 +15,7 @@ const listeningOnRequestChannelsInjectable = getInjectable({
const enlistRequestChannelListener = di.inject(enlistRequestChannelListenerInjectable); const enlistRequestChannelListener = di.inject(enlistRequestChannelListenerInjectable);
const requestChannelListeners = di.injectMany(requestChannelListenerInjectionToken); const requestChannelListeners = di.injectMany(requestChannelListenerInjectionToken);
return getStartableStoppable("listening-on-request-channels", () => { return getSyncStartableStoppable("listening-on-request-channels", () => {
const seenChannels = new Set<RequestChannel<unknown, unknown>>(); const seenChannels = new Set<RequestChannel<unknown, unknown>>();
for (const listener of requestChannelListeners) { for (const listener of requestChannelListeners) {

View File

@ -16,9 +16,9 @@ const startListeningOnChannelsInjectable = getInjectable({
return { return {
id: "start-listening-on-channels-main", id: "start-listening-on-channels-main",
run: async () => { run: () => {
await listeningOnMessageChannels.start(); listeningOnMessageChannels.start();
await listeningOnRequestChannels.start(); listeningOnRequestChannels.start();
}, },
}; };
}, },