@ng-desktop/desktop 0.6.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,5 +1,6 @@
1
1
  import { type NativeComputeMatch } from '@ng-desktop/platform';
2
2
  import * as i0 from "@angular/core";
3
+ /** Result item paired with its original index and fuzzy relevance score from `NativeComputeService`. */
3
4
  export interface NativeScoredItem<T> {
4
5
  item: T;
5
6
  index: number;
@@ -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';
@@ -38,6 +38,7 @@ export interface NativeCloseRequestEvent {
38
38
  export declare class NativeDesktopService {
39
39
  private readonly bridge;
40
40
  private readonly actionHandlers;
41
+ private readonly windowEventMasks;
41
42
  readonly theme: WritableSignal<NativeThemeMode>;
42
43
  readonly windowGeometry: WritableSignal<NativeWindowGeometry>;
43
44
  readonly appMenu: WritableSignal<readonly NativeMenuItem[]>;
@@ -56,11 +57,18 @@ export declare class NativeDesktopService {
56
57
  setNextConfirmDialogResponse(confirmed: boolean): void;
57
58
  loadWindowGeometry(): NativeWindowGeometry;
58
59
  saveWindowGeometry(patch: Partial<NativeWindowGeometry>): NativeWindowGeometry;
59
- setAppMenu(items: readonly NativeMenuItem[], handlers?: Record<string, () => void>): readonly NativeMenuItem[];
60
+ setAppMenu(items: readonly NativeMenuItem[], handlers?: Record<string, () => void>, options?: {
61
+ registerShortcuts?: boolean;
62
+ }): readonly NativeMenuItem[];
60
63
  triggerMenuAction(actionId: string): boolean;
61
64
  setTray(patch: Partial<NativeTrayState>): NativeTrayState;
62
65
  registerShortcut(accelerator: string, actionId: string, handler?: () => void): readonly NativeShortcutBinding[];
63
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;
64
72
  triggerShortcut(accelerator: string): boolean;
65
73
  onWindowResize(handler: (event: NativeResizeEvent) => void, windowNodeId?: string): () => void;
66
74
  onWindowFocusChange(handler: (focused: boolean) => void, windowNodeId?: string): () => void;
@@ -75,4 +83,8 @@ export declare class NativeDesktopService {
75
83
  static ɵfac: i0.ɵɵFactoryDeclaration<NativeDesktopService, never>;
76
84
  static ɵprov: i0.ɵɵInjectableDeclaration<any>;
77
85
  }
78
- export declare function provideNativeDesktop(): EnvironmentProviders;
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';
@@ -50,6 +50,7 @@ function parseBridgePayloadObject(raw) {
50
50
  export class NativeDesktopService {
51
51
  bridge = ensureNgNativeBridge();
52
52
  actionHandlers = new Map();
53
+ windowEventMasks = new Map();
53
54
  theme;
54
55
  windowGeometry;
55
56
  appMenu;
@@ -138,7 +139,7 @@ export class NativeDesktopService {
138
139
  }
139
140
  return next;
140
141
  }
141
- setAppMenu(items, handlers) {
142
+ setAppMenu(items, handlers, options) {
142
143
  if (handlers) {
143
144
  for (const [id, handler] of Object.entries(handlers)) {
144
145
  this.actionHandlers.set(id, handler);
@@ -147,6 +148,13 @@ export class NativeDesktopService {
147
148
  const updated = this.bridge.setAppMenu?.(items) ??
148
149
  items.map((item) => ({ ...item, enabled: item.enabled !== false }));
149
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
+ }
150
158
  return updated;
151
159
  }
152
160
  triggerMenuAction(actionId) {
@@ -186,6 +194,32 @@ export class NativeDesktopService {
186
194
  this.shortcuts.set(next);
187
195
  return next;
188
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
+ }
189
223
  triggerShortcut(accelerator) {
190
224
  const normalized = accelerator.trim().toLowerCase();
191
225
  const binding = this.shortcuts().find((item) => item.accelerator.trim().toLowerCase() === normalized);
@@ -256,7 +290,10 @@ export class NativeDesktopService {
256
290
  this.setPreventClose(options.preventClose, windowNodeId);
257
291
  }
258
292
  else {
259
- this.bridge.setAttribute(windowNodeId, 'event-mask', 'close-request');
293
+ const masks = this.windowEventMasks.get(windowNodeId) ?? new Set();
294
+ masks.add('close-request');
295
+ this.windowEventMasks.set(windowNodeId, masks);
296
+ this.bridge.setAttribute(windowNodeId, 'event-mask', Array.from(masks).join(','));
260
297
  }
261
298
  const unlisten = this.bridge.listen(windowNodeId, 'close-request', (raw) => {
262
299
  const parsed = parseBridgePayloadObject(raw);
@@ -276,12 +313,26 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImpor
276
313
  type: Injectable,
277
314
  args: [{ providedIn: 'root' }]
278
315
  }], ctorParameters: () => [] });
279
- export function provideNativeDesktop() {
280
- return makeEnvironmentProviders([
316
+ export function provideNativeDesktop(options) {
317
+ const providers = [
281
318
  NativeDesktopService,
282
319
  NativeSqliteService,
283
320
  NativeNetworkService,
284
321
  NativeComputeService,
285
322
  NativeFileSystemService,
286
- ]);
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);
287
338
  }
@@ -13,7 +13,7 @@ export class NativeDropTargetDirective {
13
13
  const elRef = inject(ElementRef);
14
14
  const nativeEl = elRef.nativeElement;
15
15
  renderer.setAttribute(nativeEl, 'drop-target', 'true');
16
- this.unlisten = renderer.listen(nativeEl, 'file-drop', (event) => {
16
+ this.unlisten = renderer.listen(nativeEl, 'drop', (event) => {
17
17
  const paths = NativeDropTargetDirective.extractPaths(event);
18
18
  if (paths.length > 0) {
19
19
  this.fileDrop.emit(paths);
@@ -51,6 +51,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImpor
51
51
  type: Directive,
52
52
  args: [{
53
53
  selector: '[ngNativeDropTarget]',
54
- standalone: true,
55
54
  }]
56
55
  }], ctorParameters: () => [], propDecorators: { fileDrop: [{ type: i0.Output, args: ["fileDrop"] }] } });
@@ -1,6 +1,7 @@
1
1
  import { Signal } from '@angular/core';
2
2
  import { type NativeXdgDirKind } from '@ng-desktop/platform';
3
3
  import * as i0 from "@angular/core";
4
+ /** Reactive file-watch handle backed by OS kernel notifications and an Angular `Signal`. */
4
5
  export interface NativeWatchedFileRef<T> {
5
6
  readonly path: string;
6
7
  readonly value: Signal<T>;
@@ -1,5 +1,6 @@
1
1
  import { Signal } from '@angular/core';
2
2
  import * as i0 from "@angular/core";
3
+ /** Signal-backed handle returned by [`NativeSqliteService.liveQuery`]. */
3
4
  export interface NativeLiveQueryRef<T> {
4
5
  readonly rows: Signal<T[]>;
5
6
  readonly count: Signal<number>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-desktop/desktop",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "Linux GTK4 / Desktop OS system services (Theme, Clipboard, Notifications, Dialogs, SQLite, Network, Compute, FileSystem, DropTarget)",
5
5
  "license": "MIT",
6
6
  "keywords": [