mirror of
https://github.com/fluxerapp/fluxer.git
synced 2026-11-20 01:01:18 -08:00
fix(desktop): linux unread badges, tray glyph and autostart (#4225)
This commit is contained in:
1 parent
68c00f214d
commit
39f0d380af
20 files changed
+843
-31
No files matched your search
@@ -88,6 +88,12 @@ export declare class SessionStateMonitor {
|
||||
close(): void;
|
||||
}
|
||||
|
||||
export declare class LauncherEntry {
|
||||
constructor(onShellStarted: () => void);
|
||||
|
||||
update(uri: string, count: number, countVisible: boolean): void;
|
||||
}
|
||||
|
||||
export declare function readColorScheme(): 'no-preference' | 'prefer-dark' | 'prefer-light';
|
||||
|
||||
export declare function readContrast(): 'no-preference' | 'high';
|
||||
|
||||
@@ -64,6 +64,7 @@ module.exports = {
|
||||
requestBackground: binding ? binding.requestBackground : null,
|
||||
GlobalShortcutsPortal: binding ? binding.GlobalShortcutsPortal : null,
|
||||
SessionStateMonitor: binding ? binding.SessionStateMonitor : null,
|
||||
LauncherEntry: binding ? binding.LauncherEntry : null,
|
||||
readColorScheme: binding ? binding.readColorScheme : () => 'no-preference',
|
||||
readContrast: binding ? binding.readContrast : () => 'no-preference',
|
||||
readAccentColor: binding ? binding.readAccentColor : () => null,
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
pub const LAUNCHER_ENTRY_PATH: &str = "/com/canonical/unity/launcherentry";
|
||||
pub const LAUNCHER_ENTRY_INTERFACE: &str = "com.canonical.Unity.LauncherEntry";
|
||||
pub const UNITY_SERVICE: &str = "com.canonical.Unity";
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub use emitter::LauncherEntryEmitter;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
mod emitter {
|
||||
use std::{collections::HashMap, thread};
|
||||
|
||||
use zbus::{
|
||||
MatchRule,
|
||||
blocking::{Connection, MessageIterator},
|
||||
message::Type as MessageType,
|
||||
zvariant::Value,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
use crate::session_monitor::{BUS_NAME, BUS_PATH};
|
||||
|
||||
pub struct LauncherEntryEmitter {
|
||||
connection: Connection,
|
||||
}
|
||||
|
||||
impl LauncherEntryEmitter {
|
||||
pub fn connect() -> zbus::Result<Self> {
|
||||
Ok(Self {
|
||||
connection: Connection::session()?,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn update(&self, uri: &str, count: i64, count_visible: bool) -> zbus::Result<()> {
|
||||
let properties = HashMap::from([
|
||||
("count", Value::from(count)),
|
||||
("count-visible", Value::from(count_visible)),
|
||||
]);
|
||||
self.connection.emit_signal(
|
||||
None::<&str>,
|
||||
LAUNCHER_ENTRY_PATH,
|
||||
LAUNCHER_ENTRY_INTERFACE,
|
||||
"Update",
|
||||
&(uri, properties),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn watch_shell(
|
||||
&self,
|
||||
on_shell_started: impl Fn() + Send + 'static,
|
||||
) -> zbus::Result<()> {
|
||||
let messages =
|
||||
MessageIterator::for_match_rule(unity_owner_rule()?, &self.connection, None)?;
|
||||
thread::Builder::new()
|
||||
.name("fluxer-linux-portals-launcher-entry".to_string())
|
||||
.spawn(move || {
|
||||
for message in messages.flatten() {
|
||||
let Ok((_name, _old, new)) =
|
||||
message.body().deserialize::<(String, String, String)>()
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
if !new.is_empty() {
|
||||
on_shell_started();
|
||||
}
|
||||
}
|
||||
})
|
||||
.map_err(|err| zbus::Error::Failure(err.to_string()))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn unity_owner_rule() -> zbus::Result<MatchRule<'static>> {
|
||||
Ok(MatchRule::builder()
|
||||
.msg_type(MessageType::Signal)
|
||||
.sender(BUS_NAME)?
|
||||
.interface(BUS_NAME)?
|
||||
.member("NameOwnerChanged")?
|
||||
.path(BUS_PATH)?
|
||||
.arg(0, UNITY_SERVICE)?
|
||||
.build())
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ pub mod background;
|
||||
pub mod global_shortcuts;
|
||||
pub mod gnome_shell;
|
||||
pub mod kwin;
|
||||
pub mod launcher_entry;
|
||||
#[cfg(target_os = "linux")]
|
||||
pub mod portal;
|
||||
pub mod session_monitor;
|
||||
@@ -33,6 +34,7 @@ mod napi_bindings {
|
||||
is_valid_token, validate_definitions,
|
||||
},
|
||||
gnome_shell, kwin,
|
||||
launcher_entry::{self, LauncherEntryEmitter},
|
||||
session_monitor::{MonitorEvent, SessionMonitor},
|
||||
settings::{self, ChangeEvent, ChangePayload},
|
||||
x11,
|
||||
@@ -441,6 +443,51 @@ mod napi_bindings {
|
||||
}
|
||||
}
|
||||
|
||||
type ShellStartedTsfn = ThreadsafeFunction<(), UnknownReturnValue, (), Status, false, true, 0>;
|
||||
|
||||
#[napi]
|
||||
pub struct LauncherEntry {
|
||||
emitter: LauncherEntryEmitter,
|
||||
}
|
||||
|
||||
#[napi]
|
||||
impl LauncherEntry {
|
||||
#[napi(constructor)]
|
||||
pub fn new(on_shell_started: Function<(), UnknownReturnValue>) -> Result<Self> {
|
||||
let callback: ShellStartedTsfn = on_shell_started
|
||||
.build_threadsafe_function::<()>()
|
||||
.weak::<true>()
|
||||
.callee_handled::<false>()
|
||||
.build()
|
||||
.map_err(|err| {
|
||||
generic_error(format!(
|
||||
"failed to create launcher entry callback: {}",
|
||||
err.reason
|
||||
))
|
||||
})?;
|
||||
let emitter = LauncherEntryEmitter::connect()
|
||||
.map_err(|err| generic_error(format!("failed to open the session bus: {err}")))?;
|
||||
emitter
|
||||
.watch_shell(move || {
|
||||
let _ = callback.call((), ThreadsafeFunctionCallMode::NonBlocking);
|
||||
})
|
||||
.map_err(|err| {
|
||||
generic_error(format!(
|
||||
"failed to watch {}: {err}",
|
||||
launcher_entry::UNITY_SERVICE
|
||||
))
|
||||
})?;
|
||||
Ok(Self { emitter })
|
||||
}
|
||||
|
||||
#[napi]
|
||||
pub fn update(&self, uri: String, count: i64, count_visible: bool) -> Result<()> {
|
||||
self.emitter
|
||||
.update(&uri, count, count_visible)
|
||||
.map_err(|err| generic_error(format!("LauncherEntry Update failed: {err}")))
|
||||
}
|
||||
}
|
||||
|
||||
#[napi(js_name = "readColorScheme")]
|
||||
pub fn read_color_scheme_js() -> &'static str {
|
||||
settings::read_color_scheme().as_str()
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"build": "node scripts/build.mjs",
|
||||
"generate:windows-badges": "electron scripts/generate-windows-badges.mjs",
|
||||
"package:dir": "node scripts/build.mjs && electron-builder --config electron-builder.config.cjs --dir",
|
||||
"test": "vitest run",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -32,7 +33,8 @@
|
||||
"electron": "44.10.0",
|
||||
"electron-builder": "27.0.0-alpha.8",
|
||||
"esbuild": "catalog:",
|
||||
"typescript": "catalog:ts7"
|
||||
"typescript": "catalog:ts7",
|
||||
"vitest": "catalog:"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@fluxer/app-store": "file:./native/app-store",
|
||||
|
||||
@@ -27,6 +27,7 @@ finish-args:
|
||||
- --talk-name=org.kde.kwalletd5
|
||||
- --talk-name=org.kde.kwalletd6
|
||||
- --talk-name=org.kde.StatusNotifierWatcher
|
||||
- --talk-name=com.canonical.Unity
|
||||
- --talk-name=org.ayatana.indicator.application
|
||||
- --talk-name=com.canonical.indicator.application
|
||||
- --talk-name=org.gnome.Mutter.IdleMonitor
|
||||
|
||||
@@ -27,6 +27,7 @@ finish-args:
|
||||
- --talk-name=org.kde.kwalletd5
|
||||
- --talk-name=org.kde.kwalletd6
|
||||
- --talk-name=org.kde.StatusNotifierWatcher
|
||||
- --talk-name=com.canonical.Unity
|
||||
- --talk-name=org.ayatana.indicator.application
|
||||
- --talk-name=com.canonical.indicator.application
|
||||
- --talk-name=org.gnome.Mutter.IdleMonitor
|
||||
|
||||
@@ -49,6 +49,12 @@ export const LINUX_DESKTOP_ENTRY_ID = LINUX_DESKTOP_ENTRY_IDS[BUILD_CHANNEL];
|
||||
export const LINUX_PORTAL_SESSION_TOKEN = LINUX_PORTAL_SESSION_TOKENS[BUILD_CHANNEL];
|
||||
export const LEGACY_LINUX_DESKTOP_ENTRY_ID = LEGACY_LINUX_DESKTOP_ENTRY_IDS[BUILD_CHANNEL];
|
||||
export const LINUX_ICON_NAME = LEGACY_LINUX_DESKTOP_ENTRY_IDS[BUILD_CHANNEL];
|
||||
export const OTHER_CHANNEL_LINUX_DESKTOP_FILES: ReadonlySet<string> = new Set(
|
||||
(Object.keys(LINUX_DESKTOP_ENTRY_IDS) as Array<BuildChannel>)
|
||||
.filter((channel) => channel !== BUILD_CHANNEL)
|
||||
.flatMap((channel) => [LINUX_DESKTOP_ENTRY_IDS[channel], LEGACY_LINUX_DESKTOP_ENTRY_IDS[channel]])
|
||||
.map((id) => `${id}.desktop`),
|
||||
);
|
||||
export const WINDOWS_SHORTCUT_AUTHOR = 'Fluxer Platform AB';
|
||||
export const WINDOWS_VELOPACK_ID = WINDOWS_VELOPACK_IDS[BUILD_CHANNEL];
|
||||
export const WINDOWS_LEGACY_SQUIRREL_ID = 'fluxer_app';
|
||||
|
||||
@@ -58,21 +58,34 @@ function getFlatpakAutostartStatePath(): string {
|
||||
return path.join(app.getPath('userData'), FLATPAK_AUTOSTART_STATE_FILE);
|
||||
}
|
||||
|
||||
function readFlatpakAutostartState(): boolean {
|
||||
interface FlatpakAutostartState {
|
||||
enabled?: unknown;
|
||||
commandline?: unknown;
|
||||
}
|
||||
|
||||
function readFlatpakAutostartStateFile(): FlatpakAutostartState {
|
||||
try {
|
||||
const raw = fs.readFileSync(getFlatpakAutostartStatePath(), 'utf8');
|
||||
const parsed = JSON.parse(raw) as {enabled?: unknown};
|
||||
return parsed.enabled === true;
|
||||
return JSON.parse(fs.readFileSync(getFlatpakAutostartStatePath(), 'utf8')) as FlatpakAutostartState;
|
||||
} catch {
|
||||
return false;
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function readFlatpakAutostartState(): boolean {
|
||||
return readFlatpakAutostartStateFile().enabled === true;
|
||||
}
|
||||
|
||||
async function writeFlatpakAutostartState(enabled: boolean): Promise<void> {
|
||||
try {
|
||||
const statePath = getFlatpakAutostartStatePath();
|
||||
await fs.promises.mkdir(path.dirname(statePath), {recursive: true});
|
||||
await fs.promises.writeFile(statePath, JSON.stringify({version: 1, enabled, updatedAt: new Date().toISOString()}), {
|
||||
const state = {
|
||||
version: 1,
|
||||
enabled,
|
||||
...(enabled ? {commandline: getFlatpakAutostartCommandline()} : {}),
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
await fs.promises.writeFile(statePath, JSON.stringify(state), {
|
||||
encoding: 'utf8',
|
||||
mode: 0o600,
|
||||
});
|
||||
@@ -600,6 +613,23 @@ async function repairLinuxAutostartEntry(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
async function repairFlatpakAutostartEntry(): Promise<void> {
|
||||
if (!isLinux || !isFlatpakRuntime()) return;
|
||||
const state = readFlatpakAutostartStateFile();
|
||||
if (state.enabled !== true) return;
|
||||
const commandline = getFlatpakAutostartCommandline();
|
||||
if (JSON.stringify(state.commandline) === JSON.stringify(commandline)) return;
|
||||
try {
|
||||
await setFlatpakAutostart(true);
|
||||
log.info('[Autostart] Rewrote the Flatpak autostart entry with the current command', {
|
||||
previous: state.commandline,
|
||||
commandline,
|
||||
});
|
||||
} catch (error) {
|
||||
log.warn('[Autostart] Failed to rewrite the stale Flatpak autostart entry:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function windowsLaunchItemMissesAutostartArg(item: Electron.LaunchItems): boolean {
|
||||
return (
|
||||
item.enabled &&
|
||||
@@ -684,6 +714,7 @@ async function migrateLegacyLinuxAutostartEntry(): Promise<void> {
|
||||
|
||||
export function registerAutostartHandlers(): void {
|
||||
void migrateLegacyLinuxAutostartEntry().then(repairLinuxAutostartEntry);
|
||||
void repairFlatpakAutostartEntry();
|
||||
void repairWindowsAutostartEntry();
|
||||
ipcMain.handle('autostart-enable', async (): Promise<void> => {
|
||||
await enableAutostart();
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {
|
||||
desktopExecRunsPath,
|
||||
isAppImageIntegratorEntry,
|
||||
isWindowDesktopEntry,
|
||||
readDesktopEntryValue,
|
||||
setDesktopEntryValue,
|
||||
} from '@electron/main/DesktopEntryText';
|
||||
import {describe, expect, it} from 'vitest';
|
||||
|
||||
const STABLE_CLASSES = ['app.fluxer.FluxerDesktop', 'fluxer'];
|
||||
|
||||
function entry(...lines: Array<string>): string {
|
||||
return ['[Desktop Entry]', 'Type=Application', 'Name=Fluxer', ...lines, ''].join('\n');
|
||||
}
|
||||
|
||||
describe('readDesktopEntryValue', () => {
|
||||
it('reads keys written with spaces around the equals sign', () => {
|
||||
expect(readDesktopEntryValue(entry('StartupWMClass = fluxer'), 'StartupWMClass')).toBe('fluxer');
|
||||
});
|
||||
|
||||
it('ignores localized keys and keys in other groups', () => {
|
||||
const contents = [
|
||||
'[Desktop Entry]',
|
||||
'Name[de]=Fluxer DE',
|
||||
'Name=Fluxer',
|
||||
'',
|
||||
'[Desktop Action new-dm]',
|
||||
'Exec=/opt/other %U',
|
||||
].join('\n');
|
||||
expect(readDesktopEntryValue(contents, 'Name')).toBe('Fluxer');
|
||||
expect(readDesktopEntryValue(contents, 'Exec')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('setDesktopEntryValue', () => {
|
||||
it('replaces a spaced key in place without adding a duplicate', () => {
|
||||
const updated = setDesktopEntryValue(
|
||||
entry('StartupWMClass = fluxer'),
|
||||
'StartupWMClass',
|
||||
'app.fluxer.FluxerDesktop',
|
||||
);
|
||||
expect(updated.match(/StartupWMClass/g)).toHaveLength(1);
|
||||
expect(readDesktopEntryValue(updated, 'StartupWMClass')).toBe('app.fluxer.FluxerDesktop');
|
||||
});
|
||||
|
||||
it('drops repeated keys so the file stays valid', () => {
|
||||
const updated = setDesktopEntryValue(entry('StartupWMClass=a', 'StartupWMClass=b'), 'StartupWMClass', 'c');
|
||||
expect(updated.match(/StartupWMClass/g)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('inserts a missing key at the end of the main group only', () => {
|
||||
const contents = ['[Desktop Entry]', 'Name=Fluxer', '', '[Desktop Action a]', 'Name=A', ''].join('\n');
|
||||
expect(setDesktopEntryValue(contents, 'StartupWMClass', 'x')).toBe(
|
||||
['[Desktop Entry]', 'Name=Fluxer', 'StartupWMClass=x', '', '[Desktop Action a]', 'Name=A', ''].join('\n'),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('desktopExecRunsPath', () => {
|
||||
it('matches the launch command as a whole program token', () => {
|
||||
expect(desktopExecRunsPath('fluxer %U', 'fluxer')).toBe(true);
|
||||
expect(desktopExecRunsPath('/usr/bin/fluxer %U', 'fluxer')).toBe(true);
|
||||
expect(desktopExecRunsPath('env FOO=1 /opt/Fluxer/fluxer %U', '/opt/Fluxer/fluxer')).toBe(true);
|
||||
});
|
||||
|
||||
it('does not match other channels or the Flatpak export for the bare fluxer command', () => {
|
||||
expect(desktopExecRunsPath('/opt/fluxer-canary/fluxer-canary %U', 'fluxer')).toBe(false);
|
||||
expect(desktopExecRunsPath('fluxer-canary %U', 'fluxer')).toBe(false);
|
||||
expect(
|
||||
desktopExecRunsPath(
|
||||
'/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=fluxer --file-forwarding app.fluxer.Fluxer @@u %U @@',
|
||||
'fluxer',
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('does not match a sibling tar.gz install whose path starts with ours', () => {
|
||||
expect(desktopExecRunsPath('/home/u/fluxer/fluxer-canary-x64/fluxer-canary %U', '/home/u/fluxer/fluxer')).toBe(
|
||||
false,
|
||||
);
|
||||
expect(desktopExecRunsPath('/home/u/fluxer/fluxer2 %U', '/home/u/fluxer/fluxer')).toBe(false);
|
||||
});
|
||||
|
||||
it('reads paths quoted and escaped the way our own entry writes them', () => {
|
||||
expect(desktopExecRunsPath('"/home/u/My Apps/Flu\\\\$x.AppImage" %U', '/home/u/My Apps/Flu$x.AppImage')).toBe(true);
|
||||
expect(desktopExecRunsPath("'/home/u/My Apps/fluxer.appimage' %U", '/home/u/My Apps/fluxer.appimage')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isWindowDesktopEntry', () => {
|
||||
const official = {wmClasses: STABLE_CLASSES, launchPath: '/opt/Fluxer/fluxer'};
|
||||
|
||||
it('claims legacy entries that name the old window class or our binary', () => {
|
||||
expect(isWindowDesktopEntry(entry('StartupWMClass=Fluxer', 'Exec=/somewhere/else %U'), official)).toBe(true);
|
||||
expect(isWindowDesktopEntry(entry('Exec=/opt/Fluxer/fluxer %U'), official)).toBe(true);
|
||||
});
|
||||
|
||||
it('skips hidden entries and other channels', () => {
|
||||
expect(isWindowDesktopEntry(entry('Hidden=true', 'Exec=/opt/Fluxer/fluxer %U'), official)).toBe(false);
|
||||
expect(
|
||||
isWindowDesktopEntry(
|
||||
entry('StartupWMClass=app.fluxer.FluxerDesktopCanary', 'Exec="/opt/fluxer-canary/fluxer-canary" %U'),
|
||||
{wmClasses: STABLE_CLASSES, launchPath: 'fluxer'},
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('never claims other Electron apps when running on a stock Electron binary', () => {
|
||||
const stock = {wmClasses: STABLE_CLASSES, launchPath: '/usr/lib/electron44/electron'};
|
||||
expect(isWindowDesktopEntry(entry('Exec=electron44 /usr/lib/other/app.asar %U'), stock)).toBe(false);
|
||||
expect(isWindowDesktopEntry(entry('Exec=/usr/lib/electron44/electron %U', 'StartupWMClass=electron'), stock)).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isAppImageIntegratorEntry', () => {
|
||||
const appImage = '/home/u/AppImages/fluxer.appimage';
|
||||
|
||||
it('accepts the entry Gear Lever writes for the AppImage', () => {
|
||||
const gearLever = entry(
|
||||
`Exec=${appImage} %U`,
|
||||
`TryExec=${appImage}`,
|
||||
'X-AppImage-Version=2026.1116.172250',
|
||||
'X-AppImage-Name=Fluxer',
|
||||
);
|
||||
expect(isAppImageIntegratorEntry(gearLever, appImage)).toBe(true);
|
||||
});
|
||||
|
||||
it('accepts the entry AppImageLauncher writes for the AppImage', () => {
|
||||
const launcher = entry(`Exec="${appImage}" %U`, 'X-AppImage-Identifier=0d1e');
|
||||
expect(isAppImageIntegratorEntry(launcher, appImage)).toBe(true);
|
||||
});
|
||||
|
||||
it('leaves hand-written entries alone', () => {
|
||||
expect(isAppImageIntegratorEntry(entry(`Exec=${appImage} %U`, 'StartupWMClass=fluxer'), appImage)).toBe(false);
|
||||
});
|
||||
|
||||
it('leaves integrator entries for other AppImages alone', () => {
|
||||
const canary = entry('Exec=/home/u/AppImages/fluxer_canary.appimage %U', 'X-AppImage-Name=Fluxer Canary');
|
||||
expect(isAppImageIntegratorEntry(canary, appImage)).toBe(false);
|
||||
expect(isAppImageIntegratorEntry(entry('Exec=fluxer %U', 'X-AppImage-Name=Fluxer'), 'fluxer')).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,171 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import path from 'node:path';
|
||||
|
||||
const MAIN_GROUP = '[Desktop Entry]';
|
||||
const KEY_LINE = /^([A-Za-z0-9-]+)\s*=\s*(.*)$/;
|
||||
const ENV_ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/;
|
||||
|
||||
function isGroupHeader(trimmed: string): boolean {
|
||||
return trimmed.startsWith('[') && trimmed.endsWith(']');
|
||||
}
|
||||
|
||||
function matchKey(trimmed: string, key: string): string | null {
|
||||
const match = KEY_LINE.exec(trimmed);
|
||||
return match !== null && match[1] === key ? match[2].trim() : null;
|
||||
}
|
||||
|
||||
export function readDesktopEntryValue(contents: string, key: string): string | null {
|
||||
let inMainGroup = true;
|
||||
for (const line of contents.split('\n')) {
|
||||
const trimmed = line.trim();
|
||||
if (isGroupHeader(trimmed)) {
|
||||
inMainGroup = trimmed === MAIN_GROUP;
|
||||
continue;
|
||||
}
|
||||
if (!inMainGroup) continue;
|
||||
const value = matchKey(trimmed, key);
|
||||
if (value !== null) return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function hasDesktopEntryKeyPrefix(contents: string, prefix: string): boolean {
|
||||
let inMainGroup = true;
|
||||
for (const line of contents.split('\n')) {
|
||||
const trimmed = line.trim();
|
||||
if (isGroupHeader(trimmed)) {
|
||||
inMainGroup = trimmed === MAIN_GROUP;
|
||||
continue;
|
||||
}
|
||||
if (inMainGroup && trimmed.startsWith(prefix)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function setDesktopEntryValue(contents: string, key: string, value: string): string {
|
||||
const lines = contents.split('\n');
|
||||
const groupStart = lines.findIndex((line) => line.trim() === MAIN_GROUP);
|
||||
if (groupStart === -1) return contents;
|
||||
let groupEnd = lines.length;
|
||||
let replaced = false;
|
||||
const kept: Array<string> = lines.slice(0, groupStart + 1);
|
||||
for (let index = groupStart + 1; index < lines.length; index++) {
|
||||
const trimmed = lines[index].trim();
|
||||
if (isGroupHeader(trimmed)) {
|
||||
groupEnd = index;
|
||||
break;
|
||||
}
|
||||
if (matchKey(trimmed, key) !== null) {
|
||||
if (!replaced) kept.push(`${key}=${value}`);
|
||||
replaced = true;
|
||||
continue;
|
||||
}
|
||||
kept.push(lines[index]);
|
||||
}
|
||||
if (!replaced) {
|
||||
let insertAt = kept.length;
|
||||
while (insertAt > groupStart + 1 && kept[insertAt - 1].trim() === '') insertAt--;
|
||||
kept.splice(insertAt, 0, `${key}=${value}`);
|
||||
}
|
||||
return [...kept, ...lines.slice(groupEnd)].join('\n');
|
||||
}
|
||||
|
||||
function unescapeDesktopValue(value: string): string {
|
||||
return value.replace(/\\([sntr\\])/g, (_, code: string) => {
|
||||
switch (code) {
|
||||
case 's':
|
||||
return ' ';
|
||||
case 'n':
|
||||
return '\n';
|
||||
case 't':
|
||||
return '\t';
|
||||
case 'r':
|
||||
return '\r';
|
||||
default:
|
||||
return '\\';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function splitExecLine(exec: string): Array<string> {
|
||||
const tokens: Array<string> = [];
|
||||
let current = '';
|
||||
let started = false;
|
||||
let quote: '"' | "'" | null = null;
|
||||
for (let index = 0; index < exec.length; index++) {
|
||||
const char = exec[index];
|
||||
if (quote === '"') {
|
||||
if (char === '\\' && index + 1 < exec.length) {
|
||||
current += exec[++index];
|
||||
} else if (char === '"') {
|
||||
quote = null;
|
||||
} else {
|
||||
current += char;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (quote === "'") {
|
||||
if (char === "'") quote = null;
|
||||
else current += char;
|
||||
continue;
|
||||
}
|
||||
if (char === '"' || char === "'") {
|
||||
quote = char;
|
||||
started = true;
|
||||
} else if (char === ' ' || char === '\t') {
|
||||
if (started) tokens.push(current);
|
||||
current = '';
|
||||
started = false;
|
||||
} else {
|
||||
current += char;
|
||||
started = true;
|
||||
}
|
||||
}
|
||||
if (started) tokens.push(current);
|
||||
return tokens;
|
||||
}
|
||||
|
||||
function getDesktopExecProgram(exec: string): string | null {
|
||||
const tokens = splitExecLine(unescapeDesktopValue(exec));
|
||||
let index = 0;
|
||||
if (tokens[index] === 'env' || tokens[index] === '/usr/bin/env') {
|
||||
index++;
|
||||
while (index < tokens.length && ENV_ASSIGNMENT.test(tokens[index])) index++;
|
||||
}
|
||||
return tokens[index] ?? null;
|
||||
}
|
||||
|
||||
export function desktopExecRunsPath(exec: string | null, launchPath: string): boolean {
|
||||
if (exec === null || launchPath.length === 0) return false;
|
||||
const program = getDesktopExecProgram(exec);
|
||||
if (program === null) return false;
|
||||
if (program === launchPath) return true;
|
||||
if (path.isAbsolute(program) && path.isAbsolute(launchPath)) return false;
|
||||
return path.basename(program) === path.basename(launchPath);
|
||||
}
|
||||
|
||||
interface WindowIdentity {
|
||||
wmClasses: ReadonlyArray<string>;
|
||||
launchPath: string;
|
||||
}
|
||||
|
||||
function isStockElectron(launchPath: string): boolean {
|
||||
return /^electron[0-9]*$/.test(path.basename(launchPath));
|
||||
}
|
||||
|
||||
export function isWindowDesktopEntry(contents: string, identity: WindowIdentity): boolean {
|
||||
if (readDesktopEntryValue(contents, 'Hidden') === 'true') return false;
|
||||
const wmClass = readDesktopEntryValue(contents, 'StartupWMClass')?.toLowerCase();
|
||||
if (wmClass !== undefined && identity.wmClasses.some((candidate) => candidate.toLowerCase() === wmClass)) return true;
|
||||
if (isStockElectron(identity.launchPath)) return false;
|
||||
return desktopExecRunsPath(readDesktopEntryValue(contents, 'Exec'), identity.launchPath);
|
||||
}
|
||||
|
||||
export function isAppImageIntegratorEntry(contents: string, appImagePath: string): boolean {
|
||||
return (
|
||||
path.isAbsolute(appImagePath) &&
|
||||
hasDesktopEntryKeyPrefix(contents, 'X-AppImage-') &&
|
||||
getDesktopExecProgram(readDesktopEntryValue(contents, 'Exec') ?? '') === appImagePath
|
||||
);
|
||||
}
|
||||
@@ -325,9 +325,10 @@ function resolveTrayIcon(): {key: string; image: Electron.NativeImage} | null {
|
||||
trayBaseIcon ??= createTrayIcon();
|
||||
if (!trayBaseIcon) return null;
|
||||
const settings = getDesktopWindowBehaviorSettings();
|
||||
const linuxDesktop = getLinuxDesktop();
|
||||
const appearance = resolveTrayIconAppearance({
|
||||
platform: process.platform,
|
||||
linuxDesktop: getLinuxDesktop(),
|
||||
linuxDesktop,
|
||||
coloredTrayIcon: settings.coloredTrayIcon,
|
||||
monochromeTone: settings.monochromeTrayIconTone,
|
||||
darkWindowsTaskbar: nativeTheme.shouldUseDarkColorsForSystemIntegratedUI,
|
||||
@@ -337,7 +338,7 @@ function resolveTrayIcon(): {key: string; image: Electron.NativeImage} | null {
|
||||
const key = `${appearance}:${indicator}`;
|
||||
let image = trayIconCache.get(key);
|
||||
if (!image) {
|
||||
image = renderTrayIcon(trayBaseIcon, appearance, indicator, process.platform);
|
||||
image = renderTrayIcon(trayBaseIcon, appearance, indicator, process.platform, linuxDesktop);
|
||||
trayIconCache.set(key, image);
|
||||
}
|
||||
return {key, image};
|
||||
|
||||
@@ -41,6 +41,7 @@ import {
|
||||
readLinuxAppearance,
|
||||
subscribeLinuxAppearance,
|
||||
} from '@electron/main/LinuxAppearance';
|
||||
import {setLinuxLauncherBadge} from '@electron/main/LinuxLauncherBadge';
|
||||
import {refreshTccStatus, registerMacTccIpcHandlers} from '@electron/main/MacTcc';
|
||||
import {setNativeStrings} from '@electron/main/MainI18n';
|
||||
import {copyRemoteFileToClipboard, parseClipboardWriteFileOptions} from '@electron/main/MediaClipboard';
|
||||
@@ -190,6 +191,8 @@ function applyUnreadBadge(badge: number): void {
|
||||
setWindowsBadgeOverlay(getMainWindow(), badge);
|
||||
} else if (process.platform === 'darwin' && badge === UNREAD_BADGE_DOT) {
|
||||
app.dock?.setBadge('•');
|
||||
} else if (process.platform === 'linux') {
|
||||
setLinuxLauncherBadge(launcherBadgeCount(badge));
|
||||
} else {
|
||||
app.setBadgeCount(launcherBadgeCount(badge));
|
||||
}
|
||||
@@ -351,7 +354,7 @@ export function registerIpcHandlers(): void {
|
||||
const nextSettings = setDesktopWindowBehaviorSettings(normalizeDesktopWindowBehaviorUpdate(settings));
|
||||
applyDesktopWindowBehaviorSettings();
|
||||
refreshWindowsBadgeOverlay(getMainWindow());
|
||||
if (process.platform === 'linux') app.setBadgeCount(launcherBadgeCount(lastUnreadBadge));
|
||||
if (process.platform === 'linux') setLinuxLauncherBadge(launcherBadgeCount(lastUnreadBadge));
|
||||
if (!nextSettings.showTrayIcon) {
|
||||
const mainWindow = getMainWindow();
|
||||
if (mainWindow && !mainWindow.isDestroyed() && !mainWindow.isVisible()) {
|
||||
|
||||
@@ -11,10 +11,17 @@ import {
|
||||
LEGACY_LINUX_DESKTOP_ENTRY_ID,
|
||||
LINUX_DESKTOP_ENTRY_ID,
|
||||
LINUX_ICON_NAME,
|
||||
OTHER_CHANNEL_LINUX_DESKTOP_FILES,
|
||||
} from '@electron/common/DesktopIdentity';
|
||||
import {createChildLogger} from '@electron/common/Logger';
|
||||
import {IS_OFFLINE_BUILD} from '@electron/common/OfflineBuild';
|
||||
import {getAppResourcesPath} from '@electron/main/DesktopDistributionPath';
|
||||
import {
|
||||
desktopExecRunsPath,
|
||||
isAppImageIntegratorEntry,
|
||||
readDesktopEntryValue,
|
||||
setDesktopEntryValue,
|
||||
} from '@electron/main/DesktopEntryText';
|
||||
import {isDirectMessagesAvailable, onDirectMessagesAvailabilityChange, TASK_ARG_PREFIX} from '@electron/main/JumpList';
|
||||
import {getStableLinuxLaunchPath} from '@electron/main/LinuxLaunchPath';
|
||||
import {isFlatpakRuntime} from '@electron/main/LinuxSandbox';
|
||||
@@ -60,6 +67,10 @@ function getUserApplicationsDir(): string {
|
||||
return path.join(getXdgDataHome(), 'applications');
|
||||
}
|
||||
|
||||
export function getLinuxApplicationsDirs(): Array<string> {
|
||||
return [getUserApplicationsDir(), ...getXdgDataDirs().map((dataDir) => path.join(dataDir, 'applications'))];
|
||||
}
|
||||
|
||||
function getDesktopFilePath(): string {
|
||||
return path.join(getUserApplicationsDir(), DESKTOP_FILE_BASENAME);
|
||||
}
|
||||
@@ -82,14 +93,23 @@ function findThirdPartyDesktopEntry(execPath: string): string | null {
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
for (const entry of entries) {
|
||||
if (!entry.endsWith('.desktop') || entry === DESKTOP_FILE_BASENAME) continue;
|
||||
let firstMatch: string | null = null;
|
||||
for (const entry of entries.sort()) {
|
||||
if (
|
||||
!entry.endsWith('.desktop') ||
|
||||
entry === DESKTOP_FILE_BASENAME ||
|
||||
OTHER_CHANNEL_LINUX_DESKTOP_FILES.has(entry)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
const candidate = path.join(applicationsDir, entry);
|
||||
try {
|
||||
if (fs.readFileSync(candidate, 'utf8').includes(execPath)) return candidate;
|
||||
} catch {}
|
||||
const contents = readExistingDesktopFile(candidate);
|
||||
if (contents === null || contents.includes(GENERATED_MARKER)) continue;
|
||||
if (!desktopExecRunsPath(readDesktopEntryValue(contents, 'Exec'), execPath)) continue;
|
||||
if (isAppImageIntegratorEntry(contents, execPath)) return candidate;
|
||||
firstMatch ??= candidate;
|
||||
}
|
||||
return null;
|
||||
return firstMatch;
|
||||
}
|
||||
|
||||
export function escapeDesktopValue(value: string): string {
|
||||
@@ -158,7 +178,7 @@ function buildDesktopFileBody(execPath: string, hidden: boolean): string {
|
||||
'Terminal=false',
|
||||
'Categories=Network;InstantMessaging;Chat;',
|
||||
`MimeType=x-scheme-handler/${APP_PROTOCOL};`,
|
||||
`StartupWMClass=${WM_CLASS}`,
|
||||
...(hidden ? [] : [`StartupWMClass=${WM_CLASS}`]),
|
||||
'SingleMainWindow=true',
|
||||
'StartupNotify=true',
|
||||
...(hidden ? ['NoDisplay=true'] : []),
|
||||
@@ -179,15 +199,6 @@ function buildDesktopFileContents(execPath: string, hidden: boolean): string {
|
||||
);
|
||||
}
|
||||
|
||||
function readDesktopEntryValue(contents: string, key: string): string | null {
|
||||
for (const line of contents.split('\n')) {
|
||||
const trimmed = line.trim();
|
||||
if (trimmed.startsWith('[Desktop Action ')) break;
|
||||
if (trimmed.startsWith(`${key}=`)) return trimmed.slice(key.length + 1).trim();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function isExecutableFile(candidate: string): boolean {
|
||||
try {
|
||||
if (!fs.statSync(candidate).isFile()) return false;
|
||||
@@ -290,11 +301,12 @@ function removeLegacyGeneratedDesktopEntry(): boolean {
|
||||
return removeFile(legacyPath, 'Removed the generated .desktop entry for the previous desktop id');
|
||||
}
|
||||
|
||||
function writeDesktopFileAtomically(filePath: string, contents: string): void {
|
||||
function writeDesktopFileAtomically(filePath: string, contents: string, mode = 0o644): void {
|
||||
const tempPath = `${filePath}.${crypto.randomBytes(8).toString('hex')}.tmp`;
|
||||
try {
|
||||
fs.mkdirSync(path.dirname(filePath), {recursive: true});
|
||||
fs.writeFileSync(tempPath, contents, {encoding: 'utf8', mode: 0o644, flag: 'wx'});
|
||||
fs.writeFileSync(tempPath, contents, {encoding: 'utf8', mode, flag: 'wx'});
|
||||
fs.chmodSync(tempPath, mode);
|
||||
fs.renameSync(tempPath, filePath);
|
||||
} catch (error) {
|
||||
try {
|
||||
@@ -304,6 +316,25 @@ function writeDesktopFileAtomically(filePath: string, contents: string): void {
|
||||
}
|
||||
}
|
||||
|
||||
function claimThirdPartyWindowClass(filePath: string, execPath: string): boolean {
|
||||
if (path.dirname(filePath) !== getUserApplicationsDir()) return false;
|
||||
const contents = readExistingDesktopFile(filePath);
|
||||
if (contents === null || !isAppImageIntegratorEntry(contents, execPath)) return false;
|
||||
if (readDesktopEntryValue(contents, 'StartupWMClass') === WM_CLASS) return false;
|
||||
const updated = setDesktopEntryValue(contents, 'StartupWMClass', WM_CLASS);
|
||||
if (updated === contents) return false;
|
||||
try {
|
||||
const stat = fs.lstatSync(filePath);
|
||||
if (!stat.isFile()) return false;
|
||||
writeDesktopFileAtomically(filePath, updated, stat.mode & 0o777);
|
||||
logger.info('Set our window class on the integrator .desktop entry so the window groups with it', {filePath});
|
||||
return true;
|
||||
} catch (error) {
|
||||
logger.warn('Failed to set the window class on the integrator .desktop entry', {filePath, error});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function syncUserDesktopEntry(): boolean {
|
||||
const execPath = getStableLinuxLaunchPath();
|
||||
const filePath = getDesktopFilePath();
|
||||
@@ -326,10 +357,11 @@ function syncUserDesktopEntry(): boolean {
|
||||
if (thirdPartyEntry) {
|
||||
logger.debug('Another .desktop entry manages the app menu entry; keeping ours hidden', {thirdPartyEntry});
|
||||
}
|
||||
const claimed = thirdPartyEntry !== null && claimThirdPartyWindowClass(thirdPartyEntry, execPath);
|
||||
const desired = buildDesktopFileContents(execPath, thirdPartyEntry !== null);
|
||||
if (existing === desired) {
|
||||
logger.debug('Linux .desktop entry already up to date', {filePath});
|
||||
return false;
|
||||
return claimed;
|
||||
}
|
||||
writeDesktopFileAtomically(filePath, desired);
|
||||
logger.info('Wrote Linux .desktop entry', {filePath, execPath});
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import fs from 'node:fs';
|
||||
import {createRequire} from 'node:module';
|
||||
import path from 'node:path';
|
||||
import {
|
||||
LEGACY_LINUX_DESKTOP_ENTRY_ID,
|
||||
LINUX_DESKTOP_ENTRY_ID,
|
||||
OTHER_CHANNEL_LINUX_DESKTOP_FILES,
|
||||
} from '@electron/common/DesktopIdentity';
|
||||
import {createChildLogger} from '@electron/common/Logger';
|
||||
import {isWindowDesktopEntry} from '@electron/main/DesktopEntryText';
|
||||
import {getLinuxPortalsMode} from '@electron/main/LaunchOptions';
|
||||
import {getLinuxApplicationsDirs} from '@electron/main/LinuxDesktopEntry';
|
||||
import {getStableLinuxLaunchPath} from '@electron/main/LinuxLaunchPath';
|
||||
import {loadOptionalNativeAddon} from '@electron/main/NativeAddon';
|
||||
import {app} from 'electron';
|
||||
|
||||
const logger = createChildLogger('LinuxLauncherBadge');
|
||||
const requireModule = createRequire(import.meta.url);
|
||||
const SETTLE_REFRESH_MS = 30_000;
|
||||
const PERIODIC_REFRESH_MS = 10 * 60_000;
|
||||
|
||||
interface LauncherEntryBinding {
|
||||
update(uri: string, count: number, countVisible: boolean): void;
|
||||
}
|
||||
|
||||
interface LinuxPortalsBinding {
|
||||
LauncherEntry: (new (onShellStarted: () => void) => LauncherEntryBinding) | null;
|
||||
loadError?: Error | null;
|
||||
}
|
||||
|
||||
const loadLinuxPortals = loadOptionalNativeAddon<LinuxPortalsBinding>({
|
||||
platform: 'linux',
|
||||
load: () => requireModule('@fluxer/linux-portals'),
|
||||
logger,
|
||||
level: 'warn',
|
||||
unavailableMessage: 'Failed to load @fluxer/linux-portals, the launcher badge only targets the primary desktop id',
|
||||
disabled: () => getLinuxPortalsMode(process.argv) === 'off',
|
||||
});
|
||||
|
||||
let launcherEntry: LauncherEntryBinding | null | undefined;
|
||||
let badgeCount = 0;
|
||||
let windowDesktopIds: ReadonlyArray<string> = [];
|
||||
let started = false;
|
||||
|
||||
function findWindowDesktopIds(): Array<string> {
|
||||
const identity = {
|
||||
wmClasses: [LINUX_DESKTOP_ENTRY_ID, LEGACY_LINUX_DESKTOP_ENTRY_ID],
|
||||
launchPath: getStableLinuxLaunchPath(),
|
||||
};
|
||||
const primaryDesktopId = process.env.CHROME_DESKTOP;
|
||||
const seen = new Set<string>();
|
||||
const ids: Array<string> = [];
|
||||
for (const dir of getLinuxApplicationsDirs()) {
|
||||
let entries: Array<string>;
|
||||
try {
|
||||
entries = fs.readdirSync(dir);
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
for (const entry of entries) {
|
||||
if (!entry.endsWith('.desktop') || seen.has(entry)) continue;
|
||||
seen.add(entry);
|
||||
if (entry === primaryDesktopId || OTHER_CHANNEL_LINUX_DESKTOP_FILES.has(entry)) continue;
|
||||
let contents: string;
|
||||
try {
|
||||
contents = fs.readFileSync(path.join(dir, entry), 'utf8');
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
if (isWindowDesktopEntry(contents, identity)) ids.push(entry);
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
function getLauncherEntry(): LauncherEntryBinding | null {
|
||||
if (launcherEntry !== undefined) return launcherEntry;
|
||||
const LauncherEntry = loadLinuxPortals()?.LauncherEntry ?? null;
|
||||
try {
|
||||
launcherEntry = LauncherEntry ? new LauncherEntry(emitBadge) : null;
|
||||
} catch (error) {
|
||||
logger.warn('Failed to open the launcher entry emitter', {error});
|
||||
launcherEntry = null;
|
||||
}
|
||||
return launcherEntry;
|
||||
}
|
||||
|
||||
function sendToDesktopIds(desktopIds: ReadonlyArray<string>, count: number): void {
|
||||
if (desktopIds.length === 0) return;
|
||||
const entry = getLauncherEntry();
|
||||
if (!entry) return;
|
||||
for (const desktopId of desktopIds) {
|
||||
try {
|
||||
entry.update(`application://${desktopId}`, count, count !== 0);
|
||||
} catch (error) {
|
||||
logger.warn('Failed to send the launcher badge', {desktopId, error});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function emitBadge(): void {
|
||||
app.setBadgeCount(badgeCount);
|
||||
sendToDesktopIds(windowDesktopIds, badgeCount);
|
||||
}
|
||||
|
||||
function refreshWindowDesktopIds(): void {
|
||||
const next = findWindowDesktopIds();
|
||||
const added = next.filter((id) => !windowDesktopIds.includes(id));
|
||||
if (added.length > 0) {
|
||||
logger.warn('Other desktop entries claim the Fluxer window, sending the launcher badge to them as well', {
|
||||
desktopIds: added,
|
||||
});
|
||||
}
|
||||
sendToDesktopIds(
|
||||
windowDesktopIds.filter((id) => !next.includes(id)),
|
||||
0,
|
||||
);
|
||||
windowDesktopIds = next;
|
||||
emitBadge();
|
||||
}
|
||||
|
||||
export function setLinuxLauncherBadge(count: number): void {
|
||||
badgeCount = count;
|
||||
emitBadge();
|
||||
}
|
||||
|
||||
export function reemitLinuxLauncherBadge(): void {
|
||||
emitBadge();
|
||||
}
|
||||
|
||||
export function startLinuxLauncherBadge(): void {
|
||||
if (process.platform !== 'linux' || started) return;
|
||||
started = true;
|
||||
refreshWindowDesktopIds();
|
||||
getLauncherEntry();
|
||||
setTimeout(refreshWindowDesktopIds, SETTLE_REFRESH_MS).unref();
|
||||
setInterval(refreshWindowDesktopIds, PERIODIC_REFRESH_MS).unref();
|
||||
app.on('will-quit', () => sendToDesktopIds(windowDesktopIds, 0));
|
||||
}
|
||||
@@ -18,6 +18,7 @@ const SUBSAMPLES = 4;
|
||||
const MIN_GLYPH_CONTRAST = 32;
|
||||
const GLYPH_CUTOUT_START = 0.1;
|
||||
const GLYPH_CUTOUT_END = 0.5;
|
||||
const KDE_MONOCHROME_CANVAS_RATIO = 22 / 16;
|
||||
const LINUX_MAX_PIXMAP_SIZE = 256;
|
||||
const PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
|
||||
const DOT_BGR: Bgr = [0x00, 0x00, 0xdd];
|
||||
@@ -189,11 +190,21 @@ function downscaleTrayBitmap(bitmap: TrayBitmap, size: number): TrayBitmap {
|
||||
return {buffer, width: size, height: size};
|
||||
}
|
||||
|
||||
function addMonochromeTrayMargins(bitmap: TrayBitmap, size: number): TrayBitmap {
|
||||
const inset = Math.floor((size - bitmap.width) / 2);
|
||||
const buffer = Buffer.alloc(size * size * 4);
|
||||
for (let y = 0; y < bitmap.height; y++) {
|
||||
bitmap.buffer.copy(buffer, ((inset + y) * size + inset) * 4, y * bitmap.width * 4, (y + 1) * bitmap.width * 4);
|
||||
}
|
||||
return {buffer, width: size, height: size};
|
||||
}
|
||||
|
||||
export function renderTrayIcon(
|
||||
base: NativeImage,
|
||||
appearance: TrayIconAppearance,
|
||||
indicator: boolean,
|
||||
platform: NodeJS.Platform,
|
||||
linuxDesktop: LinuxDesktopKind,
|
||||
): NativeImage {
|
||||
const monochrome = appearance === 'white' || appearance === 'black';
|
||||
if (!monochrome && !indicator) {
|
||||
@@ -202,6 +213,7 @@ export function renderTrayIcon(
|
||||
const result = nativeImage.createEmpty();
|
||||
const scaleFactors = base.getScaleFactors();
|
||||
const linuxMonochrome = platform === 'linux' && monochrome;
|
||||
const kdeMargins = linuxMonochrome && linuxDesktop === 'kde';
|
||||
const representations: Array<{scaleFactor: number; bitmap: TrayBitmap}> = [];
|
||||
for (const scaleFactor of scaleFactors.length > 0 ? scaleFactors : [1]) {
|
||||
if (!Number.isFinite(scaleFactor) || scaleFactor <= 0) continue;
|
||||
@@ -224,6 +236,10 @@ export function renderTrayIcon(
|
||||
representations.push({scaleFactor, bitmap});
|
||||
}
|
||||
if (representations.length === 0) return base;
|
||||
const kdeLogicalCanvasSize = Math.ceil(
|
||||
Math.max(...representations.map(({scaleFactor, bitmap}) => bitmap.width / scaleFactor)) *
|
||||
KDE_MONOCHROME_CANVAS_RATIO,
|
||||
);
|
||||
for (const {scaleFactor, bitmap: source} of representations) {
|
||||
let bitmap = source;
|
||||
if (monochrome) {
|
||||
@@ -237,7 +253,13 @@ export function renderTrayIcon(
|
||||
appearance === 'template' ? TEMPLATE_DOT_BGR : DOT_BGR,
|
||||
);
|
||||
}
|
||||
if (linuxMonochrome) {
|
||||
if (kdeMargins) {
|
||||
const canvasSize = Math.min(Math.ceil(kdeLogicalCanvasSize * scaleFactor), LINUX_MAX_PIXMAP_SIZE);
|
||||
bitmap = addMonochromeTrayMargins(
|
||||
downscaleTrayBitmap(bitmap, Math.floor(canvasSize / KDE_MONOCHROME_CANVAS_RATIO)),
|
||||
canvasSize,
|
||||
);
|
||||
} else if (linuxMonochrome) {
|
||||
bitmap = downscaleTrayBitmap(bitmap, LINUX_MAX_PIXMAP_SIZE);
|
||||
}
|
||||
result.addRepresentation({scaleFactor, ...bitmap});
|
||||
|
||||
@@ -31,6 +31,7 @@ import {drainPendingDisplayMediaRequests, registerDisplayMediaRequestHandler} fr
|
||||
import {isNativeGatewayPermitted} from '@electron/main/GatewaySocketNativeBoundary';
|
||||
import {armHiddenWindowMemoryRelease} from '@electron/main/HiddenWindowMemory';
|
||||
import {shouldDisableV8CodeCache} from '@electron/main/LaunchOptions';
|
||||
import {reemitLinuxLauncherBadge} from '@electron/main/LinuxLauncherBadge';
|
||||
import {getDesktopLocalAppAuthorization} from '@electron/main/LocalAppProtocolAuthorization';
|
||||
import {isLocalAppRendererDocumentURL, isLocalAppURL} from '@electron/main/LocalAppURL';
|
||||
import {cancelPendingFullScreenHide, hideWindowLeavingFullScreen} from '@electron/main/MacFullScreenHide';
|
||||
@@ -1010,6 +1011,10 @@ export function createWindow(options: CreateWindowOptions = {}): BrowserWindow {
|
||||
refreshWindowsBadgeOverlay(mainWindow);
|
||||
});
|
||||
}
|
||||
if (process.platform === 'linux') {
|
||||
mainWindow.on('show', reemitLinuxLauncherBadge);
|
||||
mainWindow.on('focus', reemitLinuxLauncherBadge);
|
||||
}
|
||||
const webContents = mainWindow.webContents;
|
||||
const session = webContents.session;
|
||||
runtimeSecurity.install(session);
|
||||
|
||||
@@ -81,6 +81,7 @@ import {cleanupLegacyHarvestHandlers, registerLegacyHarvestHandlers} from '@elec
|
||||
import {initializeLegacyOriginHarvest} from '@electron/main/LegacyOriginHarvest';
|
||||
import {cleanupVirtmic, registerVirtmicHandlers} from '@electron/main/LinuxAudioCapture';
|
||||
import {ensureLinuxDesktopEntry} from '@electron/main/LinuxDesktopEntry';
|
||||
import {startLinuxLauncherBadge} from '@electron/main/LinuxLauncherBadge';
|
||||
import {cleanupDesktopLocalAppProtocol} from '@electron/main/LocalAppProtocol';
|
||||
import {initializeMainI18n, t} from '@electron/main/MainI18n';
|
||||
import {createApplicationMenu} from '@electron/main/Menu';
|
||||
@@ -825,6 +826,11 @@ export async function finishMainAppStartup(): Promise<void> {
|
||||
} catch (error) {
|
||||
log.error('[Init] Failed to ensure the Linux desktop entry:', error);
|
||||
}
|
||||
try {
|
||||
runStartupPhase('linux-launcher-badge', startLinuxLauncherBadge);
|
||||
} catch (error) {
|
||||
log.error('[Init] Failed to start the Linux launcher badge:', error);
|
||||
}
|
||||
try {
|
||||
runStartupPhase('jump-list', initializeJumpList);
|
||||
} catch (error) {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
export {default} from '../tsconfigs/vitest.base.mts';
|
||||
Generated
+104
-1
@@ -1810,6 +1810,9 @@ importers:
|
||||
typescript:
|
||||
specifier: catalog:ts7
|
||||
version: 7.0.2
|
||||
vitest:
|
||||
specifier: 'catalog:'
|
||||
version: 5.0.5(@opentelemetry/[email protected])(@types/[email protected])([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])))([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected]))
|
||||
optionalDependencies:
|
||||
'@fluxer/app-store':
|
||||
specifier: file:./native/app-store
|
||||
@@ -6392,7 +6395,9 @@ packages:
|
||||
'@smithy/[email protected]':
|
||||
resolution: {integrity: sha512-97imTcCyiPd8k0e9+ts/Sp0W65Dn9Ti357J7M09Ov4tI8Q1JDJVFSoAJtjEVKqfHEr3Pdo2jfolqKCaaiszH0g==}
|
||||
engines: {node: '>=18.0.0'}
|
||||
deprecated: Deprecated due to a bug in custom logger data redaction. See https://github.com/aws/aws-sdk-js-v3/issues/8393.
|
||||
deprecated: |-
|
||||
Deprecated due to a bug in custom logger data redaction. Upgrade to the latest version. If you used a custom logger with this
|
||||
version, review your logs and rotate any credentials or other secrets. See https://github.com/aws/aws-sdk-js-v3/issues/8393.
|
||||
|
||||
'@smithy/[email protected]':
|
||||
resolution: {integrity: sha512-A9uSdn72ozbRUSit0eib0TW7nXuNPlaeM0zcGkJ+nE6tFcSDbnmtwoxbTCFBukVQcszDAyvsd7+rTduPTXpygg==}
|
||||
@@ -11051,6 +11056,7 @@ packages:
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-C630TWXZCZmLq0F2bW4QqwnaaxCQ/svpAqvJwnC4JvgEM5ohhBnGsEzTLSOXcN+xjz+kEaHS5uoWIw2klnqd0A==}
|
||||
deprecated: Partial release, see https://github.com/remusao/tldts/issues/2735. Use >=7.4.22.
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-48dH6aSpQnpbzDUc4vIQZ1VjB8tkK+e8c1yx05/SZK+rkssgjEOlxDd/yU8/a4vGYQ9vRgJr9dwMq9TJ0b3X2Q==}
|
||||
@@ -14454,6 +14460,14 @@ snapshots:
|
||||
|
||||
'@inquirer/[email protected]': {}
|
||||
|
||||
'@inquirer/[email protected](@types/[email protected])':
|
||||
dependencies:
|
||||
'@inquirer/core': 12.0.6(@types/[email protected])
|
||||
'@inquirer/type': 4.2.1(@types/[email protected])
|
||||
optionalDependencies:
|
||||
'@types/node': 24.19.2
|
||||
optional: true
|
||||
|
||||
'@inquirer/[email protected](@types/[email protected])':
|
||||
dependencies:
|
||||
'@inquirer/core': 12.0.6(@types/[email protected])
|
||||
@@ -14461,6 +14475,19 @@ snapshots:
|
||||
optionalDependencies:
|
||||
'@types/node': 26.6.6
|
||||
|
||||
'@inquirer/[email protected](@types/[email protected])':
|
||||
dependencies:
|
||||
'@inquirer/ansi': 2.0.10
|
||||
'@inquirer/figures': 2.0.10
|
||||
'@inquirer/type': 4.2.1(@types/[email protected])
|
||||
cli-width: 4.1.0
|
||||
fast-wrap-ansi: 0.2.2
|
||||
mute-stream: 3.0.0
|
||||
signal-exit: 4.1.0
|
||||
optionalDependencies:
|
||||
'@types/node': 24.19.2
|
||||
optional: true
|
||||
|
||||
'@inquirer/[email protected](@types/[email protected])':
|
||||
dependencies:
|
||||
'@inquirer/ansi': 2.0.10
|
||||
@@ -14475,6 +14502,11 @@ snapshots:
|
||||
|
||||
'@inquirer/[email protected]': {}
|
||||
|
||||
'@inquirer/[email protected](@types/[email protected])':
|
||||
optionalDependencies:
|
||||
'@types/node': 24.19.2
|
||||
optional: true
|
||||
|
||||
'@inquirer/[email protected](@types/[email protected])':
|
||||
optionalDependencies:
|
||||
'@types/node': 26.6.6
|
||||
@@ -16507,6 +16539,16 @@ snapshots:
|
||||
msw: 2.15.0(@types/[email protected])([email protected])
|
||||
vite: 8.3.5(@types/[email protected])([email protected])([email protected])([email protected])([email protected])
|
||||
|
||||
'@vitest/[email protected]([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])))([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected]))':
|
||||
dependencies:
|
||||
'@jridgewell/trace-mapping': 0.3.31
|
||||
'@vitest/spy': 5.0.5
|
||||
estree-walker: 3.0.3
|
||||
magic-string: 1.4.5
|
||||
optionalDependencies:
|
||||
msw: 3.0.3(@types/[email protected])([email protected])([email protected])([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected]))
|
||||
vite: 8.3.5(@types/[email protected])([email protected])([email protected])([email protected])([email protected])
|
||||
|
||||
'@vitest/[email protected]([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])))([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected]))':
|
||||
dependencies:
|
||||
'@jridgewell/trace-mapping': 0.3.31
|
||||
@@ -19891,6 +19933,29 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- '@types/node'
|
||||
|
||||
[email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])):
|
||||
dependencies:
|
||||
'@inquirer/confirm': 6.3.5(@types/[email protected])
|
||||
'@msw/url': 0.1.2
|
||||
'@mswjs/interceptors': 0.45.10([email protected])
|
||||
cookie: 2.0.1
|
||||
headers-polyfill: 5.0.1
|
||||
is-node-process: 1.2.0
|
||||
outvariant: 1.4.3
|
||||
rettime: 0.11.12
|
||||
tough-cookie: 6.0.2
|
||||
type-fest: 5.10.0
|
||||
until-async: 3.0.2
|
||||
yargs: 18.2.0
|
||||
optionalDependencies:
|
||||
graphql: 16.14.2
|
||||
typescript: 7.0.2
|
||||
vite: 8.3.5(@types/[email protected])([email protected])([email protected])([email protected])([email protected])
|
||||
transitivePeerDependencies:
|
||||
- '@types/node'
|
||||
- supports-color
|
||||
optional: true
|
||||
|
||||
[email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])):
|
||||
dependencies:
|
||||
'@inquirer/confirm': 6.3.5(@types/[email protected])
|
||||
@@ -21968,6 +22033,21 @@ snapshots:
|
||||
'@types/unist': 3.0.3
|
||||
vfile-message: 4.0.3
|
||||
|
||||
[email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected]):
|
||||
dependencies:
|
||||
lightningcss: 1.33.0
|
||||
picomatch: 4.0.7
|
||||
postcss: 8.5.32
|
||||
rolldown: 1.2.16
|
||||
tinyglobby: 0.2.17
|
||||
optionalDependencies:
|
||||
'@types/node': 24.19.2
|
||||
esbuild: 0.28.2
|
||||
fsevents: 2.3.3
|
||||
jiti: 2.7.0
|
||||
tsx: 4.23.15
|
||||
yaml: 2.9.1
|
||||
|
||||
[email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected]):
|
||||
dependencies:
|
||||
lightningcss: 1.33.0
|
||||
@@ -21987,6 +22067,29 @@ snapshots:
|
||||
optionalDependencies:
|
||||
vite: 8.3.5(@types/[email protected])([email protected])([email protected])([email protected])([email protected])
|
||||
|
||||
[email protected](@opentelemetry/[email protected])(@types/[email protected])([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])))([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])):
|
||||
dependencies:
|
||||
'@types/chai': 5.2.3
|
||||
'@vitest/mocker': 5.0.5([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])))([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected]))
|
||||
chai: 6.3.0
|
||||
es-module-lexer: 2.3.2
|
||||
expect-type: 1.4.0
|
||||
magic-string: 1.4.5
|
||||
obug: 3.0.0
|
||||
picomatch: 4.0.7
|
||||
std-env: 4.3.0
|
||||
tinybench: 6.2.2
|
||||
tinyexec: 1.3.1
|
||||
tinyglobby: 0.2.17
|
||||
vite: 8.3.5(@types/[email protected])([email protected])([email protected])([email protected])([email protected])
|
||||
why-is-node-running: 3.2.1
|
||||
optionalDependencies:
|
||||
'@opentelemetry/api': 1.9.1
|
||||
'@types/node': 24.19.2
|
||||
happy-dom: 20.14.6
|
||||
transitivePeerDependencies:
|
||||
- msw
|
||||
|
||||
[email protected](@opentelemetry/[email protected])(@types/[email protected])([email protected])([email protected](@types/[email protected])([email protected]))([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])):
|
||||
dependencies:
|
||||
'@types/chai': 5.2.3
|
||||
|
||||
Reference in new issue
Block a user