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.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { getStartableStoppable } from "../get-startable-stoppable";
import { getSyncStartableStoppable } from "../get-startable-stoppable";
import { disposer } from "../index";
import { messageChannelListenerInjectionToken } from "./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 messageChannelListeners = di.injectMany(messageChannelListenerInjectionToken);
return getStartableStoppable("listening-on-channels", () => (
return getSyncStartableStoppable("listening-on-channels", () => (
disposer(messageChannelListeners.map(enlistMessageChannelListener))
));
},

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
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 withOrphanPromiseInjectable from "../../../../../common/utils/with-orphan-promise/with-orphan-promise.injectable";
@ -14,13 +14,12 @@ const periodicalCheckForUpdatesInjectable = getInjectable({
const withOrphanPromise = di.inject(withOrphanPromiseInjectable);
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;
processCheckingForUpdates("periodic");
const intervalId = setInterval(() => {
processCheckingForUpdates("periodic");
}, TWO_HOURS);

View File

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

View File

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

View File

@ -4,7 +4,7 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
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 selectedUpdateChannelInjectable from "../../common/selected-update-channel/selected-update-channel.injectable";
import type { ReleaseChannel, UpdateChannel } from "../../common/update-channels";
@ -18,7 +18,7 @@ const watchIfUpdateShouldHappenOnQuitInjectable = getInjectable({
const selectedUpdateChannel = di.inject(selectedUpdateChannelInjectable);
const discoveredVersionState = di.inject(discoveredUpdateVersionInjectable);
return getStartableStoppable("watch-if-update-should-happen-on-quit", () =>
return getSyncStartableStoppable("watch-if-update-should-happen-on-quit", () =>
autorun(() => {
const sufficientlyStableUpdateChannels = getSufficientlyStableUpdateChannels(selectedUpdateChannel.value.get());
const updateIsDiscoveredFromChannel = discoveredVersionState.value.get()?.updateChannel;

View File

@ -4,7 +4,7 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
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";
const catalogSyncToRendererInjectable = getInjectable({
@ -13,7 +13,7 @@ const catalogSyncToRendererInjectable = getInjectable({
instantiate: (di) => {
const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable);
return getStartableStoppable("catalog-sync", () =>
return getSyncStartableStoppable("catalog-sync", () =>
startCatalogSyncToRenderer(catalogEntityRegistry),
);
},

View File

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

View File

@ -14,9 +14,9 @@ const stopCatalogSyncInjectable = getInjectable({
return {
id: "stop-catalog-sync",
run: async () => {
run: () => {
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.
*/
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 nativeThemeInjectable from "./native-theme.injectable";
import getElectronThemeInjectable from "./get-electron-theme.injectable";
@ -16,11 +16,9 @@ const syncThemeFromOperatingSystemInjectable = getInjectable({
const nativeTheme = di.inject(nativeThemeInjectable);
const getElectronTheme = di.inject(getElectronThemeInjectable);
return getStartableStoppable("sync-theme-from-operating-system", () => {
return getSyncStartableStoppable("sync-theme-from-operating-system", () => {
const updateThemeState = () => {
const newTheme = getElectronTheme();
currentThemeState.set(newTheme);
currentThemeState.set(getElectronTheme());
};
nativeTheme.on("updated", updateThemeState);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
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 trayIconInjectable from "./tray-icon.injectable";
@ -15,7 +15,7 @@ const reactiveTrayMenuIconInjectable = getInjectable({
const trayMenuIcon = di.inject(trayIconInjectable);
const electronTray = di.inject(electronTrayInjectable);
return getStartableStoppable("reactive-tray-menu-icon", () => (
return getSyncStartableStoppable("reactive-tray-menu-icon", () => (
reaction(
() => trayMenuIcon.get(),
icon => {

View File

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

View File

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

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
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 type { MinimalTrayMenuItem } 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 reactiveItems = di.inject(trayMenuItemsInjectable);
return getStartableStoppable("reactive-tray-menu-items", () =>
return getSyncStartableStoppable("reactive-tray-menu-items", () =>
reaction(
(): MinimalTrayMenuItem[] => reactiveItems.get().map(toNonReactiveItem),

View File

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

View File

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

View File

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

View File

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