mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Extract responsibilities from electron
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
5faaa7fa30
commit
6ab70aef22
13
src/common/utils/environment-variables.injectable.ts
Normal file
13
src/common/utils/environment-variables.injectable.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 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";
|
||||
|
||||
const environmentVariablesInjectable = getInjectable({
|
||||
id: "environment-variables",
|
||||
instantiate: () => process.env,
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default environmentVariablesInjectable;
|
||||
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 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 electronAppInjectable from "./electron-app.injectable";
|
||||
|
||||
const disableHardwareAccelerationInjectable = getInjectable({
|
||||
id: "disable-hardware-acceleration",
|
||||
|
||||
instantiate: (di) => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
|
||||
return () => {
|
||||
app.disableHardwareAcceleration();
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default disableHardwareAccelerationInjectable;
|
||||
28
src/main/electron-app/register-file-protocol.injectable.ts
Normal file
28
src/main/electron-app/register-file-protocol.injectable.ts
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 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 { protocol } from "electron";
|
||||
import getAbsolutePathInjectable from "../../common/path/get-absolute-path.injectable";
|
||||
|
||||
const registerFileProtocolInjectable = getInjectable({
|
||||
id: "register-file-protocol",
|
||||
|
||||
instantiate: (di) => {
|
||||
const getAbsolutePath = di.inject(getAbsolutePathInjectable);
|
||||
|
||||
return (name: string, basePath: string) => {
|
||||
protocol.registerFileProtocol(name, (request, callback) => {
|
||||
const filePath = request.url.replace(`${name}://`, "");
|
||||
const absPath = getAbsolutePath(basePath, filePath);
|
||||
|
||||
callback({ path: absPath });
|
||||
});
|
||||
};
|
||||
},
|
||||
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default registerFileProtocolInjectable;
|
||||
@ -4,22 +4,25 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { afterApplicationIsReadyInjectionToken } from "../after-application-is-ready-injection-token";
|
||||
import { registerFileProtocol } from "../../../../common/register-protocol";
|
||||
import registerFileProtocolInjectable from "../../../electron-app/register-file-protocol.injectable";
|
||||
|
||||
// TODO: Remove side effect on import defining __static
|
||||
import "../../../../common/vars";
|
||||
import staticDirInjectable from "../../../../common/vars/static-dir.injectable";
|
||||
|
||||
const setupFileProtocolInjectable = getInjectable({
|
||||
|
||||
id: "setup-file-protocol",
|
||||
|
||||
instantiate: () => ({
|
||||
run: () => {
|
||||
registerFileProtocol("static", __static);
|
||||
},
|
||||
}),
|
||||
instantiate: (di) => {
|
||||
const registerFileProtocol = di.inject(registerFileProtocolInjectable);
|
||||
const staticDir = di.inject(staticDirInjectable);
|
||||
|
||||
causesSideEffects: true,
|
||||
return {
|
||||
run: () => {
|
||||
registerFileProtocol("static", staticDir);
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: afterApplicationIsReadyInjectionToken,
|
||||
});
|
||||
|
||||
@ -4,25 +4,25 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { afterApplicationIsReadyInjectionToken } from "../after-application-is-ready-injection-token";
|
||||
import electronAppInjectable from "../../../electron-app/electron-app.injectable";
|
||||
import environmentVariablesInjectable from "../../../../common/utils/environment-variables.injectable";
|
||||
import disableHardwareAccelerationInjectable from "../../../electron-app/disable-hardware-acceleration.injectable";
|
||||
|
||||
const setupHardwareAccelerationInjectable = getInjectable({
|
||||
id: "setup-hardware-acceleration",
|
||||
|
||||
instantiate: (di) => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const { LENS_DISABLE_GPU: hardwareAccelerationShouldBeDisabled } = di.inject(environmentVariablesInjectable);
|
||||
const disableHardwareAcceleration = di.inject(disableHardwareAccelerationInjectable);
|
||||
|
||||
return {
|
||||
run: async () => {
|
||||
if (process.env.LENS_DISABLE_GPU) {
|
||||
app.disableHardwareAcceleration();
|
||||
run: () => {
|
||||
if (hardwareAccelerationShouldBeDisabled) {
|
||||
disableHardwareAcceleration();
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
causesSideEffects: true,
|
||||
|
||||
injectionToken: afterApplicationIsReadyInjectionToken,
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user