mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Make startMainApplication not an injection time side effect
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
bbb610ec69
commit
f43757e23b
@ -14,10 +14,11 @@ import { getDi } from "./getDi";
|
||||
import startMainApplicationInjectable from "./start-main-application/start-main-application.injectable";
|
||||
|
||||
const di = getDi();
|
||||
const startMainApplication = di.inject(startMainApplicationInjectable);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await di.inject(startMainApplicationInjectable);
|
||||
await startMainApplication();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
|
||||
@ -29,19 +29,21 @@ const startMainApplicationInjectable = getInjectable({
|
||||
const showInitialWindowRunnablePhase = runMany(showInitialWindowRunnablePhaseInjectionToken);
|
||||
const afterApplicationIsLoaded = runMany(afterApplicationIsLoadedInjectionToken);
|
||||
|
||||
// Stuff happening before application is ready needs to be synchronous because of
|
||||
// https://github.com/electron/electron/issues/21370
|
||||
appPathsRunnablePhase();
|
||||
beforeElectronIsReady();
|
||||
return () => {
|
||||
// Stuff happening before application is ready needs to be synchronous because of
|
||||
// https://github.com/electron/electron/issues/21370
|
||||
appPathsRunnablePhase();
|
||||
beforeElectronIsReady();
|
||||
|
||||
return (async () => {
|
||||
await waitForElectronToBeReady();
|
||||
await beforeApplicationIsLoading();
|
||||
await showLoadingRunnablePhase();
|
||||
await onLoadOfApplication();
|
||||
await showInitialWindowRunnablePhase();
|
||||
await afterApplicationIsLoaded();
|
||||
})();
|
||||
return (async () => {
|
||||
await waitForElectronToBeReady();
|
||||
await beforeApplicationIsLoading();
|
||||
await showLoadingRunnablePhase();
|
||||
await onLoadOfApplication();
|
||||
await showInitialWindowRunnablePhase();
|
||||
await afterApplicationIsLoaded();
|
||||
})();
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -290,6 +290,24 @@ export const getApplicationBuilder = () => {
|
||||
const namespaces = observable.set<string>();
|
||||
const namespaceItems = observable.array<Namespace>();
|
||||
const selectedNamespaces = observable.set<string>();
|
||||
const startMainApplication = mainDi.inject(startMainApplicationInjectable);
|
||||
|
||||
const startApplication = async ({ shouldStartHidden }: { shouldStartHidden: boolean }) => {
|
||||
mainDi.inject(lensProxyPortInjectable).set(42);
|
||||
|
||||
for (const callback of beforeApplicationStartCallbacks) {
|
||||
await callback(mainDi);
|
||||
}
|
||||
|
||||
mainDi.override(shouldStartHiddenInjectable, () => shouldStartHidden);
|
||||
await startMainApplication();
|
||||
|
||||
for (const callback of afterApplicationStartCallbacks) {
|
||||
await callback(mainDi);
|
||||
}
|
||||
|
||||
applicationHasStarted = true;
|
||||
};
|
||||
|
||||
const builder: ApplicationBuilder = {
|
||||
mainDi,
|
||||
@ -672,37 +690,11 @@ export const getApplicationBuilder = () => {
|
||||
},
|
||||
|
||||
startHidden: async () => {
|
||||
mainDi.inject(lensProxyPortInjectable).set(42);
|
||||
|
||||
for (const callback of beforeApplicationStartCallbacks) {
|
||||
await callback(mainDi);
|
||||
}
|
||||
|
||||
mainDi.override(shouldStartHiddenInjectable, () => true);
|
||||
await mainDi.inject(startMainApplicationInjectable);
|
||||
|
||||
for (const callback of afterApplicationStartCallbacks) {
|
||||
await callback(mainDi);
|
||||
}
|
||||
|
||||
applicationHasStarted = true;
|
||||
await startApplication({ shouldStartHidden: true });
|
||||
},
|
||||
|
||||
async render() {
|
||||
mainDi.inject(lensProxyPortInjectable).set(42);
|
||||
|
||||
for (const callback of beforeApplicationStartCallbacks) {
|
||||
await callback(mainDi);
|
||||
}
|
||||
|
||||
mainDi.override(shouldStartHiddenInjectable, () => false);
|
||||
await mainDi.inject(startMainApplicationInjectable);
|
||||
|
||||
for (const callback of afterApplicationStartCallbacks) {
|
||||
await callback(mainDi);
|
||||
}
|
||||
|
||||
applicationHasStarted = true;
|
||||
await startApplication({ shouldStartHidden: false });
|
||||
|
||||
return builder
|
||||
.applicationWindow
|
||||
|
||||
Loading…
Reference in New Issue
Block a user