Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

fix: send a local app home to its bundled page, and keep a config inject path with a comma whole

Tw93d25b57bb40fd
diff --git a/bin/utils/validate.ts b/bin/utils/validate.ts
index 43dd4857..6add393b 100644
--- a/bin/utils/validate.ts
+++ b/bin/utils/validate.ts
@@ -72,15 +72,15 @@ export function validateDownloadDirInput(value: string): string {
const INJECT_EXTENSIONS = new Set(['.css', '.js']);
-// Shared by --inject and the config "inject" field, so a config entry is split
-// on commas like the flag and a bad file fails before anything is built.
+// Shared by --inject and the config "inject" field, so a bad file fails before
+// anything is built. The flag has split its value on commas already; a config
+// entry is one path and may hold a comma.
export function validateInjectInput(
inject: string[] | undefined,
cwd: string = process.cwd(),
): string[] {
if (!Array.isArray(inject)) return [];
const files = inject
- .flatMap((entry) => entry.split(','))
.map((item) => item.trim())
.filter((item) => item.length > 0);
diff --git a/dist/cli.js b/dist/cli.js
index 034f43ec..c43895bf 100644
--- a/dist/cli.js
+++ b/dist/cli.js
@@ -1046,13 +1046,13 @@ function validateDownloadDirInput(value) {
return value;
}
const INJECT_EXTENSIONS = new Set(['.css', '.js']);
-// Shared by --inject and the config "inject" field, so a config entry is split
-// on commas like the flag and a bad file fails before anything is built.
+// Shared by --inject and the config "inject" field, so a bad file fails before
+// anything is built. The flag has split its value on commas already; a config
+// entry is one path and may hold a comma.
function validateInjectInput(inject, cwd = process.cwd()) {
if (!Array.isArray(inject))
return [];
const files = inject
- .flatMap((entry) => entry.split(','))
.map((item) => item.trim())
.filter((item) => item.length > 0);
for (const file of files) {
diff --git a/src-tauri/src/inject/event.js b/src-tauri/src/inject/event.js
index dbf2af71..eb34c7ca 100644
--- a/src-tauri/src/inject/event.js
+++ b/src-tauri/src/inject/event.js
@@ -20,13 +20,27 @@ function fallbackNavigate(action) {
} else if (action === "forward") {
window.history.forward();
} else if (action === "home") {
- const homeUrl = window.pakeConfig?.url;
+ const homeUrl = packagedHomeUrl();
if (homeUrl) {
window.location.href = homeUrl;
}
}
}
+// A page on another origin has no IPC, so it goes home by address. A local
+// app's url is only a file name, which would resolve against the site the
+// window is on; its bundled page lives where navigation.rs says it does.
+function packagedHomeUrl() {
+ const url = window.pakeConfig?.url;
+ if (!url || window.pakeConfig?.url_type !== "local") {
+ return url;
+ }
+ const base = /win/i.test(getDesktopPlatform())
+ ? "http://tauri.localhost/"
+ : "tauri://localhost/";
+ return base + url;
+}
+
const shortcuts = {
"[": () => nativeNavigate("back"),
"]": () => nativeNavigate("forward"),
diff --git a/tests/unit/event-fullscreen-shortcuts.test.js b/tests/unit/event-fullscreen-shortcuts.test.js
index 65e3b8b4..d21ba359 100644
--- a/tests/unit/event-fullscreen-shortcuts.test.js
+++ b/tests/unit/event-fullscreen-shortcuts.test.js
@@ -344,6 +344,32 @@ describe("event fullscreen shortcuts", () => {
expect(context.navigateCalls).toEqual([]);
});
+ it("goes home by address from a page that has no IPC", async () => {
+ const press = async (config, platform) => {
+ const context = loadEventHelpers(platform ? { platform } : {});
+ Object.assign(context.window.pakeConfig, config);
+ context.window.location.href = "https://elsewhere.example/page";
+ context.window.__PAKE_NATIVE__.core.invoke = () =>
+ Promise.reject(new Error("not allowed"));
+ getWindowShortcutHandler(context)(
+ createKeyEvent("h", { ctrlKey: true, shiftKey: true }),
+ );
+ await new Promise((resolve) => setTimeout(resolve, 0));
+ return context.window.location.href;
+ };
+
+ expect(await press({ url: "https://example.com/", url_type: "web" })).toBe(
+ "https://example.com/",
+ );
+ // A local app's url is a file name: it must not resolve against the site.
+ expect(await press({ url: "launcher.html", url_type: "local" })).toMatch(
+ /^(http:\/\/tauri\.localhost|tauri:\/\/localhost)\/launcher\.html$/,
+ );
+ expect(
+ await press({ url: "launcher.html", url_type: "local" }, "Linux x86_64"),
+ ).toBe("tauri://localhost/launcher.html");
+ });
+
it("leaves the window shortcuts to the macOS menu", () => {
const context = loadEventHelpers({
userAgent:
diff --git a/tests/unit/validate-inject-input.test.ts b/tests/unit/validate-inject-input.test.ts
index 4bc11f45..106ebe9f 100644
--- a/tests/unit/validate-inject-input.test.ts
+++ b/tests/unit/validate-inject-input.test.ts
@@ -36,11 +36,12 @@ describe('validateInjectInput', () => {
expect(validateInjectInput(['THEME.CSS'], dir)).toEqual(['THEME.CSS']);
});
- it('splits a comma-separated config entry the way the flag does', () => {
- expect(validateInjectInput(['style.css, hotkey.js', ' '], dir)).toEqual([
- 'style.css',
- 'hotkey.js',
- ]);
+ it('keeps a path with a comma whole and drops blank entries', () => {
+ fs.mkdirSync(path.join(dir, 'My, Styles'), { recursive: true });
+ fs.writeFileSync(path.join(dir, 'My, Styles', 'x.css'), '');
+ expect(
+ validateInjectInput([' My, Styles/x.css ', ' ', 'hotkey.js'], dir),
+ ).toEqual(['My, Styles/x.css', 'hotkey.js']);
});
it('rejects a file that is neither CSS nor JS', () => {