fix(desktop): accept a bare tray-host flag from dbus-native 0.15

plainValues now defaults to true, so IsStatusNotifierHostRegistered
arrives as true rather than { value: true }. The old check always
failed and minimize-to-tray reported that no tray was available.
This commit is contained in:
686f6c61
2026-09-24 14:28:21 +02:00
committed by brooklyn!
parent 491a3d90ac
commit 0a7a0f8d4e
2 changed files with 20 additions and 1 deletions

View File

@@ -40,6 +40,15 @@ test('a registered host is required, and losing its owner reports loss exactly o
dispose()
})
test('dbus-native 0.15 returns the registered flag as a bare boolean', async () => {
const instance = bus(true)
instance.invoke.mockResolvedValue(true)
const lost = vi.fn()
const dispose = await watchLinuxTrayHost(lost)
expect(lost).not.toHaveBeenCalled()
dispose()
})
test('a missing host and a failed query reject without leaving an open bus connection', async () => {
const lost = vi.fn()
const absent = bus(false)

View File

@@ -1,5 +1,15 @@
import { createClient, type Message, type Variant } from 'dbus-native'
// dbus-native 0.15 defaults plainValues to true, so a property Get returns the
// bare boolean. Older builds still wrap it as { value }.
function statusNotifierHostRegistered(value: unknown): boolean {
if (value === true) {
return true
}
return typeof value === 'object' && value !== null && (value as { value?: unknown }).value === true
}
// Electron can construct a Linux Tray even when the desktop has no tray host
// (notably stock GNOME). Never use that object alone as proof of a restore path.
export async function watchLinuxTrayHost(onLost: () => void): Promise<() => void> {
@@ -93,7 +103,7 @@ export async function watchLinuxTrayHost(onLost: () => void): Promise<() => void
options
)
if (disposed || value.value !== true) {
if (disposed || !statusNotifierHostRegistered(value)) {
throw new Error('No system tray host is available')
}