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

Extract responsibility to injectable

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2022-05-05 09:02:12 +03:00
parent 678043e34e
commit 96b5771b08
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A
3 changed files with 27 additions and 7 deletions

View File

@ -42,10 +42,14 @@ autoUpdater.logger = {
debug: message => logger.debug(`[AUTO-UPDATE]: electron-updater: %s`, message),
};
interface Dependencies {
isAutoUpdateEnabled: () => boolean;
}
/**
* starts the automatic update checking
*/
export const startUpdateChecking = (isAutoUpdateEnabled : () => boolean) => once(function (interval = 1000 * 60 * 60 * 24): void {
export const startUpdateChecking = ({ isAutoUpdateEnabled } : Dependencies) => once(function (interval = 1000 * 60 * 60 * 24): void {
if (!isAutoUpdateEnabled() || isTestEnv) {
return;
}

View File

@ -4,24 +4,21 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import { afterRootFrameIsReadyInjectionToken } from "../../start-main-application/runnable-tokens/after-root-frame-is-ready-injection-token";
import { startUpdateChecking } from "../../app-updater";
import isAutoUpdateEnabledInjectable from "../../is-auto-update-enabled.injectable";
import startUpdateCheckingInjectable from "../../start-update-checking.injectable";
const setupUpdateCheckingInjectable = getInjectable({
id: "setup-update-checking",
instantiate: (di) => {
const isAutoUpdateEnabled = di.inject(isAutoUpdateEnabledInjectable);
const startUpdateChecking = di.inject(startUpdateCheckingInjectable);
return {
run: () => {
startUpdateChecking(isAutoUpdateEnabled)();
startUpdateChecking();
},
};
},
causesSideEffects: true,
injectionToken: afterRootFrameIsReadyInjectionToken,
});

View File

@ -0,0 +1,19 @@
/**
* 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 { startUpdateChecking } from "./app-updater";
import isAutoUpdateEnabledInjectable from "./is-auto-update-enabled.injectable";
const startUpdateCheckingInjectable = getInjectable({
id: "start-update-checking",
instantiate: (di) => startUpdateChecking({
isAutoUpdateEnabled: di.inject(isAutoUpdateEnabledInjectable),
}),
causesSideEffects: true,
});
export default startUpdateCheckingInjectable;