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

get protocol handling working for linux

Signed-off-by: Sebastian Malton <smalton@mirantis.com>
This commit is contained in:
Sebastian Malton 2021-02-01 17:30:15 -05:00 committed by Sebastian Malton
parent bce07796b1
commit aa5909bdd1
4 changed files with 51 additions and 9 deletions

View File

@ -4,7 +4,6 @@ import { listHelmRepositories } from "../helpers/utils";
import { fail } from "assert";
import open from "open";
jest.setTimeout(60000);
// FIXME (!): improve / simplify all css-selectors + use [data-test-id="some-id"] (already used in some tests below)
@ -29,7 +28,7 @@ describe("Lens integration tests", () => {
await app.client.waitUntilTextExists("h2", "Add Cluster");
});
describe("protocol app start", () => {
describe.only("protocol app start", () => {
it("should handle opening lens:// links", async () => {
await open("lens://app/foobar");

View File

@ -1,8 +1,9 @@
import { AppConstructorOptions, Application } from "spectron";
import * as util from "util";
import { exec } from "child_process";
import fse from "fs-extra";
import { exec, spawnSync } from "child_process";
import fse, { writeFile } from "fs-extra";
import path from "path";
import os from "os";
import { delay } from "../../src/common/utils";
interface AppTestingPaths {
@ -10,7 +11,7 @@ interface AppTestingPaths {
libraryPath: string,
}
function getAppTestingPaths(): AppTestingPaths {
export function getAppTestingPaths(): AppTestingPaths {
switch (process.platform) {
case "win32":
return {
@ -69,6 +70,27 @@ export async function appStart() {
await app.client.windowByIndex(0);
await app.client.waitUntilWindowLoaded();
if (process.platform === "linux") {
const testingDesktop = [
"[Desktop Entry]",
"Name=Lens",
`Exec=${path.resolve(getAppTestingPaths().testingPath)} %U`,
"Terminal=false",
"Type=Application",
"Icon=lens",
"StartupWMClass=Lens",
"Comment=Lens - The Kubernetes IDE",
"MimeType=x-scheme-handler/lens;",
"Categories=Network;"
].join("\n");
await writeFile(path.join(os.homedir(), ".local/share/applications/lens-testing.desktop"), testingDesktop);
const { status } = spawnSync("xdg-settings set default-url-scheme-handler lens lens-testing.desktop", { shell: true });
expect(status).toBe(0);
}
return app;
}
@ -134,6 +156,8 @@ async function* splitLogs(app: Application): AsyncGenerator<LogLines, void, void
const curLogs: string[] = (app as any).chromeDriver.getLogs();
const newLogs = curLogs.slice(lastLogLineCount);
console.log(curLogs);
lastLogLineCount = curLogs.length;
const item: LogLines = {

View File

@ -174,7 +174,10 @@
},
"protocols": {
"name": "Lens Protocol Handler",
"schemes": "lens"
"schemes": [
"lens"
],
"role": "Viewer"
}
},
"lens": {

View File

@ -52,12 +52,28 @@ if (app.commandLine.getSwitchValue("proxy-server") !== "") {
}
if (!app.requestSingleInstanceLock()) {
console.log(process.argv);
app.exit();
} else {
const lprm = LensProtocolRouterMain.getInstance<LensProtocolRouterMain>();
for (const arg of process.argv) {
if (arg.toLowerCase().startsWith("lens://")) {
lprm.route(arg)
.catch(error => logger.error(`${LensProtocolRouterMain.LoggingPrefix}: an error occured`, { error, rawUrl: arg }));
}
}
}
app.on("second-instance", () => {
console.log(process.argv);
app.on("second-instance", (event, argv) => {
const lprm = LensProtocolRouterMain.getInstance<LensProtocolRouterMain>();
for (const arg of argv) {
if (arg.toLowerCase().startsWith("lens://")) {
lprm.route(arg)
.catch(error => logger.error(`${LensProtocolRouterMain.LoggingPrefix}: an error occured`, { error, rawUrl: arg }));
}
}
windowManager?.ensureMainWindow();
});