GeezerVison is showing github.com — perf(desktop): cut foreground GPU repaints, add battery power-saver m… · mediavee/t3code@9949267
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/desktop/src/app/DesktopApp.test.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -68,6 +68,7 @@ import * as DesktopTelemetryPublisher from "../telemetry/DesktopTelemetryPublish | 68 | 68 | import * as DesktopWebLinks from "./DesktopWebLinks.ts"; | 69 | 69 | import * as DesktopWslEnvironment from "../wsl/DesktopWslEnvironment.ts"; | 70 | 70 | import * as ElectronMenu from "../electron/ElectronMenu.ts"; | | 71 | +import * as ElectronPowerMonitor from "../electron/ElectronPowerMonitor.ts"; | 71 | 72 | import * as ElectronShell from "../electron/ElectronShell.ts"; | 72 | 73 | import * as ElectronTheme from "../electron/ElectronTheme.ts"; | 73 | 74 | import * as ElectronWindow from "../electron/ElectronWindow.ts"; | @@ -230,6 +231,7 @@ const runStubbedDesktop = (stub: StubbedDesktop) => | 230 | 231 | Layer.mock(DesktopWebLinks.DesktopWebLinks, {}), | 231 | 232 | Layer.mock(DesktopWslEnvironment.DesktopWslEnvironment, {}), | 232 | 233 | Layer.mock(ElectronMenu.ElectronMenu, {}), | | 234 | + Layer.mock(ElectronPowerMonitor.ElectronPowerMonitor, {}), | 233 | 235 | Layer.mock(ElectronShell.ElectronShell, {}), | 234 | 236 | Layer.mock(ElectronTheme.ElectronTheme, {}), | 235 | 237 | Layer.mock(ElectronWindow.ElectronWindow, {}), | |
Collapse file Copy file name to clipboardExpand all lines: apps/desktop/src/ipc/DesktopIpcHandlers.ts +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -44,7 +44,9 @@ import { | 44 | 44 | getDatabaseMigrationProgress, | 45 | 45 | getLocalEnvironmentBootstraps, | 46 | 46 | getLocalEnvironmentBearerToken, | | 47 | + getOnBatteryPower, | 47 | 48 | installLocalEnvironmentsChangedForwarding, | | 49 | + installPowerStateChangedForwarding, | 48 | 50 | installRelayTelemetryEnabled, | 49 | 51 | getSystemLocale, | 50 | 52 | getPreferredSystemLanguages, | @@ -99,6 +101,7 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers" | 99 | 101 | const ipc = yield* DesktopIpc.DesktopIpc; | 100 | 102 | yield* installNotificationBadge(); | 101 | 103 | yield* installLocalEnvironmentsChangedForwarding(); | | 104 | + yield* installPowerStateChangedForwarding(); | 102 | 105 | yield* PreviewIpc.installPreviewEventForwarding(); | 103 | 106 |
| 104 | 107 | yield* ipc.handle(AppActivationIpc.setReady); | @@ -114,6 +117,7 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers" | 114 | 117 | yield* ipc.handleSync(getPreferredSystemLanguages); | 115 | 118 | yield* ipc.handleSync(getPrimaryPasteEnabled); | 116 | 119 | yield* ipc.handleSync(getWindowFullscreenState); | | 120 | + yield* ipc.handleSync(getOnBatteryPower); | 117 | 121 | yield* ipc.handleSync(getLocalEnvironmentBootstraps); | 118 | 122 | yield* ipc.handleSync(getLocalEnvironmentEnabled); | 119 | 123 | yield* ipc.handle(setLocalEnvironmentEnabled); | |
Collapse file Copy file name to clipboardExpand all lines: apps/desktop/src/ipc/channels.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,6 +20,8 @@ export const TRACKPAD_SCROLL_BEGIN_CHANNEL = "desktop:trackpad-scroll-begin"; | 20 | 20 | export const TRACKPAD_SCROLL_END_CHANNEL = "desktop:trackpad-scroll-end"; | 21 | 21 | export const GET_WINDOW_FULLSCREEN_STATE_CHANNEL = "desktop:get-window-fullscreen-state"; | 22 | 22 | export const WINDOW_FULLSCREEN_STATE_CHANNEL = "desktop:window-fullscreen-state"; | | 23 | +export const GET_ON_BATTERY_POWER_CHANNEL = "desktop:get-on-battery-power"; | | 24 | +export const POWER_STATE_CHANGED_CHANNEL = "desktop:power-state-changed"; | 23 | 25 | export const SYNC_HTML_FULLSCREEN_CHANNEL = "desktop:sync-html-fullscreen"; | 24 | 26 | export const DESKTOP_APP_ACTIVATION_READY_CHANNEL = "desktop:app-activation-ready"; | 25 | 27 | export const DESKTOP_APP_ACTIVATION_COMPLETE_CHANNEL = "desktop:app-activation-complete"; | |
Collapse file Copy file name to clipboardExpand all lines: apps/desktop/src/ipc/methods/window.test.ts +128Lines changed: 128 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -31,15 +31,19 @@ import * as DesktopBackendManager from "../../backend/DesktopBackendManager.ts"; | 31 | 31 | import * as DesktopBackendPool from "../../backend/DesktopBackendPool.ts"; | 32 | 32 | import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts"; | 33 | 33 | import * as DesktopShellEnvironment from "../../shell/DesktopShellEnvironment.ts"; | | 34 | +import * as DesktopTelemetryPublisher from "../../telemetry/DesktopTelemetryPublisher.ts"; | 34 | 35 | import * as DesktopManagedPolicy from "../../app/DesktopManagedPolicy.ts"; | 35 | 36 | import * as DesktopWslEnvironment from "../../wsl/DesktopWslEnvironment.ts"; | 36 | 37 | import * as ElectronDialog from "../../electron/ElectronDialog.ts"; | | 38 | +import * as ElectronPowerMonitor from "../../electron/ElectronPowerMonitor.ts"; | 37 | 39 | import * as ElectronWindow from "../../electron/ElectronWindow.ts"; | 38 | 40 | import * as IpcChannels from "../channels.ts"; | 39 | 41 | import * as DesktopIpc from "../DesktopIpc.ts"; | 40 | 42 | import { | 41 | 43 | getLocalEnvironmentBootstraps, | | 44 | + getOnBatteryPower, | 42 | 45 | installLocalEnvironmentsChangedForwarding, | | 46 | + installPowerStateChangedForwarding, | 43 | 47 | installRelayTelemetryEnabled, | 44 | 48 | pickProjectFavicon, | 45 | 49 | probeRemoteEditors, | @@ -273,6 +277,130 @@ describe("installLocalEnvironmentsChangedForwarding", () => { | 273 | 277 | ); | 274 | 278 | }); | 275 | 279 |
| | 280 | +describe("power state IPC", () => { | | 281 | + it.effect("reads battery power state from ElectronPowerMonitor", () => | | 282 | + Effect.gen(function* () { | | 283 | + assert.isTrue( | | 284 | + yield* getOnBatteryPower.handler().pipe( | | 285 | + Effect.provide( | | 286 | + Layer.mock(ElectronPowerMonitor.ElectronPowerMonitor)({ | | 287 | + isOnBatteryPower: Effect.succeed(true), | | 288 | + }), | | 289 | + ), | | 290 | + ), | | 291 | + ); | | 292 | + assert.isFalse( | | 293 | + yield* getOnBatteryPower.handler().pipe( | | 294 | + Effect.provide( | | 295 | + Layer.mock(ElectronPowerMonitor.ElectronPowerMonitor)({ | | 296 | + isOnBatteryPower: Effect.succeed(false), | | 297 | + }), | | 298 | + ), | | 299 | + ), | | 300 | + ); | | 301 | + }), | | 302 | + ); | | 303 | + | | 304 | + it.effect( | | 305 | + "forwards deduplicated power transitions from powerMonitor, resume, and telemetry", | | 306 | + () => | | 307 | + Effect.gen(function* () { | | 308 | + let currentOnBattery = false; | | 309 | + const listeners = new Map<string, Set<() => void>>(); | | 310 | + const telemetryChanges = yield* PubSub.unbounded<{ | | 311 | + readonly power: { readonly onBattery: "true" | "false" | "unknown" }; | | 312 | + }>(); | | 313 | + const sent: Array<{ readonly channel: string; readonly args: readonly unknown[] }> = []; | | 314 | + const powerLayer = Layer.mock(ElectronPowerMonitor.ElectronPowerMonitor)({ | | 315 | + isOnBatteryPower: Effect.sync(() => currentOnBattery), | | 316 | + onSimpleEvent: (eventName, listener) => | | 317 | + Effect.acquireRelease( | | 318 | + Effect.sync(() => { | | 319 | + let set = listeners.get(eventName); | | 320 | + if (!set) { | | 321 | + set = new Set(); | | 322 | + listeners.set(eventName, set); | | 323 | + } | | 324 | + set.add(listener); | | 325 | + }), | | 326 | + () => | | 327 | + Effect.sync(() => { | | 328 | + listeners.get(eventName)?.delete(listener); | | 329 | + }), | | 330 | + ).pipe(Effect.asVoid), | | 331 | + }); | | 332 | + const telemetryLayer = Layer.mock(DesktopTelemetryPublisher.DesktopTelemetryPublisher)({ | | 333 | + changes: Stream.fromPubSub(telemetryChanges) as never, | | 334 | + }); | | 335 | + const windowLayer = Layer.mock(ElectronWindow.ElectronWindow)({ | | 336 | + sendAll: (channel, ...args) => | | 337 | + Effect.sync(() => { | | 338 | + sent.push({ channel, args }); | | 339 | + }), | | 340 | + }); | | 341 | + | | 342 | + yield* Effect.gen(function* () { | | 343 | + yield* installPowerStateChangedForwarding(); | | 344 | + yield* Effect.yieldNow; | | 345 | + assert.deepEqual(sent, []); | | 346 | + | | 347 | + // Instant macOS/Win32 powerMonitor events emit on change and deduplicate repeats. | | 348 | + for (const listener of listeners.get("on-battery") ?? []) listener(); | | 349 | + yield* Effect.yieldNow; | | 350 | + for (const listener of listeners.get("on-battery") ?? []) listener(); | | 351 | + yield* Effect.yieldNow; | | 352 | + assert.deepEqual(sent, [ | | 353 | + { channel: IpcChannels.POWER_STATE_CHANGED_CHANNEL, args: [true] }, | | 354 | + ]); | | 355 | + | | 356 | + // Duplicate telemetry sample matching current state does not re-emit. | | 357 | + yield* PubSub.publish(telemetryChanges, { power: { onBattery: "true" as const } }); | | 358 | + yield* Effect.yieldNow; | | 359 | + assert.strictEqual(sent.length, 1); | | 360 | + | | 361 | + // Non-macOS telemetry transition (e.g., Windows/Linux) forwards when state changes. | | 362 | + yield* PubSub.publish(telemetryChanges, { power: { onBattery: "false" as const } }); | | 363 | + yield* Effect.yieldNow; | | 364 | + assert.deepEqual(sent, [ | | 365 | + { channel: IpcChannels.POWER_STATE_CHANGED_CHANNEL, args: [true] }, | | 366 | + { channel: IpcChannels.POWER_STATE_CHANGED_CHANNEL, args: [false] }, | | 367 | + ]); | | 368 | + | | 369 | + // Unknown telemetry state is ignored. | | 370 | + yield* PubSub.publish(telemetryChanges, { power: { onBattery: "unknown" as const } }); | | 371 | + yield* Effect.yieldNow; | | 372 | + assert.strictEqual(sent.length, 2); | | 373 | + | | 374 | + // Resume re-reads isOnBatteryPower to catch unplug/plug during sleep. | | 375 | + currentOnBattery = true; | | 376 | + for (const listener of listeners.get("resume") ?? []) listener(); | | 377 | + yield* Effect.yieldNow; | | 378 | + assert.deepEqual(sent, [ | | 379 | + { channel: IpcChannels.POWER_STATE_CHANGED_CHANNEL, args: [true] }, | | 380 | + { channel: IpcChannels.POWER_STATE_CHANGED_CHANNEL, args: [false] }, | | 381 | + { channel: IpcChannels.POWER_STATE_CHANGED_CHANNEL, args: [true] }, | | 382 | + ]); | | 383 | + | | 384 | + for (const listener of listeners.get("on-ac") ?? []) listener(); | | 385 | + yield* Effect.yieldNow; | | 386 | + assert.deepEqual(sent, [ | | 387 | + { channel: IpcChannels.POWER_STATE_CHANGED_CHANNEL, args: [true] }, | | 388 | + { channel: IpcChannels.POWER_STATE_CHANGED_CHANNEL, args: [false] }, | | 389 | + { channel: IpcChannels.POWER_STATE_CHANGED_CHANNEL, args: [true] }, | | 390 | + { channel: IpcChannels.POWER_STATE_CHANGED_CHANNEL, args: [false] }, | | 391 | + ]); | | 392 | + }).pipe( | | 393 | + Effect.scoped, | | 394 | + Effect.provide(Layer.mergeAll(powerLayer, telemetryLayer, windowLayer)), | | 395 | + ); | | 396 | + | | 397 | + assert.strictEqual(listeners.get("on-battery")?.size ?? 0, 0); | | 398 | + assert.strictEqual(listeners.get("on-ac")?.size ?? 0, 0); | | 399 | + assert.strictEqual(listeners.get("resume")?.size ?? 0, 0); | | 400 | + }), | | 401 | + ); | | 402 | +}); | | 403 | + | 276 | 404 | describe("toLocalBackendPath", () => { | 277 | 405 | const { runningDistro: _, ...windowsConfig } = readyWslConfig; | 278 | 406 | it.effect("converts paths through wslpath only for backends running in WSL", () => | |
Collapse file Copy file name to clipboardExpand all lines: apps/desktop/src/ipc/methods/window.ts +52Lines changed: 52 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -24,6 +24,7 @@ import * as FileSystem from "effect/FileSystem"; | 24 | 24 | import * as Path from "effect/Path"; | 25 | 25 | import * as Effect from "effect/Effect"; | 26 | 26 | import * as Option from "effect/Option"; | | 27 | +import * as Queue from "effect/Queue"; | 27 | 28 | import * as Schema from "effect/Schema"; | 28 | 29 | import * as Ref from "effect/Ref"; | 29 | 30 | import * as Stream from "effect/Stream"; | @@ -38,12 +39,14 @@ import * as DesktopManagedPolicy from "../../app/DesktopManagedPolicy.ts"; | 38 | 39 | import * as DesktopPrimaryPaste from "../../app/DesktopPrimaryPaste.ts"; | 39 | 40 | import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts"; | 40 | 41 | import * as DesktopShellEnvironment from "../../shell/DesktopShellEnvironment.ts"; | | 42 | +import * as DesktopTelemetryPublisher from "../../telemetry/DesktopTelemetryPublisher.ts"; | 41 | 43 | import * as DesktopWslBackend from "../../wsl/DesktopWslBackend.ts"; | 42 | 44 | import * as DesktopWslEnvironment from "../../wsl/DesktopWslEnvironment.ts"; | 43 | 45 | import * as ElectronApp from "../../electron/ElectronApp.ts"; | 44 | 46 | import * as ElectronAudio from "../../electron/ElectronAudio.ts"; | 45 | 47 | import * as ElectronDialog from "../../electron/ElectronDialog.ts"; | 46 | 48 | import * as ElectronMenu from "../../electron/ElectronMenu.ts"; | | 49 | +import * as ElectronPowerMonitor from "../../electron/ElectronPowerMonitor.ts"; | 47 | 50 | import * as ElectronShell from "../../electron/ElectronShell.ts"; | 48 | 51 | import * as ElectronTheme from "../../electron/ElectronTheme.ts"; | 49 | 52 | import * as ElectronWindow from "../../electron/ElectronWindow.ts"; | @@ -162,6 +165,55 @@ export const getWindowFullscreenState = DesktopIpc.makeSyncIpcMethod({ | 162 | 165 | }), | 163 | 166 | }); | 164 | 167 |
| | 168 | +export const getOnBatteryPower = DesktopIpc.makeSyncIpcMethod({ | | 169 | + channel: IpcChannels.GET_ON_BATTERY_POWER_CHANNEL, | | 170 | + result: Schema.Boolean, | | 171 | + handler: Effect.fn("desktop.ipc.window.getOnBatteryPower")(function* () { | | 172 | + const powerMonitor = yield* ElectronPowerMonitor.ElectronPowerMonitor; | | 173 | + return yield* powerMonitor.isOnBatteryPower; | | 174 | + }), | | 175 | +}); | | 176 | + | | 177 | +export const installPowerStateChangedForwarding = Effect.fn( | | 178 | + "desktop.ipc.window.installPowerStateChangedForwarding", | | 179 | +)(function* () { | | 180 | + const powerMonitor = yield* ElectronPowerMonitor.ElectronPowerMonitor; | | 181 | + const telemetryPublisher = yield* DesktopTelemetryPublisher.DesktopTelemetryPublisher; | | 182 | + const electronWindow = yield* ElectronWindow.ElectronWindow; | | 183 | + let lastSent = yield* powerMonitor.isOnBatteryPower; | | 184 | + const powerStateSignals = yield* Queue.sliding<boolean | "refresh">(1); | | 185 | + | | 186 | + yield* powerMonitor.onSimpleEvent("on-battery", () => { | | 187 | + Queue.offerUnsafe(powerStateSignals, true); | | 188 | + }); | | 189 | + yield* powerMonitor.onSimpleEvent("on-ac", () => { | | 190 | + Queue.offerUnsafe(powerStateSignals, false); | | 191 | + }); | | 192 | + yield* powerMonitor.onSimpleEvent("resume", () => { | | 193 | + Queue.offerUnsafe(powerStateSignals, "refresh"); | | 194 | + }); | | 195 | + yield* telemetryPublisher.changes.pipe( | | 196 | + Stream.runForEach((snapshot) => { | | 197 | + if (snapshot.power.onBattery === "unknown") return Effect.void; | | 198 | + return Effect.sync(() => { | | 199 | + Queue.offerUnsafe(powerStateSignals, snapshot.power.onBattery === "true"); | | 200 | + }); | | 201 | + }), | | 202 | + Effect.forkScoped({ startImmediately: true }), | | 203 | + ); | | 204 | + yield* Stream.fromQueue(powerStateSignals).pipe( | | 205 | + Stream.runForEach((signal) => | | 206 | + Effect.gen(function* () { | | 207 | + const next = signal === "refresh" ? yield* powerMonitor.isOnBatteryPower : signal; | | 208 | + if (next === lastSent) return; | | 209 | + lastSent = next; | | 210 | + yield* electronWindow.sendAll(IpcChannels.POWER_STATE_CHANGED_CHANNEL, next); | | 211 | + }), | | 212 | + ), | | 213 | + Effect.forkScoped({ startImmediately: true }), | | 214 | + ); | | 215 | +}); | | 216 | + | 165 | 217 | const localEnvironmentSettingsKey = (settings: DesktopAppSettings.DesktopSettings): string => | 166 | 218 | `${settings.localEnvironmentEnabled ? "1" : "0"}|${settings.wslBackendEnabled ? "1" : "0"}|${settings.wslOnly ? "1" : "0"}|${settings.wslDistro ?? ""}`; | 167 | 219 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/desktop/src/preload.test.ts +32Lines changed: 32 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,10 +26,12 @@ describe("desktop preload local environment cache", () => { | 26 | 26 | }, | 27 | 27 | ]; | 28 | 28 | let localEnabled = true; | | 29 | + let onBatteryPower = false; | 29 | 30 |
| 30 | 31 | const sendSync = vi.fn((channel: string) => { | 31 | 32 | if (channel === IpcChannels.GET_LOCAL_ENVIRONMENT_BOOTSTRAPS_CHANNEL) return bootstraps; | 32 | 33 | if (channel === IpcChannels.GET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL) return localEnabled; | | 34 | + if (channel === IpcChannels.GET_ON_BATTERY_POWER_CHANNEL) return onBatteryPower; | 33 | 35 | if (channel === IpcChannels.GET_PRIMARY_PASTE_ENABLED_CHANNEL) return true; | 34 | 36 | return undefined; | 35 | 37 | }); | @@ -141,6 +143,36 @@ describe("desktop preload local environment cache", () => { | 141 | 143 | expect(bridge.getLocalEnvironmentBootstraps()).toEqual(nextBootstraps); | 142 | 144 | expect(bootstrapCalls()).toBe(3); | 143 | 145 |
| | 146 | + // Battery power state is read once via sendSync, then updated via push events with zero polling. | | 147 | + const batteryCalls = () => | | 148 | + sendSync.mock.calls.filter( | | 149 | + ([channel]) => channel === IpcChannels.GET_ON_BATTERY_POWER_CHANNEL, | | 150 | + ).length; | | 151 | + expect(bridge.getOnBatteryPower?.()).toBe(false); | | 152 | + expect(bridge.getOnBatteryPower?.()).toBe(false); | | 153 | + expect(batteryCalls()).toBe(1); | | 154 | + | | 155 | + const observedBatteryStates: boolean[] = []; | | 156 | + const unsubscribePower = bridge.onPowerStateChanged?.((next) => { | | 157 | + observedBatteryStates.push(next); | | 158 | + expect(bridge.getOnBatteryPower?.()).toBe(next); | | 159 | + }); | | 160 | + onBatteryPower = true; | | 161 | + for (const handler of ipcListeners.get(IpcChannels.POWER_STATE_CHANGED_CHANNEL) ?? []) { | | 162 | + handler({}, true); | | 163 | + } | | 164 | + expect(observedBatteryStates).toEqual([true]); | | 165 | + expect(bridge.getOnBatteryPower?.()).toBe(true); | | 166 | + expect(batteryCalls()).toBe(1); | | 167 | + | | 168 | + for (const handler of ipcListeners.get(IpcChannels.POWER_STATE_CHANGED_CHANNEL) ?? []) { | | 169 | + handler({}, false); | | 170 | + } | | 171 | + expect(observedBatteryStates).toEqual([true, false]); | | 172 | + expect(bridge.getOnBatteryPower?.()).toBe(false); | | 173 | + expect(batteryCalls()).toBe(1); | | 174 | + | | 175 | + unsubscribePower?.(); | 144 | 176 | unsubscribe(); | 145 | 177 | }); | 146 | 178 | }); |
Collapse file Copy file name to clipboardExpand all lines: apps/desktop/src/preload.ts +35Lines changed: 35 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -112,6 +112,22 @@ ipcRenderer.on(IpcChannels.LOCAL_ENVIRONMENTS_CHANGED_CHANNEL, () => { | 112 | 112 | } | 113 | 113 | }); | 114 | 114 |
| | 115 | +const powerStateChangedListeners = new Set<(onBattery: boolean) => void>(); | | 116 | +let cachedOnBatteryPower: boolean | undefined; | | 117 | + | | 118 | +ipcRenderer.on( | | 119 | + IpcChannels.POWER_STATE_CHANGED_CHANNEL, | | 120 | + (_event: Electron.IpcRendererEvent, onBattery: unknown) => { | | 121 | + if (typeof onBattery !== "boolean") return; | | 122 | + cachedOnBatteryPower = onBattery; | | 123 | + for (const listener of powerStateChangedListeners) { | | 124 | + try { | | 125 | + listener(onBattery); | | 126 | + } catch {} | | 127 | + } | | 128 | + }, | | 129 | +); | | 130 | + | 115 | 131 | function unwrapEnsureSshEnvironmentResult(result: unknown) { | 116 | 132 | if ( | 117 | 133 | typeof result === "object" && | @@ -376,6 +392,25 @@ contextBridge.exposeInMainWorld("desktopBridge", { | 376 | 392 | getWindowFullscreenState: () => | 377 | 393 | ipcRenderer.sendSync(IpcChannels.GET_WINDOW_FULLSCREEN_STATE_CHANNEL) === true, | 378 | 394 | getWindowZoomFactor: () => webFrame.getZoomFactor(), | | 395 | + getOnBatteryPower: () => { | | 396 | + if (cachedOnBatteryPower !== undefined) { | | 397 | + return cachedOnBatteryPower; | | 398 | + } | | 399 | + try { | | 400 | + const result: unknown = ipcRenderer.sendSync(IpcChannels.GET_ON_BATTERY_POWER_CHANNEL); | | 401 | + if (typeof result === "boolean") { | | 402 | + cachedOnBatteryPower = result; | | 403 | + return result; | | 404 | + } | | 405 | + } catch {} | | 406 | + return false; | | 407 | + }, | | 408 | + onPowerStateChanged: (listener) => { | | 409 | + powerStateChangedListeners.add(listener); | | 410 | + return () => { | | 411 | + powerStateChangedListeners.delete(listener); | | 412 | + }; | | 413 | + }, | 379 | 414 | onWindowFullscreenStateChange: (listener) => { | 380 | 415 | const wrappedListener = (_event: Electron.IpcRendererEvent, fullscreen: unknown) => { | 381 | 416 | if (typeof fullscreen !== "boolean") return; | |
|