@ng-desktop/desktop 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EnvironmentProviders, WritableSignal } from '@angular/core';
|
|
1
|
+
import { DestroyRef, EnvironmentProviders, WritableSignal } from '@angular/core';
|
|
2
2
|
import { type NativeConfirmDialogOptions, type NativeMenuItem, type NativeShortcutBinding, type NativeTrayState, type NativeWindowGeometry } from '@ng-desktop/platform';
|
|
3
3
|
import * as i0 from "@angular/core";
|
|
4
4
|
export type NativeThemeMode = 'dark' | 'light';
|
|
@@ -57,11 +57,18 @@ export declare class NativeDesktopService {
|
|
|
57
57
|
setNextConfirmDialogResponse(confirmed: boolean): void;
|
|
58
58
|
loadWindowGeometry(): NativeWindowGeometry;
|
|
59
59
|
saveWindowGeometry(patch: Partial<NativeWindowGeometry>): NativeWindowGeometry;
|
|
60
|
-
setAppMenu(items: readonly NativeMenuItem[], handlers?: Record<string, () => void
|
|
60
|
+
setAppMenu(items: readonly NativeMenuItem[], handlers?: Record<string, () => void>, options?: {
|
|
61
|
+
registerShortcuts?: boolean;
|
|
62
|
+
}): readonly NativeMenuItem[];
|
|
61
63
|
triggerMenuAction(actionId: string): boolean;
|
|
62
64
|
setTray(patch: Partial<NativeTrayState>): NativeTrayState;
|
|
63
65
|
registerShortcut(accelerator: string, actionId: string, handler?: () => void): readonly NativeShortcutBinding[];
|
|
64
66
|
unregisterShortcut(accelerator: string): readonly NativeShortcutBinding[];
|
|
67
|
+
/**
|
|
68
|
+
* Registers a shortcut and returns an idempotent disposer, automatically unbinding on `DestroyRef`
|
|
69
|
+
* when provided or when invoked inside an Angular injection context.
|
|
70
|
+
*/
|
|
71
|
+
bindShortcut(accelerator: string, actionId: string, handler: () => void, destroyRef?: DestroyRef): () => void;
|
|
65
72
|
triggerShortcut(accelerator: string): boolean;
|
|
66
73
|
onWindowResize(handler: (event: NativeResizeEvent) => void, windowNodeId?: string): () => void;
|
|
67
74
|
onWindowFocusChange(handler: (focused: boolean) => void, windowNodeId?: string): () => void;
|
|
@@ -76,4 +83,8 @@ export declare class NativeDesktopService {
|
|
|
76
83
|
static ɵfac: i0.ɵɵFactoryDeclaration<NativeDesktopService, never>;
|
|
77
84
|
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
78
85
|
}
|
|
79
|
-
export
|
|
86
|
+
export interface ProvideNativeDesktopOptions {
|
|
87
|
+
/** Automatically restore window geometry at startup and save it on `beforeunload`. */
|
|
88
|
+
persistWindowGeometry?: boolean;
|
|
89
|
+
}
|
|
90
|
+
export declare function provideNativeDesktop(options?: ProvideNativeDesktopOptions): EnvironmentProviders;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Injectable, makeEnvironmentProviders, signal, } from '@angular/core';
|
|
1
|
+
import { DestroyRef, inject, Injectable, makeEnvironmentProviders, provideEnvironmentInitializer, signal, } from '@angular/core';
|
|
2
2
|
import { ensureNgNativeBridge, } from '@ng-desktop/platform';
|
|
3
3
|
import { NativeComputeService } from './compute-service.js';
|
|
4
4
|
import { NativeFileSystemService } from './fs-service.js';
|
|
@@ -139,7 +139,7 @@ export class NativeDesktopService {
|
|
|
139
139
|
}
|
|
140
140
|
return next;
|
|
141
141
|
}
|
|
142
|
-
setAppMenu(items, handlers) {
|
|
142
|
+
setAppMenu(items, handlers, options) {
|
|
143
143
|
if (handlers) {
|
|
144
144
|
for (const [id, handler] of Object.entries(handlers)) {
|
|
145
145
|
this.actionHandlers.set(id, handler);
|
|
@@ -148,6 +148,13 @@ export class NativeDesktopService {
|
|
|
148
148
|
const updated = this.bridge.setAppMenu?.(items) ??
|
|
149
149
|
items.map((item) => ({ ...item, enabled: item.enabled !== false }));
|
|
150
150
|
this.appMenu.set(updated);
|
|
151
|
+
if (options?.registerShortcuts) {
|
|
152
|
+
for (const item of updated) {
|
|
153
|
+
if (item.accelerator?.trim() && item.enabled !== false) {
|
|
154
|
+
this.registerShortcut(item.accelerator, item.id);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
151
158
|
return updated;
|
|
152
159
|
}
|
|
153
160
|
triggerMenuAction(actionId) {
|
|
@@ -187,6 +194,32 @@ export class NativeDesktopService {
|
|
|
187
194
|
this.shortcuts.set(next);
|
|
188
195
|
return next;
|
|
189
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Registers a shortcut and returns an idempotent disposer, automatically unbinding on `DestroyRef`
|
|
199
|
+
* when provided or when invoked inside an Angular injection context.
|
|
200
|
+
*/
|
|
201
|
+
bindShortcut(accelerator, actionId, handler, destroyRef) {
|
|
202
|
+
this.registerShortcut(accelerator, actionId, handler);
|
|
203
|
+
let disposed = false;
|
|
204
|
+
const dispose = () => {
|
|
205
|
+
if (disposed) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
disposed = true;
|
|
209
|
+
this.unregisterShortcut(accelerator);
|
|
210
|
+
};
|
|
211
|
+
let resolvedDestroyRef = destroyRef ?? null;
|
|
212
|
+
if (!resolvedDestroyRef) {
|
|
213
|
+
try {
|
|
214
|
+
resolvedDestroyRef = inject(DestroyRef, { optional: true });
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
resolvedDestroyRef = null;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
resolvedDestroyRef?.onDestroy(dispose);
|
|
221
|
+
return dispose;
|
|
222
|
+
}
|
|
190
223
|
triggerShortcut(accelerator) {
|
|
191
224
|
const normalized = accelerator.trim().toLowerCase();
|
|
192
225
|
const binding = this.shortcuts().find((item) => item.accelerator.trim().toLowerCase() === normalized);
|
|
@@ -280,12 +313,26 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImpor
|
|
|
280
313
|
type: Injectable,
|
|
281
314
|
args: [{ providedIn: 'root' }]
|
|
282
315
|
}], ctorParameters: () => [] });
|
|
283
|
-
export function provideNativeDesktop() {
|
|
284
|
-
|
|
316
|
+
export function provideNativeDesktop(options) {
|
|
317
|
+
const providers = [
|
|
285
318
|
NativeDesktopService,
|
|
286
319
|
NativeSqliteService,
|
|
287
320
|
NativeNetworkService,
|
|
288
321
|
NativeComputeService,
|
|
289
322
|
NativeFileSystemService,
|
|
290
|
-
]
|
|
323
|
+
];
|
|
324
|
+
if (options?.persistWindowGeometry) {
|
|
325
|
+
return makeEnvironmentProviders([
|
|
326
|
+
...providers,
|
|
327
|
+
provideEnvironmentInitializer(() => {
|
|
328
|
+
const desktop = inject(NativeDesktopService);
|
|
329
|
+
const bridge = ensureNgNativeBridge();
|
|
330
|
+
desktop.loadWindowGeometry();
|
|
331
|
+
bridge.listen('win', 'beforeunload', () => {
|
|
332
|
+
desktop.saveWindowGeometry(desktop.windowGeometry());
|
|
333
|
+
});
|
|
334
|
+
}),
|
|
335
|
+
]);
|
|
336
|
+
}
|
|
337
|
+
return makeEnvironmentProviders(providers);
|
|
291
338
|
}
|
package/package.json
CHANGED