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

Stuff that were tried to mitigate the issue

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2023-04-04 16:22:05 +03:00
parent 673144ae8f
commit 98ef8538a4
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A
12 changed files with 46659 additions and 4566 deletions

View File

@ -14,10 +14,14 @@ export interface StartableStoppable {
type StartableStoppableState = "stopped" | "started" | "starting";
export const startableStoppableMap = new Map();
export function getStartableStoppable(id: string, startAndGetStopper: Starter): StartableStoppable {
let stop: Stopper;
let state: StartableStoppableState = "stopped";
startableStoppableMap.set(id, state);
return {
get started() {
return state === "started";
@ -29,8 +33,10 @@ export function getStartableStoppable(id: string, startAndGetStopper: Starter):
}
state = "starting";
startableStoppableMap.set(id, state);
stop = startAndGetStopper();
state = "started";
startableStoppableMap.set(id, state);
},
stop: () => {
@ -40,6 +46,7 @@ export function getStartableStoppable(id: string, startAndGetStopper: Starter):
stop();
state = "stopped";
startableStoppableMap.set(id, state);
},
};
}

View File

@ -4,7 +4,7 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import catalogSyncToRendererInjectable from "./catalog-sync-to-renderer.injectable";
import { beforeQuitOfFrontEndInjectionToken } from "../start-main-application/runnable-tokens/before-quit-of-front-end-injection-token";
import { beforeQuitOfBackEndInjectionToken } from "../start-main-application/runnable-tokens/before-quit-of-back-end-injection-token";
const stopCatalogSyncInjectable = getInjectable({
id: "stop-catalog-sync",
@ -24,7 +24,7 @@ const stopCatalogSyncInjectable = getInjectable({
};
},
injectionToken: beforeQuitOfFrontEndInjectionToken,
injectionToken: beforeQuitOfBackEndInjectionToken,
});
export default stopCatalogSyncInjectable;

View File

@ -11,7 +11,7 @@ const exitAppInjectable = getInjectable({
instantiate: (di) => () => {
const app = di.inject(electronAppInjectable);
app.exit(0);
app.quit();
},
});

View File

