Skip to content

Commit 8a781c7

Browse files
committed
πŸ› fix: Fix Browser mode: standalone window + correct WM_CLASS
big-webapps-exec: always pass --user-data-dir for all profiles. Previously "Browser" profile skipped it β†’ Brave reused existing instance β†’ --app= flag ignored β†’ URL opened as regular tab. desktop.rs: derive_wm_class now generates correct StartupWMClass for Browser mode matching Chrome/Brave convention: {browser_prefix}-{url_class}-Default (e.g. brave-www.deezer.com__-Default). Add browser_wm_prefix() mapping browser binaries to WM_CLASS prefixes. Add browser_url_class() using url::Url::parse for proper path normalization.
1 parent 5f67e02 commit 8a781c7

2 files changed

Lines changed: 45 additions & 21 deletions

File tree

β€Žbiglinux-webapps/usr/bin/big-webapps-execβ€Ž

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,14 @@ if grep -q '\-BigWebApp' <<< "$filename" && [[ $XDG_SESSION_TYPE == 'wayland' ]]
101101
cp "$filename" "$filename_orig"
102102
# Wait to system detect updated icon
103103
sleep 2
104-
if [[ "$profile" == "Browser" ]]; then
105-
"${browser_exec[@]}" --no-default-browser-check --app="$url" &
106-
else
107-
"${browser_exec[@]}" --no-default-browser-check --user-data-dir="$HOME/.bigwebapps/$browser/$profile" --app="$url" &
108-
fi
104+
"${browser_exec[@]}" --no-default-browser-check --user-data-dir="$HOME/.bigwebapps/$browser/$profile" --app="$url" &
109105

110106
sleep 2
111107
mv -f "$filename_orig_bkp" "$filename_orig"
112108
flock -u 9
113109
else
114110
# another instance holds lock β†’ just launch without icon swap
115-
if [[ "$profile" == "Browser" ]]; then
116-
"${browser_exec[@]}" --no-default-browser-check --app="$url" &
117-
else
118-
"${browser_exec[@]}" --no-default-browser-check --user-data-dir="$HOME/.bigwebapps/$browser/$profile" --app="$url" &
119-
fi
111+
"${browser_exec[@]}" --no-default-browser-check --user-data-dir="$HOME/.bigwebapps/$browser/$profile" --app="$url" &
120112
fi
121113
rm -f "$lockfile"
122114
else
@@ -128,9 +120,5 @@ else
128120
mv -f "$filename_bkp" "$filename"
129121
fi
130122

131-
if [[ "$profile" == "Browser" ]]; then
132-
"${browser_exec[@]}" --no-default-browser-check --app="$url" &
133-
else
134-
"${browser_exec[@]}" --no-default-browser-check --user-data-dir="$HOME/.bigwebapps/$browser/$profile" --app="$url" &
135-
fi
123+
"${browser_exec[@]}" --no-default-browser-check --user-data-dir="$HOME/.bigwebapps/$browser/$profile" --app="$url" &
136124
fi

β€Žcrates/webapps-core/src/desktop.rsβ€Ž

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::path::PathBuf;
77
/// Generate .desktop file content for a webapp
88
pub fn generate_desktop_entry(webapp: &WebApp) -> String {
99
let app_id = desktop_file_id(&webapp.app_url);
10-
let wm_class = derive_wm_class(&webapp.app_url, &webapp.app_mode);
10+
let wm_class = derive_wm_class(webapp);
1111
let has_mime = !webapp.mime_types.is_empty();
1212
let file_arg = if has_mime { " %f" } else { "" };
1313

@@ -69,11 +69,14 @@ pub fn generate_desktop_entry(webapp: &WebApp) -> String {
6969
lines.join("\n") + "\n"
7070
}
7171

72-
/// Derive WM class from URL + mode (matches original big-webapps script)
73-
fn derive_wm_class(url: &str, mode: &AppMode) -> String {
74-
match mode {
72+
/// Derive WM class β€” must match what the browser/viewer actually sets.
73+
/// App mode β†’ custom Freedesktop reverse-DNS.
74+
/// Browser mode β†’ `{browser_prefix}-{url_class}-{profile}` (Chrome/Brave convention).
75+
fn derive_wm_class(webapp: &WebApp) -> String {
76+
match webapp.app_mode {
7577
AppMode::App => {
76-
let app_id = url
78+
let app_id = webapp
79+
.app_url
7780
.replace("https://", "")
7881
.replace("http://", "")
7982
.replace('/', "_")
@@ -82,7 +85,40 @@ fn derive_wm_class(url: &str, mode: &AppMode) -> String {
8285
.collect::<String>();
8386
format!("br.com.biglinux.webapp.{app_id}")
8487
}
85-
AppMode::Browser => derive_class_from_url(url),
88+
AppMode::Browser => {
89+
let url_class = browser_url_class(&webapp.app_url);
90+
let prefix = browser_wm_prefix(&webapp.browser);
91+
// --user-data-dir always creates "Default" profile internally
92+
format!("{prefix}-{url_class}-Default")
93+
}
94+
}
95+
}
96+
97+
/// Map browser binary/id β†’ WM_CLASS prefix that Chrome/Brave/Chromium actually use.
98+
fn browser_wm_prefix(browser: &str) -> &str {
99+
let b = browser
100+
.strip_prefix("flatpak-")
101+
.unwrap_or(browser);
102+
match b {
103+
"brave" | "brave-browser" => "brave",
104+
"google-chrome" | "google-chrome-stable" => "google-chrome",
105+
"chromium" | "chromium-browser" => "chromium",
106+
"microsoft-edge" | "microsoft-edge-stable" => "microsoft-edge",
107+
"vivaldi" | "vivaldi-stable" => "vivaldi",
108+
other => other,
109+
}
110+
}
111+
112+
/// URL β†’ class matching Chrome/Brave convention: strip scheme, replace / β†’ __.
113+
/// Ensures trailing slash for root paths so `deezer.com` β†’ `deezer.com__`.
114+
fn browser_url_class(url: &str) -> String {
115+
if let Ok(parsed) = url::Url::parse(url) {
116+
let host = parsed.host_str().unwrap_or("");
117+
let path = parsed.path();
118+
let path_class = path.replace('/', "__");
119+
format!("{host}{path_class}")
120+
} else {
121+
derive_class_from_url(url)
86122
}
87123
}
88124

0 commit comments

Comments
Β (0)