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: leave Ctrl+Shift+H alone in a window the page opened

Tw93269c057c6521
diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rs
index a1ec1987..2e764555 100644
--- a/src-tauri/src/app/window.rs
+++ b/src-tauri/src/app/window.rs
@@ -807,7 +807,11 @@ fn build_window(
let config_script = format!(
"window.pakeConfig = {}",
- page_config(window_config, extensions_run(config))
+ page_config(
+ window_config,
+ extensions_run(config),
+ new_window_features.is_some()
+ )
);
// A host-provided marker avoids relying on a site's overridden user agent.
#[cfg(target_os = "windows")]
@@ -1648,12 +1652,18 @@ fn extensions_run(config: &PakeConfig) -> bool {
/// `window.pakeConfig` for the page. An extension that restyles the site turns
/// the runtime's own tweaks off (`site_styles`), but where it does not run they
/// stay, so the site never ends up with neither.
-fn page_config(window_config: &WindowConfig, extensions_run: bool) -> String {
+///
+/// `page_popup` marks a window a page opened, such as a sign-in popup: it is
+/// not the app's window, so the shortcut that goes home leaves it alone.
+fn page_config(window_config: &WindowConfig, extensions_run: bool, page_popup: bool) -> String {
let mut value = serde_json::to_value(window_config).unwrap_or_default();
- if !extensions_run {
- if let Some(object) = value.as_object_mut() {
+ if let Some(object) = value.as_object_mut() {
+ if !extensions_run {
object.insert("site_styles".into(), true.into());
}
+ if page_popup {
+ object.insert("page_popup".into(), true.into());
+ }
}
serde_json::to_string(&value).unwrap_or_else(|_| "{}".to_string())
}
@@ -1668,9 +1678,14 @@ mod site_style_tests {
let config: PakeConfig = serde_json::from_str(include_str!("../../pake.json")).unwrap();
let mut window = config.windows[0].clone();
window.site_styles = false;
- let page =
- |run| serde_json::from_str::<serde_json::Value>(&page_config(&window, run)).unwrap();
+ let page = |run| {
+ serde_json::from_str::<serde_json::Value>(&page_config(&window, run, false)).unwrap()
+ };
assert_eq!(page(true)["site_styles"], false);
assert_eq!(page(false)["site_styles"], true);
+ assert!(page(true).get("page_popup").is_none());
+ let popup: serde_json::Value =
+ serde_json::from_str(&page_config(&window, true, true)).unwrap();
+ assert_eq!(popup["page_popup"], true);
}
}
diff --git a/src-tauri/src/inject/event.js b/src-tauri/src/inject/event.js
index eb34c7ca..21582ff1 100644
--- a/src-tauri/src/inject/event.js
+++ b/src-tauri/src/inject/event.js
@@ -169,7 +169,10 @@ function handleWindowShortcut(event) {
!event.altKey &&
!event.metaKey
) {
- action = shiftShortcuts[event.key?.toLowerCase?.()];
+ // A window the page opened, such as a sign-in popup, is not the app's.
+ action = window.pakeConfig?.page_popup
+ ? undefined
+ : shiftShortcuts[event.key?.toLowerCase?.()];
} else if (
event.altKey &&
!event.ctrlKey &&
diff --git a/tests/unit/event-fullscreen-shortcuts.test.js b/tests/unit/event-fullscreen-shortcuts.test.js
index d21ba359..aa8bd221 100644
--- a/tests/unit/event-fullscreen-shortcuts.test.js
+++ b/tests/unit/event-fullscreen-shortcuts.test.js
@@ -344,6 +344,17 @@ describe("event fullscreen shortcuts", () => {
expect(context.navigateCalls).toEqual([]);
});
+ it("leaves Ctrl+Shift+H alone in a window the page opened", () => {
+ const context = loadEventHelpers();
+ context.window.pakeConfig.page_popup = true;
+ const event = createKeyEvent("h", { ctrlKey: true, shiftKey: true });
+
+ getWindowShortcutHandler(context)(event);
+
+ expect(context.navigateCalls).toEqual([]);
+ expect(event.preventDefault).not.toHaveBeenCalled();
+ });
+
it("goes home by address from a page that has no IPC", async () => {
const press = async (config, platform) => {
const context = loadEventHelpers(platform ? { platform } : {});