@ -3,72 +3,85 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { beforeElectronIsReadyInjectionToken } from "../../start-main-application/runnable-tokens/before-electron-is-ready-injection-token";
import { beforeQuitOfFrontEndInjectionToken } from "../../start-main-application/runnable-tokens/before-quit-of-front-end-injection-token";
import { beforeQuitOfBackEndInjectionToken } from "../../start-main-application/runnable-tokens/before-quit-of-back-end-injection-token";
// import { beforeQuitOfFrontEndInjectionToken } from "../../start-main-application/runnable-tokens/before-quit-of-front-end-injection-token";
// import { beforeQuitOfBackEndInjectionToken } from "../../start-main-application/runnable-tokens/before-quit-of-back-end-injection-token";
import electronAppInjectable from "../electron-app.injectable";
import isIntegrationTestingInjectable from "../../../common/vars/is-integration-testing.injectable";
import autoUpdaterInjectable from "../features/auto-updater.injectable";
// import isIntegrationTestingInjectable from "../../../common/vars/is-integration-testing.injectable";
// import autoUpdaterInjectable from "../features/auto-updater.injectable";
// import { runManySyncFor } from "../../../common/runnable/run-many-sync-for";
// import { runManyFor } from "../../../common/runnable/run-many-for";
import {
beforeElectronIsReadyInjectionToken
} from "../../start-main-application/runnable-tokens/before-electron-is-ready-injection-token";
import {
beforeQuitOfFrontEndInjectionToken
} from "../../start-main-application/runnable-tokens/before-quit-of-front-end-injection-token";
import { runManySyncFor } from "../../../common/runnable/run-many-sync-for";
import { runManyFor } from "../../../common/runnable/run-many-for";
const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
id: "setup-closing-of-application",
instantiate: (di) => {
const runManySync = runManySyncFor(di);
const runMany = runManyFor(di);
// const runMany = runManyFor(di);
const runRunnablesBeforeQuitOfFrontEnd = runManySync(beforeQuitOfFrontEndInjectionToken);
const runRunnablesBeforeQuitOfBackEnd = runMany(beforeQuitOfBackEndInjectionToken);
// const runRunnablesBeforeQuitOfBackEnd = runMany(beforeQuitOfBackEndInjectionToken);
const app = di.inject(electronAppInjectable);
const isIntegrationTesting = di.inject(isIntegrationTestingInjectable);
const autoUpdater = di.inject(autoUpdaterInjectable);
// const isIntegrationTesting = di.inject(isIntegrationTestingInjectable);
// const autoUpdater = di.inject(autoUpdaterInjectable);
return {
id: "setup-closing-of-application",
run: () => {
let isAutoUpdating = false;
autoUpdater.on("before-quit-for-update", () => {
isAutoUpdating = true;
});
let isAsyncQuitting = false;
const doAsyncQuit = (event: Electron.Event, exitCode = 0) => {
if (isAsyncQuitting) {
return;
}
isAsyncQuitting = true;
void (async () => {
try {
await runRunnablesBeforeQuitOfBackEnd();
} catch (error) {
console.error("A beforeQuitOfBackEnd failed!!!!", error);
exitCode = 1;
}
app.exit(exitCode);
})();
};
app.on("will-quit", (event) => {
app.on('window-all-closed', () => {
console.log('All windows closed');
runRunnablesBeforeQuitOfFrontEnd();
event.preventDefault();
if (isIntegrationTesting || isAutoUpdating) {
doAsyncQuit(event);
}
});
app.on("quit", (event, exitCode) => {
event.preventDefault();
doAsyncQuit(event, exitCode);
});
})
return undefined;
// let isAutoUpdating = false;
//
// autoUpdater.on("before-quit-for-update", () => {
// isAutoUpdating = true;
// });
//
// let isAsyncQuitting = false;
//
// const doAsyncQuit = (event: Electron.Event, exitCode = 0) => {
// if (isAsyncQuitting) {
// return;
// }
//
// isAsyncQuitting = true;
//
// void (async () => {
// try {
// await runRunnablesBeforeQuitOfBackEnd();
// } catch (error) {
// console.error("A beforeQuitOfBackEnd failed!!!!", error);
// exitCode = 1;
// }
//
// app.exit(exitCode);
// })();
// };
//
// app.on("will-quit", (event) => {
// runRunnablesBeforeQuitOfFrontEnd();
// event.preventDefault();
//
// if (isIntegrationTesting || isAutoUpdating) {
// doAsyncQuit(event);
// }
// });
//
// app.on("quit", (event, exitCode) => {
// event.preventDefault();
// doAsyncQuit(event, exitCode);
// });
//
// return undefined;
},
};
},

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 { beforeQuitOfBackEndInjectionToken } from "../start-main-application/runnable-tokens/before-quit-of-back-end-injection-token";
// import { beforeQuitOfBackEndInjectionToken } from "../start-main-application/runnable-tokens/before-quit-of-back-end-injection-token";
import lensProxyInjectable from "./lens-proxy.injectable";
const closeLensProxyOnQuitInjectable = getInjectable({
@ -16,7 +16,7 @@ const closeLensProxyOnQuitInjectable = getInjectable({
await lensProxy.close();
},
}),
injectionToken: beforeQuitOfBackEndInjectionToken,
// injectionToken: beforeQuitOfBackEndInjectionToken,
});
export default closeLensProxyOnQuitInjectable;

View File

