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";
|
import startMainApplicationInjectable from "./start-main-application/start-main-application.injectable";
|
||||||
|
|
||||||
const di = getDi();
|
const di = getDi();
|
||||||
|
const startMainApplication = di.inject(startMainApplicationInjectable);
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
await di.inject(startMainApplicationInjectable);
|
await startMainApplication();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|||||||
@ -29,19 +29,21 @@ const startMainApplicationInjectable = getInjectable({
|
|||||||
const showInitialWindowRunnablePhase = runMany(showInitialWindowRunnablePhaseInjectionToken);
|
const showInitialWindowRunnablePhase = runMany(showInitialWindowRunnablePhaseInjectionToken);
|
||||||
const afterApplicationIsLoaded = runMany(afterApplicationIsLoadedInjectionToken);
|
const afterApplicationIsLoaded = runMany(afterApplicationIsLoadedInjectionToken);
|
||||||
|
|
||||||
// Stuff happening before application is ready needs to be synchronous because of
|
return () => {
|
||||||
// https://github.com/electron/electron/issues/21370
|
// Stuff happening before application is ready needs to be synchronous because of
|
||||||
appPathsRunnablePhase();
|
// https://github.com/electron/electron/issues/21370
|
||||||
beforeElectronIsReady();
|
appPathsRunnablePhase();
|
||||||
|
beforeElectronIsReady();
|
||||||
|
|
||||||
return (async () => {
|
return (async () => {
|
||||||
await waitForElectronToBeReady();
|
await waitForElectronToBeReady();
|
||||||
await beforeApplicationIsLoading();
|
await beforeApplicationIsLoading();
|
||||||
await showLoadingRunnablePhase();
|
await showLoadingRunnablePhase();
|
||||||
await onLoadOfApplication();
|
await onLoadOfApplication();
|
||||||
await showInitialWindowRunnablePhase();
|
await showInitialWindowRunnablePhase();
|
||||||
await afterApplicationIsLoaded();
|
await afterApplicationIsLoaded();
|
||||||
})();
|
})();
|
||||||
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -290,6 +290,24 @@ export const getApplicationBuilder = () => {
|
|||||||
const namespaces = observable.set<string>();
|
const namespaces = observable.set<string>();
|
||||||
const namespaceItems = observable.array<Namespace>();
|
const namespaceItems = observable.array<Namespace>();
|
||||||
const selectedNamespaces = observable.set<string>();
|
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 = {
|
const builder: ApplicationBuilder = {
|
||||||
mainDi,
|
mainDi,
|
||||||
@ -672,37 +690,11 @@ export const getApplicationBuilder = () => {
|
|||||||
},
|
},
|
||||||
|
|
||||||
startHidden: async () => {
|
startHidden: async () => {
|
||||||
mainDi.inject(lensProxyPortInjectable).set(42);
|
await startApplication({ shouldStartHidden: true });
|
||||||
|
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async render() {
|
async render() {
|
||||||
mainDi.inject(lensProxyPortInjectable).set(42);
|
await startApplication({ shouldStartHidden: false });
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
return builder
|
return builder
|
||||||
.applicationWindow
|
.applicationWindow
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user