mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Consolidate all setupping related to single feature to same runnable
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
1e4a140a55
commit
605ab0683a
@ -8,33 +8,46 @@ import windowManagerInjectable from "../../../window-manager.injectable";
|
|||||||
import { afterApplicationIsReadyInjectionToken } from "../after-application-is-ready-injection-token";
|
import { afterApplicationIsReadyInjectionToken } from "../after-application-is-ready-injection-token";
|
||||||
import whenOpeningUrlInjectable from "../../../electron-app/when-opening-url.injectable";
|
import whenOpeningUrlInjectable from "../../../electron-app/when-opening-url.injectable";
|
||||||
import whenSecondInstanceInjectable from "../../../electron-app/when-second-instance.injectable";
|
import whenSecondInstanceInjectable from "../../../electron-app/when-second-instance.injectable";
|
||||||
|
import loggerInjectable from "../../../../common/logger.injectable";
|
||||||
|
import electronAppInjectable from "../../../electron-app/electron-app.injectable";
|
||||||
|
import type { LensProtocolRouterMain } from "../../../protocol-handler";
|
||||||
|
import { pipeline } from "@ogre-tools/fp";
|
||||||
|
import { find, map, startsWith, toLower } from "lodash/fp";
|
||||||
|
|
||||||
const setupDeepLinking = getInjectable({
|
const setupDeepLinkingInjectable = getInjectable({
|
||||||
id: "setup-deep-linking",
|
id: "setup-deep-linking",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const lensProtocolRouterMain = di.inject(lensProtocolRouterMainInjectable);
|
|
||||||
const windowManager = di.inject(windowManagerInjectable);
|
const windowManager = di.inject(windowManagerInjectable);
|
||||||
const whenOpeningUrl = di.inject(whenOpeningUrlInjectable);
|
const whenOpeningUrl = di.inject(whenOpeningUrlInjectable);
|
||||||
const whenSecondInstance = di.inject(whenSecondInstanceInjectable);
|
const whenSecondInstance = di.inject(whenSecondInstanceInjectable);
|
||||||
|
const logger = di.inject(loggerInjectable);
|
||||||
|
const app = di.inject(electronAppInjectable);
|
||||||
|
const protocolRouter = di.inject(lensProtocolRouterMainInjectable);
|
||||||
|
const routeWithProtocolRouter = routeWithProtocolRouterFor(protocolRouter);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
run: () => {
|
run: async () => {
|
||||||
whenOpeningUrl(({ cancel, url }) => {
|
whenOpeningUrl(async ({ cancel, url }) => {
|
||||||
cancel();
|
cancel();
|
||||||
|
|
||||||
lensProtocolRouterMain.route(url);
|
await protocolRouter.route(url);
|
||||||
});
|
});
|
||||||
|
|
||||||
whenSecondInstance(async ({ commandLineArguments }) => {
|
whenSecondInstance(async ({ commandLineArguments }) => {
|
||||||
for (const arg of commandLineArguments) {
|
await routeWithProtocolRouter(commandLineArguments);
|
||||||
if (arg.toLowerCase().startsWith("lens://")) {
|
|
||||||
await lensProtocolRouterMain.route(arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await windowManager.ensureMainWindow();
|
await windowManager.ensureMainWindow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
logger.info(`📟 Setting protocol client for lens://`);
|
||||||
|
|
||||||
|
if (app.setAsDefaultProtocolClient("lens")) {
|
||||||
|
logger.info("📟 Protocol client register succeeded ✅");
|
||||||
|
} else {
|
||||||
|
logger.info("📟 Protocol client register failed ❗");
|
||||||
|
}
|
||||||
|
|
||||||
|
await routeWithProtocolRouter(process.argv);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -42,4 +55,18 @@ const setupDeepLinking = getInjectable({
|
|||||||
injectionToken: afterApplicationIsReadyInjectionToken,
|
injectionToken: afterApplicationIsReadyInjectionToken,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default setupDeepLinking;
|
const routeWithProtocolRouterFor =
|
||||||
|
(protocolRouter: LensProtocolRouterMain) =>
|
||||||
|
async (commandLineArguments: string[]) => {
|
||||||
|
const route = pipeline(
|
||||||
|
commandLineArguments,
|
||||||
|
map(toLower),
|
||||||
|
find(startsWith("lens://")),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (route) {
|
||||||
|
await protocolRouter.route(route);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default setupDeepLinkingInjectable;
|
||||||
|
|||||||
@ -1,53 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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 { afterApplicationIsReadyInjectionToken } from "../after-application-is-ready-injection-token";
|
|
||||||
import { productName } from "../../../../common/vars";
|
|
||||||
import loggerInjectable from "../../../../common/logger.injectable";
|
|
||||||
import electronAppInjectable from "../../../electron-app/electron-app.injectable";
|
|
||||||
import lensProtocolRouterMainInjectable from "../../../protocol-handler/lens-protocol-router-main/lens-protocol-router-main.injectable";
|
|
||||||
import exitAppInjectable from "../../../electron-app/exit-app.injectable";
|
|
||||||
|
|
||||||
const setupProtocolRouterMainInjectable = getInjectable({
|
|
||||||
id: "setup-protocol-router-main",
|
|
||||||
|
|
||||||
instantiate: (di) => {
|
|
||||||
const logger = di.inject(loggerInjectable);
|
|
||||||
const app = di.inject(electronAppInjectable);
|
|
||||||
const exitApp = di.inject(exitAppInjectable);
|
|
||||||
|
|
||||||
return {
|
|
||||||
run: () => {
|
|
||||||
logger.info(`📟 Setting ${productName} as protocol client for lens://`);
|
|
||||||
|
|
||||||
if (app.setAsDefaultProtocolClient("lens")) {
|
|
||||||
logger.info("📟 Protocol client register succeeded ✅");
|
|
||||||
} else {
|
|
||||||
logger.info("📟 Protocol client register failed ❗");
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.debug("[APP-MAIN] Lens protocol routing main");
|
|
||||||
|
|
||||||
const lensProtocolRouterMain = di.inject(
|
|
||||||
lensProtocolRouterMainInjectable,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!app.requestSingleInstanceLock()) {
|
|
||||||
exitApp();
|
|
||||||
} else {
|
|
||||||
for (const arg of process.argv) {
|
|
||||||
if (arg.toLowerCase().startsWith("lens://")) {
|
|
||||||
lensProtocolRouterMain.route(arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
injectionToken: afterApplicationIsReadyInjectionToken,
|
|
||||||
});
|
|
||||||
|
|
||||||
export default setupProtocolRouterMainInjectable;
|
|
||||||
@ -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 { afterApplicationIsReadyInjectionToken } from "../after-application-is-ready-injection-token";
|
||||||
|
import exitAppInjectable from "../../../electron-app/exit-app.injectable";
|
||||||
|
import electronAppInjectable from "../../../electron-app/electron-app.injectable";
|
||||||
|
|
||||||
|
const setupSingleInstanceLockInjectable = getInjectable({
|
||||||
|
id: "setup-single-instance-lock",
|
||||||
|
|
||||||
|
instantiate: (di) => {
|
||||||
|
const exitApp = di.inject(exitAppInjectable);
|
||||||
|
const app = di.inject(electronAppInjectable);
|
||||||
|
|
||||||
|
return {
|
||||||
|
run: () => {
|
||||||
|
if (!app.requestSingleInstanceLock()) {
|
||||||
|
exitApp();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
injectionToken: afterApplicationIsReadyInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default setupSingleInstanceLockInjectable;
|
||||||
Loading…
Reference in New Issue
Block a user