@ -15,6 +15,7 @@ import initializeBuildVersionInjectable from "../../vars/build-version/init.inje
import lensProxyCertificateInjectable from "../../../common/certificate/lens-proxy-certificate.injectable";
import fetchInjectable from "../../../common/fetch/fetch.injectable";
import { Agent } from "https";
import appEventBusInjectable from "../../../common/app-event-bus/app-event-bus.injectable";
const setupLensProxyInjectable = getInjectable({
id: "setup-lens-proxy",
@ -30,9 +31,19 @@ const setupLensProxyInjectable = getInjectable({
const lensProxyCertificate = di.inject(lensProxyCertificateInjectable);
const fetch = di.inject(fetchInjectable);
const appEventBus = di.inject(appEventBusInjectable);
return {
id: "setup-lens-proxy",
run: async () => {
appEventBus.addListener((event) => {
console.log('appEventBus listener', event)
if (event.name === 'service' && event.action === 'close') {
console.log('appEventBus listener 1111')
lensProxy.close();
}
})
try {
logger.info("🔌 Starting LensProxy");
await lensProxy.listen(); // lensProxy.port available

View File

@ -3,17 +3,26 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import exitAppInjectable from "./electron-app/features/exit-app.injectable";
import clusterManagerInjectable from "./cluster/manager.injectable";
import loggerInjectable from "../common/logger.injectable";
import closeAllWindowsInjectable from "./start-main-application/lens-window/hide-all-windows/close-all-windows.injectable";
import emitAppEventInjectable from "../common/app-event-bus/emit-event.injectable";
import stopAllExtensionsInjectable from "../features/extensions/stopping/main/stop-all.injectable";
import { runManyFor } from "../common/runnable/run-many-for";
import { beforeQuitOfBackEndInjectionToken } from "./start-main-application/runnable-tokens/before-quit-of-back-end-injection-token";
import exitAppInjectable from "./electron-app/features/exit-app.injectable";
import { startableStoppableMap } from "../common/utils/get-startable-stoppable";
const stopServicesAndExitAppInjectable = getInjectable({
id: "stop-services-and-exit-app",
instantiate: (di) => {
// const app = di.inject(electronAppInjectable);
const runMany = runManyFor(di);
const runRunnablesBeforeQuitOfBackEnd = runMany(
beforeQuitOfBackEndInjectionToken
);
const exitApp = di.inject(exitAppInjectable);
const clusterManager = di.inject(clusterManagerInjectable);
const logger = di.inject(loggerInjectable);
@ -26,8 +35,12 @@ const stopServicesAndExitAppInjectable = getInjectable({
closeAllWindows();
clusterManager.stop();
await stopAllExtensions();
await runRunnablesBeforeQuitOfBackEnd();
console.log([...startableStoppableMap.entries()]);
logger.info("SERVICE:QUIT");
setTimeout(exitApp, 1000);
setTimeout(exitApp, 5000);
};
},
});

View File

@ -0,0 +1,31 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import listeningOnMessageChannelsInjectable from "../../../../common/utils/channel/listening-on-message-channels.injectable";
import listeningOnRequestChannelsInjectable from "./listening-on-request-channels.injectable";
import {
beforeQuitOfBackEndInjectionToken
} from "../../../start-main-application/runnable-tokens/before-quit-of-back-end-injection-token";
const stopListeningOnChannelsInjectable = getInjectable({
id: "stop-listening-on-channels-main",
instantiate: (di) => {
const listeningOnMessageChannels = di.inject(listeningOnMessageChannelsInjectable);
const listeningOnRequestChannels = di.inject(listeningOnRequestChannelsInjectable);
return {
id: "stop-listening-on-channels-main",
run: () => {
listeningOnMessageChannels.stop();
listeningOnRequestChannels.stop();
},
};
},
injectionToken: beforeQuitOfBackEndInjectionToken,
});
export default stopListeningOnChannelsInjectable;

45099
packages/open-lens/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -200,6 +200,7 @@
"@ogre-tools/injectable-extension-for-auto-registration": "^12.0.1",
"@ogre-tools/injectable-extension-for-mobx": "^12.0.1",
"@ogre-tools/injectable-react": "^12.0.1",
"electron-unhandled": "^4.0.1",
"mobx": "^6.8.0",
"rimraf": "^4.1.2"
},

View File

@ -2,6 +2,11 @@ import { createContainer } from "@ogre-tools/injectable";
import { autoRegister } from "@ogre-tools/injectable-extension-for-auto-registration";
import { runInAction } from "mobx";
import { createApp, mainExtensionApi as Main, commonExtensionApi as Common } from "@k8slens/core/main";
import { app as electronApp, crashReporter } from "electron";
console.info("CRASHREPORTER:START");
console.info(electronApp.getPath("crashDumps"));
crashReporter.start({ submitURL: "", uploadToServer: false });
const di = createContainer("main");
const app = createApp({

File diff suppressed because it is too large Load Diff