Refactor runnables (#6528)

* Convert runManyFor to use composite

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Convert runManySyncFor to use composite and to enfore sync-ness

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Remove dead code

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Convert getStartableStoppable to be always sync as it is never used in an async fashion

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Convert all sync runnables to comply with new checks for sync-ness

Signed-off-by: Sebastian Malton <sebastian@malton.name>

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2022-11-07 19:04:56 +02:00
1 parent 82ab60d544
commit b498f12186
42 files changed
+191 -401

No files matched your search

@@ -18,9 +18,7 @@ const syncThemeFromOperatingSystemInjectable = getInjectable({
return getStartableStoppable("sync-theme-from-operating-system", () => {
const updateThemeState = () => {
const newTheme = getElectronTheme();
currentThemeState.set(newTheme);
currentThemeState.set(getElectronTheme());
};
nativeTheme.on("updated", updateThemeState);
@@ -14,9 +14,7 @@ const cleanUpDeepLinkingInjectable = getInjectable({
return {
id: "clean-up-deep-linking",
run: () => {
lensProtocolRouterMain.cleanup();
},
run: () => void lensProtocolRouterMain.cleanup(),
};
},
@@ -23,6 +23,8 @@ const hideDockForLastClosedWindowInjectable = getInjectable({
if (isEmpty(visibleWindows)) {
app.dock?.hide();
}
return undefined;
},
};
},
@@ -20,6 +20,8 @@ const enforceSingleApplicationInstanceInjectable = getInjectable({
if (!requestSingleInstanceLock()) {
exitApp();
}
return undefined;
},
};
},
@@ -18,6 +18,8 @@ const setupApplicationNameInjectable = getInjectable({
id: "setup-application-name",
run: () => {
app.setName(appName);
return undefined;
},
};
},
@@ -13,15 +13,14 @@ const setupRunnablesAfterWindowIsOpenedInjectable = getInjectable({
instantiate: (di) => {
const afterWindowIsOpened = runManyFor(di)(afterWindowIsOpenedInjectionToken);
const app = di.inject(electronAppInjectable);
return {
id: "setup-runnables-after-window-is-opened",
run: () => {
const app = di.inject(electronAppInjectable);
app.on("browser-window-created", () => afterWindowIsOpened);
app.on("browser-window-created", async () => {
await afterWindowIsOpened();
});
return undefined;
},
};
},
@@ -15,24 +15,16 @@ const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
id: "setup-closing-of-application",
instantiate: (di) => {
const runMany = runManySyncFor(di);
const runRunnablesBeforeQuitOfFrontEnd = runMany(
beforeQuitOfFrontEndInjectionToken,
);
const runRunnablesBeforeQuitOfBackEnd = runMany(
beforeQuitOfBackEndInjectionToken,
);
const runManySync = runManySyncFor(di);
const runRunnablesBeforeQuitOfFrontEnd = runManySync(beforeQuitOfFrontEndInjectionToken);
const runRunnablesBeforeQuitOfBackEnd = runManySync(beforeQuitOfBackEndInjectionToken);
const app = di.inject(electronAppInjectable);
const isIntegrationTesting = di.inject(isIntegrationTestingInjectable);
const autoUpdater = di.inject(autoUpdaterInjectable);
return {
id: "setup-closing-of-application",
run: () => {
const app = di.inject(electronAppInjectable);
const isIntegrationTesting = di.inject(isIntegrationTestingInjectable);
const autoUpdater = di.inject(autoUpdaterInjectable);
let isAutoUpdating = false;
autoUpdater.on("before-quit-for-update", () => {
@@ -51,6 +43,8 @@ const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
event.preventDefault();
}
});
return undefined;
},
};
},