@ng-desktop/desktop 0.0.0-stage → 0.4.0
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.
- package/LICENSE +21 -0
- package/README.md +13 -2
- package/fesm2022/compute-service.d.ts +19 -0
- package/fesm2022/compute-service.js +31 -0
- package/fesm2022/desktop-service.d.ts +78 -0
- package/fesm2022/desktop-service.js +287 -0
- package/fesm2022/drop-target.directive.d.ts +20 -0
- package/fesm2022/drop-target.directive.js +56 -0
- package/fesm2022/fs-service.d.ts +26 -0
- package/fesm2022/fs-service.js +83 -0
- package/fesm2022/index.d.ts +6 -0
- package/fesm2022/index.js +6 -0
- package/fesm2022/network-service.d.ts +18 -0
- package/fesm2022/network-service.js +42 -0
- package/fesm2022/sqlite-service.d.ts +22 -0
- package/fesm2022/sqlite-service.js +62 -0
- package/package.json +50 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gaspar1992 and NgDesktop Engine Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ng-desktop/desktop
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Linux GTK4 / Desktop OS system services (Theme, Clipboard, Notifications, Dialogs, SQLite, Network, Compute, FileSystem, DropTarget)
|
|
4
|
+
|
|
5
|
+
Part of **[NgDesktop Engine](https://github.com/Gaspar1992/ng-desktop-engine)** — Native desktop rendering engine for Angular 22+ (`GTK4`, `WinUI 3`, `AppKit`).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @ng-desktop/desktop
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
- Repository path: `packages/desktop-native`
|
|
14
|
+
- Documentation & Ecosystem Guide: https://github.com/Gaspar1992/ng-desktop-engine/blob/main/docs/ECOSYSTEM_COMPATIBILITY.md
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type NativeComputeMatch } from '@ng-desktop/platform';
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
export interface NativeScoredItem<T> {
|
|
4
|
+
item: T;
|
|
5
|
+
index: number;
|
|
6
|
+
score: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Injectable Angular service delegating CPU-intensive fuzzy search, scoring, and FNV-1a hashing
|
|
10
|
+
* to the multithreaded Rust `NativeComputePool` without blocking the UI thread.
|
|
11
|
+
*/
|
|
12
|
+
export declare class NativeComputeService {
|
|
13
|
+
private readonly bridge;
|
|
14
|
+
fuzzyFilterStrings(items: readonly string[], query: string, limit?: number): NativeComputeMatch[];
|
|
15
|
+
fuzzyFilter<T>(items: readonly T[], selector: (item: T) => string, query: string, limit?: number): NativeScoredItem<T>[];
|
|
16
|
+
hash(input: string): string;
|
|
17
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NativeComputeService, never>;
|
|
18
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { ensureNgNativeBridge } from '@ng-desktop/platform';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
/**
|
|
5
|
+
* Injectable Angular service delegating CPU-intensive fuzzy search, scoring, and FNV-1a hashing
|
|
6
|
+
* to the multithreaded Rust `NativeComputePool` without blocking the UI thread.
|
|
7
|
+
*/
|
|
8
|
+
export class NativeComputeService {
|
|
9
|
+
bridge = ensureNgNativeBridge();
|
|
10
|
+
fuzzyFilterStrings(items, query, limit = 50) {
|
|
11
|
+
return this.bridge.computeFuzzyFilter(items, query, limit);
|
|
12
|
+
}
|
|
13
|
+
fuzzyFilter(items, selector, query, limit = 50) {
|
|
14
|
+
const keys = items.map((item) => selector(item));
|
|
15
|
+
const matches = this.bridge.computeFuzzyFilter(keys, query, limit);
|
|
16
|
+
return matches.map((m) => ({
|
|
17
|
+
item: items[m.index],
|
|
18
|
+
index: m.index,
|
|
19
|
+
score: m.score,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
hash(input) {
|
|
23
|
+
return this.bridge.computeHash(input);
|
|
24
|
+
}
|
|
25
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeComputeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
26
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeComputeService, providedIn: 'root' });
|
|
27
|
+
}
|
|
28
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeComputeService, decorators: [{
|
|
29
|
+
type: Injectable,
|
|
30
|
+
args: [{ providedIn: 'root' }]
|
|
31
|
+
}] });
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { EnvironmentProviders, WritableSignal } from '@angular/core';
|
|
2
|
+
import { type NativeConfirmDialogOptions, type NativeMenuItem, type NativeShortcutBinding, type NativeTrayState, type NativeWindowGeometry } from '@ng-desktop/platform';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
export type NativeThemeMode = 'dark' | 'light';
|
|
5
|
+
export type { NativeMenuItem, NativeShortcutBinding, NativeTrayState, NativeWindowGeometry, } from '@ng-desktop/platform';
|
|
6
|
+
export type ConfirmDialogOptions = NativeConfirmDialogOptions;
|
|
7
|
+
export interface OpenFileDialogOptions {
|
|
8
|
+
title?: string;
|
|
9
|
+
defaultPath?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface SaveFileDialogOptions {
|
|
12
|
+
title?: string;
|
|
13
|
+
suggestedName?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface NativeScrollEvent {
|
|
16
|
+
scrollTop: number;
|
|
17
|
+
scrollHeight: number;
|
|
18
|
+
clientHeight: number;
|
|
19
|
+
atTop: boolean;
|
|
20
|
+
atBottom: boolean;
|
|
21
|
+
progress: number;
|
|
22
|
+
}
|
|
23
|
+
export interface NativeResizeEvent {
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
|
+
maximized: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface NativeCloseRequestEvent {
|
|
29
|
+
preventable: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Injectable Angular service providing reactive access to native Desktop OS capabilities:
|
|
33
|
+
* - System Dark/Light theme (`theme` signal synchronized with `GtkSettings` / `AdwStyleManager`)
|
|
34
|
+
* - Native Clipboard (`GdkClipboard`)
|
|
35
|
+
* - Desktop Notifications (`GNotification`)
|
|
36
|
+
* - Native File Dialogs (`GtkFileDialog` open/save)
|
|
37
|
+
*/
|
|
38
|
+
export declare class NativeDesktopService {
|
|
39
|
+
private readonly bridge;
|
|
40
|
+
private readonly actionHandlers;
|
|
41
|
+
readonly theme: WritableSignal<NativeThemeMode>;
|
|
42
|
+
readonly windowGeometry: WritableSignal<NativeWindowGeometry>;
|
|
43
|
+
readonly appMenu: WritableSignal<readonly NativeMenuItem[]>;
|
|
44
|
+
readonly trayState: WritableSignal<NativeTrayState>;
|
|
45
|
+
readonly shortcuts: WritableSignal<readonly NativeShortcutBinding[]>;
|
|
46
|
+
readonly windowFocused: WritableSignal<boolean>;
|
|
47
|
+
constructor();
|
|
48
|
+
setTheme(mode: NativeThemeMode): void;
|
|
49
|
+
toggleTheme(): NativeThemeMode;
|
|
50
|
+
getClipboardText(): string;
|
|
51
|
+
setClipboardText(text: string): void;
|
|
52
|
+
notify(title: string, body: string, icon?: string): void;
|
|
53
|
+
openFileDialog(options?: OpenFileDialogOptions): string;
|
|
54
|
+
saveFileDialog(options?: SaveFileDialogOptions): string;
|
|
55
|
+
confirmDialog(options?: ConfirmDialogOptions): boolean;
|
|
56
|
+
setNextConfirmDialogResponse(confirmed: boolean): void;
|
|
57
|
+
loadWindowGeometry(): NativeWindowGeometry;
|
|
58
|
+
saveWindowGeometry(patch: Partial<NativeWindowGeometry>): NativeWindowGeometry;
|
|
59
|
+
setAppMenu(items: readonly NativeMenuItem[], handlers?: Record<string, () => void>): readonly NativeMenuItem[];
|
|
60
|
+
triggerMenuAction(actionId: string): boolean;
|
|
61
|
+
setTray(patch: Partial<NativeTrayState>): NativeTrayState;
|
|
62
|
+
registerShortcut(accelerator: string, actionId: string, handler?: () => void): readonly NativeShortcutBinding[];
|
|
63
|
+
unregisterShortcut(accelerator: string): readonly NativeShortcutBinding[];
|
|
64
|
+
triggerShortcut(accelerator: string): boolean;
|
|
65
|
+
onWindowResize(handler: (event: NativeResizeEvent) => void, windowNodeId?: string): () => void;
|
|
66
|
+
onWindowFocusChange(handler: (focused: boolean) => void, windowNodeId?: string): () => void;
|
|
67
|
+
onScroll(scrollNodeId: string, handler: (event: NativeScrollEvent) => void): () => void;
|
|
68
|
+
onScrollBottom(scrollNodeId: string, handler: () => void): () => void;
|
|
69
|
+
setPreventClose(prevent: boolean, windowNodeId?: string): void;
|
|
70
|
+
closeWindow(windowNodeId?: string): void;
|
|
71
|
+
onWindowCloseRequest(handler: (event: NativeCloseRequestEvent) => void, options?: {
|
|
72
|
+
preventClose?: boolean;
|
|
73
|
+
windowNodeId?: string;
|
|
74
|
+
}): () => void;
|
|
75
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NativeDesktopService, never>;
|
|
76
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
77
|
+
}
|
|
78
|
+
export declare function provideNativeDesktop(): EnvironmentProviders;
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { Injectable, makeEnvironmentProviders, signal, } from '@angular/core';
|
|
2
|
+
import { ensureNgNativeBridge, } from '@ng-desktop/platform';
|
|
3
|
+
import { NativeComputeService } from './compute-service.js';
|
|
4
|
+
import { NativeFileSystemService } from './fs-service.js';
|
|
5
|
+
import { NativeNetworkService } from './network-service.js';
|
|
6
|
+
import { NativeSqliteService } from './sqlite-service.js';
|
|
7
|
+
import * as i0 from "@angular/core";
|
|
8
|
+
const WINDOW_STATE_FILE = 'window-state.json';
|
|
9
|
+
const DEFAULT_WINDOW_GEOMETRY = {
|
|
10
|
+
width: 1020,
|
|
11
|
+
height: 720,
|
|
12
|
+
x: null,
|
|
13
|
+
y: null,
|
|
14
|
+
maximized: false,
|
|
15
|
+
};
|
|
16
|
+
function parseBridgePayloadObject(raw) {
|
|
17
|
+
const tryParse = (candidate) => {
|
|
18
|
+
if (typeof candidate !== 'string')
|
|
19
|
+
return null;
|
|
20
|
+
const trimmed = candidate.trim();
|
|
21
|
+
if (!trimmed.startsWith('{') || !trimmed.endsWith('}'))
|
|
22
|
+
return null;
|
|
23
|
+
try {
|
|
24
|
+
const parsed = JSON.parse(trimmed);
|
|
25
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
26
|
+
? parsed
|
|
27
|
+
: null;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const direct = tryParse(raw);
|
|
34
|
+
if (direct)
|
|
35
|
+
return direct;
|
|
36
|
+
if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
|
|
37
|
+
const obj = raw;
|
|
38
|
+
const nested = tryParse(obj['value']);
|
|
39
|
+
return nested ? { ...obj, ...nested } : obj;
|
|
40
|
+
}
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Injectable Angular service providing reactive access to native Desktop OS capabilities:
|
|
45
|
+
* - System Dark/Light theme (`theme` signal synchronized with `GtkSettings` / `AdwStyleManager`)
|
|
46
|
+
* - Native Clipboard (`GdkClipboard`)
|
|
47
|
+
* - Desktop Notifications (`GNotification`)
|
|
48
|
+
* - Native File Dialogs (`GtkFileDialog` open/save)
|
|
49
|
+
*/
|
|
50
|
+
export class NativeDesktopService {
|
|
51
|
+
bridge = ensureNgNativeBridge();
|
|
52
|
+
actionHandlers = new Map();
|
|
53
|
+
theme;
|
|
54
|
+
windowGeometry;
|
|
55
|
+
appMenu;
|
|
56
|
+
trayState;
|
|
57
|
+
shortcuts;
|
|
58
|
+
windowFocused = signal(true, /* @ts-ignore */
|
|
59
|
+
...(ngDevMode ? [{ debugName: "windowFocused" }] : /* istanbul ignore next */ []));
|
|
60
|
+
constructor() {
|
|
61
|
+
this.theme = signal(this.bridge.getSystemTheme(), /* @ts-ignore */
|
|
62
|
+
...(ngDevMode ? [{ debugName: "theme" }] : /* istanbul ignore next */ []));
|
|
63
|
+
this.windowGeometry = signal(this.bridge.getWindowGeometry?.() ?? { ...DEFAULT_WINDOW_GEOMETRY }, /* @ts-ignore */
|
|
64
|
+
...(ngDevMode ? [{ debugName: "windowGeometry" }] : /* istanbul ignore next */ []));
|
|
65
|
+
this.appMenu = signal(this.bridge.getAppMenu?.() ?? [], /* @ts-ignore */
|
|
66
|
+
...(ngDevMode ? [{ debugName: "appMenu" }] : /* istanbul ignore next */ []));
|
|
67
|
+
this.trayState = signal(this.bridge.getTrayState?.() ?? {
|
|
68
|
+
visible: false,
|
|
69
|
+
icon: '',
|
|
70
|
+
tooltip: '',
|
|
71
|
+
menuItems: [],
|
|
72
|
+
}, /* @ts-ignore */
|
|
73
|
+
...(ngDevMode ? [{ debugName: "trayState" }] : /* istanbul ignore next */ []));
|
|
74
|
+
this.shortcuts = signal(this.bridge.getRegisteredShortcuts?.() ?? [], /* @ts-ignore */
|
|
75
|
+
...(ngDevMode ? [{ debugName: "shortcuts" }] : /* istanbul ignore next */ []));
|
|
76
|
+
}
|
|
77
|
+
setTheme(mode) {
|
|
78
|
+
this.bridge.setSystemTheme(mode);
|
|
79
|
+
this.theme.set(mode);
|
|
80
|
+
}
|
|
81
|
+
toggleTheme() {
|
|
82
|
+
const next = this.theme() === 'dark' ? 'light' : 'dark';
|
|
83
|
+
this.setTheme(next);
|
|
84
|
+
return next;
|
|
85
|
+
}
|
|
86
|
+
getClipboardText() {
|
|
87
|
+
return this.bridge.getClipboard();
|
|
88
|
+
}
|
|
89
|
+
setClipboardText(text) {
|
|
90
|
+
this.bridge.setClipboard(text);
|
|
91
|
+
}
|
|
92
|
+
notify(title, body, icon) {
|
|
93
|
+
this.bridge.sendNotification(title, body, icon);
|
|
94
|
+
}
|
|
95
|
+
openFileDialog(options) {
|
|
96
|
+
return this.bridge.openFileDialog(options?.title, options?.defaultPath);
|
|
97
|
+
}
|
|
98
|
+
saveFileDialog(options) {
|
|
99
|
+
return this.bridge.saveFileDialog(options?.title, options?.suggestedName);
|
|
100
|
+
}
|
|
101
|
+
confirmDialog(options) {
|
|
102
|
+
if (typeof this.bridge.confirmDialog === 'function') {
|
|
103
|
+
return this.bridge.confirmDialog(options);
|
|
104
|
+
}
|
|
105
|
+
return options?.defaultConfirmed !== false;
|
|
106
|
+
}
|
|
107
|
+
setNextConfirmDialogResponse(confirmed) {
|
|
108
|
+
this.bridge.setNextConfirmDialogResponse?.(confirmed);
|
|
109
|
+
}
|
|
110
|
+
loadWindowGeometry() {
|
|
111
|
+
let geometry = this.bridge.getWindowGeometry?.() ?? { ...DEFAULT_WINDOW_GEOMETRY };
|
|
112
|
+
try {
|
|
113
|
+
const statePath = this.bridge.fsResolvePath('config', WINDOW_STATE_FILE);
|
|
114
|
+
const raw = this.bridge.fsReadText(statePath);
|
|
115
|
+
if (raw) {
|
|
116
|
+
const parsed = JSON.parse(raw);
|
|
117
|
+
geometry = this.bridge.setWindowGeometry?.(parsed) ?? { ...geometry, ...parsed };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// Keep current bridge geometry when XDG storage is unavailable or invalid
|
|
122
|
+
}
|
|
123
|
+
this.windowGeometry.set(geometry);
|
|
124
|
+
return geometry;
|
|
125
|
+
}
|
|
126
|
+
saveWindowGeometry(patch) {
|
|
127
|
+
const next = this.bridge.setWindowGeometry?.(patch) ?? {
|
|
128
|
+
...this.windowGeometry(),
|
|
129
|
+
...patch,
|
|
130
|
+
};
|
|
131
|
+
this.windowGeometry.set(next);
|
|
132
|
+
try {
|
|
133
|
+
const statePath = this.bridge.fsResolvePath('config', WINDOW_STATE_FILE);
|
|
134
|
+
this.bridge.fsWriteText(statePath, JSON.stringify(next));
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
// Best-effort persistence when XDG filesystem access is restricted
|
|
138
|
+
}
|
|
139
|
+
return next;
|
|
140
|
+
}
|
|
141
|
+
setAppMenu(items, handlers) {
|
|
142
|
+
if (handlers) {
|
|
143
|
+
for (const [id, handler] of Object.entries(handlers)) {
|
|
144
|
+
this.actionHandlers.set(id, handler);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const updated = this.bridge.setAppMenu?.(items) ??
|
|
148
|
+
items.map((item) => ({ ...item, enabled: item.enabled !== false }));
|
|
149
|
+
this.appMenu.set(updated);
|
|
150
|
+
return updated;
|
|
151
|
+
}
|
|
152
|
+
triggerMenuAction(actionId) {
|
|
153
|
+
const menuItem = this.appMenu().find((item) => item.id === actionId);
|
|
154
|
+
if (menuItem?.enabled === false) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
const handler = this.actionHandlers.get(actionId);
|
|
158
|
+
if (!handler) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
handler();
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
setTray(patch) {
|
|
165
|
+
const next = this.bridge.setTrayState?.(patch) ?? {
|
|
166
|
+
...this.trayState(),
|
|
167
|
+
...patch,
|
|
168
|
+
};
|
|
169
|
+
this.trayState.set(next);
|
|
170
|
+
return next;
|
|
171
|
+
}
|
|
172
|
+
registerShortcut(accelerator, actionId, handler) {
|
|
173
|
+
if (handler) {
|
|
174
|
+
this.actionHandlers.set(actionId, handler);
|
|
175
|
+
}
|
|
176
|
+
const next = this.bridge.registerShortcut?.(accelerator, actionId) ?? [
|
|
177
|
+
...this.shortcuts().filter((item) => item.accelerator !== accelerator.trim()),
|
|
178
|
+
{ accelerator: accelerator.trim(), actionId: actionId.trim() },
|
|
179
|
+
];
|
|
180
|
+
this.shortcuts.set(next);
|
|
181
|
+
return next;
|
|
182
|
+
}
|
|
183
|
+
unregisterShortcut(accelerator) {
|
|
184
|
+
const next = this.bridge.unregisterShortcut?.(accelerator) ??
|
|
185
|
+
this.shortcuts().filter((item) => item.accelerator !== accelerator.trim());
|
|
186
|
+
this.shortcuts.set(next);
|
|
187
|
+
return next;
|
|
188
|
+
}
|
|
189
|
+
triggerShortcut(accelerator) {
|
|
190
|
+
const normalized = accelerator.trim().toLowerCase();
|
|
191
|
+
const binding = this.shortcuts().find((item) => item.accelerator.trim().toLowerCase() === normalized);
|
|
192
|
+
if (!binding) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
const handler = this.actionHandlers.get(binding.actionId);
|
|
196
|
+
if (!handler) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
handler();
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
onWindowResize(handler, windowNodeId = 'win') {
|
|
203
|
+
return this.bridge.listen(windowNodeId, 'resize', (raw) => {
|
|
204
|
+
const parsed = parseBridgePayloadObject(raw);
|
|
205
|
+
const current = this.windowGeometry();
|
|
206
|
+
const event = {
|
|
207
|
+
width: Number(parsed['width'] ?? current.width),
|
|
208
|
+
height: Number(parsed['height'] ?? current.height),
|
|
209
|
+
maximized: Boolean(parsed['maximized'] ?? current.maximized),
|
|
210
|
+
};
|
|
211
|
+
this.windowGeometry.set({ ...current, ...event });
|
|
212
|
+
handler(event);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
onWindowFocusChange(handler, windowNodeId = 'win') {
|
|
216
|
+
const unFocus = this.bridge.listen(windowNodeId, 'focus', () => {
|
|
217
|
+
this.windowFocused.set(true);
|
|
218
|
+
handler(true);
|
|
219
|
+
});
|
|
220
|
+
const unBlur = this.bridge.listen(windowNodeId, 'blur', () => {
|
|
221
|
+
this.windowFocused.set(false);
|
|
222
|
+
handler(false);
|
|
223
|
+
});
|
|
224
|
+
return () => {
|
|
225
|
+
unFocus();
|
|
226
|
+
unBlur();
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
onScroll(scrollNodeId, handler) {
|
|
230
|
+
return this.bridge.listen(scrollNodeId, 'scroll', (raw) => {
|
|
231
|
+
const parsed = parseBridgePayloadObject(raw);
|
|
232
|
+
handler({
|
|
233
|
+
scrollTop: Number(parsed['scrollTop'] ?? 0),
|
|
234
|
+
scrollHeight: Number(parsed['scrollHeight'] ?? 0),
|
|
235
|
+
clientHeight: Number(parsed['clientHeight'] ?? 0),
|
|
236
|
+
atTop: Boolean(parsed['atTop'] ?? false),
|
|
237
|
+
atBottom: Boolean(parsed['atBottom'] ?? false),
|
|
238
|
+
progress: Number(parsed['progress'] ?? 0),
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
onScrollBottom(scrollNodeId, handler) {
|
|
243
|
+
return this.bridge.listen(scrollNodeId, 'scroll-bottom', () => {
|
|
244
|
+
handler();
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
setPreventClose(prevent, windowNodeId = 'win') {
|
|
248
|
+
this.bridge.setAttribute(windowNodeId, 'prevent-close', prevent ? 'true' : 'false');
|
|
249
|
+
}
|
|
250
|
+
closeWindow(windowNodeId = 'win') {
|
|
251
|
+
this.bridge.setAttribute(windowNodeId, 'close-window', 'true');
|
|
252
|
+
}
|
|
253
|
+
onWindowCloseRequest(handler, options) {
|
|
254
|
+
const windowNodeId = options?.windowNodeId ?? 'win';
|
|
255
|
+
if (options?.preventClose !== undefined) {
|
|
256
|
+
this.setPreventClose(options.preventClose, windowNodeId);
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
this.bridge.setAttribute(windowNodeId, 'event-mask', 'close-request');
|
|
260
|
+
}
|
|
261
|
+
const unlisten = this.bridge.listen(windowNodeId, 'close-request', (raw) => {
|
|
262
|
+
const parsed = parseBridgePayloadObject(raw);
|
|
263
|
+
handler({ preventable: Boolean(parsed['preventable']) });
|
|
264
|
+
});
|
|
265
|
+
return () => {
|
|
266
|
+
if (options?.preventClose) {
|
|
267
|
+
this.setPreventClose(false, windowNodeId);
|
|
268
|
+
}
|
|
269
|
+
unlisten();
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeDesktopService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
273
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeDesktopService, providedIn: 'root' });
|
|
274
|
+
}
|
|
275
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeDesktopService, decorators: [{
|
|
276
|
+
type: Injectable,
|
|
277
|
+
args: [{ providedIn: 'root' }]
|
|
278
|
+
}], ctorParameters: () => [] });
|
|
279
|
+
export function provideNativeDesktop() {
|
|
280
|
+
return makeEnvironmentProviders([
|
|
281
|
+
NativeDesktopService,
|
|
282
|
+
NativeSqliteService,
|
|
283
|
+
NativeNetworkService,
|
|
284
|
+
NativeComputeService,
|
|
285
|
+
NativeFileSystemService,
|
|
286
|
+
]);
|
|
287
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { OnDestroy } from '@angular/core';
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
export interface NativeFileDropPayload {
|
|
4
|
+
value?: string;
|
|
5
|
+
paths?: string[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Standalone directive (`[ngNativeDropTarget]`) that enables OS-native file drag-and-drop
|
|
9
|
+
* (`GtkDropTarget` on Linux GTK4, `AllowDrop` on WinUI 3, `registerForDraggedTypes` on macOS AppKit)
|
|
10
|
+
* and emits dropped file paths through `(fileDrop)`.
|
|
11
|
+
*/
|
|
12
|
+
export declare class NativeDropTargetDirective implements OnDestroy {
|
|
13
|
+
readonly fileDrop: import("@angular/core").OutputEmitterRef<string[]>;
|
|
14
|
+
private readonly unlisten;
|
|
15
|
+
constructor();
|
|
16
|
+
static extractPaths(event: unknown): string[];
|
|
17
|
+
ngOnDestroy(): void;
|
|
18
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NativeDropTargetDirective, never>;
|
|
19
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<NativeDropTargetDirective, "[ngNativeDropTarget]", never, {}, { "fileDrop": "fileDrop"; }, never, never, true, never>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Directive, ElementRef, inject, output, Renderer2 } from '@angular/core';
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
/**
|
|
4
|
+
* Standalone directive (`[ngNativeDropTarget]`) that enables OS-native file drag-and-drop
|
|
5
|
+
* (`GtkDropTarget` on Linux GTK4, `AllowDrop` on WinUI 3, `registerForDraggedTypes` on macOS AppKit)
|
|
6
|
+
* and emits dropped file paths through `(fileDrop)`.
|
|
7
|
+
*/
|
|
8
|
+
export class NativeDropTargetDirective {
|
|
9
|
+
fileDrop = output();
|
|
10
|
+
unlisten;
|
|
11
|
+
constructor() {
|
|
12
|
+
const renderer = inject(Renderer2);
|
|
13
|
+
const elRef = inject(ElementRef);
|
|
14
|
+
const nativeEl = elRef.nativeElement;
|
|
15
|
+
renderer.setAttribute(nativeEl, 'drop-target', 'true');
|
|
16
|
+
this.unlisten = renderer.listen(nativeEl, 'file-drop', (event) => {
|
|
17
|
+
const paths = NativeDropTargetDirective.extractPaths(event);
|
|
18
|
+
if (paths.length > 0) {
|
|
19
|
+
this.fileDrop.emit(paths);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
static extractPaths(event) {
|
|
24
|
+
if (typeof event === 'string') {
|
|
25
|
+
return event
|
|
26
|
+
.split(/\r?\n|,/)
|
|
27
|
+
.map((p) => p.trim())
|
|
28
|
+
.filter((p) => p.length > 0);
|
|
29
|
+
}
|
|
30
|
+
if (event && typeof event === 'object') {
|
|
31
|
+
const payload = event;
|
|
32
|
+
if (Array.isArray(payload.paths)) {
|
|
33
|
+
return payload.paths.map((p) => String(p).trim()).filter((p) => p.length > 0);
|
|
34
|
+
}
|
|
35
|
+
if (typeof payload.value === 'string') {
|
|
36
|
+
return payload.value
|
|
37
|
+
.split(/\r?\n|,/)
|
|
38
|
+
.map((p) => p.trim())
|
|
39
|
+
.filter((p) => p.length > 0);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
ngOnDestroy() {
|
|
45
|
+
this.unlisten();
|
|
46
|
+
}
|
|
47
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeDropTargetDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
48
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.2.6", type: NativeDropTargetDirective, isStandalone: true, selector: "[ngNativeDropTarget]", outputs: { fileDrop: "fileDrop" }, ngImport: i0 });
|
|
49
|
+
}
|
|
50
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeDropTargetDirective, decorators: [{
|
|
51
|
+
type: Directive,
|
|
52
|
+
args: [{
|
|
53
|
+
selector: '[ngNativeDropTarget]',
|
|
54
|
+
standalone: true,
|
|
55
|
+
}]
|
|
56
|
+
}], ctorParameters: () => [], propDecorators: { fileDrop: [{ type: i0.Output, args: ["fileDrop"] }] } });
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Signal } from '@angular/core';
|
|
2
|
+
import { type NativeXdgDirKind } from '@ng-desktop/platform';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
export interface NativeWatchedFileRef<T> {
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly value: Signal<T>;
|
|
7
|
+
reload(): void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Injectable Angular service for XDG Base Directory resolution (`config`, `data`, `cache`),
|
|
11
|
+
* atomic file writes, and reactive file watching backed by OS kernel notifications (`inotify` / `FSEvents` / `ReadDirectoryChangesW`).
|
|
12
|
+
*/
|
|
13
|
+
export declare class NativeFileSystemService {
|
|
14
|
+
private readonly bridge;
|
|
15
|
+
private readonly watchedEntries;
|
|
16
|
+
resolveXdgPath(kind: NativeXdgDirKind, relPath: string): string;
|
|
17
|
+
readText(path: string): string | null;
|
|
18
|
+
writeText(path: string, content: string): boolean;
|
|
19
|
+
readJson<T>(path: string, fallback: T): T;
|
|
20
|
+
writeJson(path: string, data: unknown): boolean;
|
|
21
|
+
watchFile(path: string, initialContent?: string): NativeWatchedFileRef<string>;
|
|
22
|
+
watchJson<T>(path: string, fallback: T): NativeWatchedFileRef<T>;
|
|
23
|
+
refreshWatchedFiles(): string[];
|
|
24
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NativeFileSystemService, never>;
|
|
25
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Injectable, signal } from '@angular/core';
|
|
2
|
+
import { ensureNgNativeBridge } from '@ng-desktop/platform';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
/**
|
|
5
|
+
* Injectable Angular service for XDG Base Directory resolution (`config`, `data`, `cache`),
|
|
6
|
+
* atomic file writes, and reactive file watching backed by OS kernel notifications (`inotify` / `FSEvents` / `ReadDirectoryChangesW`).
|
|
7
|
+
*/
|
|
8
|
+
export class NativeFileSystemService {
|
|
9
|
+
bridge = ensureNgNativeBridge();
|
|
10
|
+
watchedEntries = new Map();
|
|
11
|
+
resolveXdgPath(kind, relPath) {
|
|
12
|
+
return this.bridge.fsResolvePath(kind, relPath);
|
|
13
|
+
}
|
|
14
|
+
readText(path) {
|
|
15
|
+
return this.bridge.fsReadText(path);
|
|
16
|
+
}
|
|
17
|
+
writeText(path, content) {
|
|
18
|
+
const ok = this.bridge.fsWriteText(path, content);
|
|
19
|
+
if (ok) {
|
|
20
|
+
this.refreshWatchedFiles();
|
|
21
|
+
}
|
|
22
|
+
return ok;
|
|
23
|
+
}
|
|
24
|
+
readJson(path, fallback) {
|
|
25
|
+
const raw = this.readText(path);
|
|
26
|
+
if (raw === null || raw.trim().length === 0) {
|
|
27
|
+
return fallback;
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
return JSON.parse(raw);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return fallback;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
writeJson(path, data) {
|
|
37
|
+
return this.writeText(path, JSON.stringify(data, null, 2));
|
|
38
|
+
}
|
|
39
|
+
watchFile(path, initialContent = '') {
|
|
40
|
+
this.bridge.fsWatchFile(path);
|
|
41
|
+
const sig = signal(this.readText(path) ?? initialContent, /* @ts-ignore */
|
|
42
|
+
...(ngDevMode ? [{ debugName: "sig" }] : /* istanbul ignore next */ []));
|
|
43
|
+
const reload = () => {
|
|
44
|
+
const latest = this.readText(path);
|
|
45
|
+
if (latest !== null) {
|
|
46
|
+
sig.set(latest);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
this.watchedEntries.set(path, { path, reload });
|
|
50
|
+
return {
|
|
51
|
+
path,
|
|
52
|
+
value: sig.asReadonly(),
|
|
53
|
+
reload,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
watchJson(path, fallback) {
|
|
57
|
+
this.bridge.fsWatchFile(path);
|
|
58
|
+
const sig = signal(this.readJson(path, fallback), /* @ts-ignore */
|
|
59
|
+
...(ngDevMode ? [{ debugName: "sig" }] : /* istanbul ignore next */ []));
|
|
60
|
+
const reload = () => {
|
|
61
|
+
sig.set(this.readJson(path, fallback));
|
|
62
|
+
};
|
|
63
|
+
this.watchedEntries.set(path, { path, reload });
|
|
64
|
+
return {
|
|
65
|
+
path,
|
|
66
|
+
value: sig.asReadonly(),
|
|
67
|
+
reload,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
refreshWatchedFiles() {
|
|
71
|
+
const changed = this.bridge.fsPollChangedFiles();
|
|
72
|
+
for (const path of changed) {
|
|
73
|
+
this.watchedEntries.get(path)?.reload();
|
|
74
|
+
}
|
|
75
|
+
return changed;
|
|
76
|
+
}
|
|
77
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeFileSystemService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
78
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeFileSystemService, providedIn: 'root' });
|
|
79
|
+
}
|
|
80
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeFileSystemService, decorators: [{
|
|
81
|
+
type: Injectable,
|
|
82
|
+
args: [{ providedIn: 'root' }]
|
|
83
|
+
}] });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { NativeComputeService, type NativeScoredItem } from './compute-service';
|
|
2
|
+
export { NativeDesktopService, provideNativeDesktop, type ConfirmDialogOptions, type NativeCloseRequestEvent, type NativeMenuItem, type NativeResizeEvent, type NativeScrollEvent, type NativeShortcutBinding, type NativeThemeMode, type NativeTrayState, type NativeWindowGeometry, type OpenFileDialogOptions, type SaveFileDialogOptions, } from './desktop-service';
|
|
3
|
+
export { NativeDropTargetDirective, type NativeFileDropPayload } from './drop-target.directive';
|
|
4
|
+
export { NativeFileSystemService, type NativeWatchedFileRef } from './fs-service';
|
|
5
|
+
export { NativeNetworkService } from './network-service';
|
|
6
|
+
export { NativeSqliteService, type NativeLiveQueryRef } from './sqlite-service';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { NativeComputeService } from './compute-service.js';
|
|
2
|
+
export { NativeDesktopService, provideNativeDesktop, } from './desktop-service.js';
|
|
3
|
+
export { NativeDropTargetDirective } from './drop-target.directive.js';
|
|
4
|
+
export { NativeFileSystemService } from './fs-service.js';
|
|
5
|
+
export { NativeNetworkService } from './network-service.js';
|
|
6
|
+
export { NativeSqliteService } from './sqlite-service.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Signal, WritableSignal } from '@angular/core';
|
|
2
|
+
import { NativeConnectivity } from '@ng-desktop/platform';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
/**
|
|
5
|
+
* Reactive OS Network Monitor backed by `GNetworkMonitor` (Linux GIO), `NWPathMonitor` (macOS),
|
|
6
|
+
* or `NetworkInformation` (Windows), exposing Signal-based online/metered state.
|
|
7
|
+
*/
|
|
8
|
+
export declare class NativeNetworkService {
|
|
9
|
+
private readonly bridge;
|
|
10
|
+
readonly isOnline: WritableSignal<boolean>;
|
|
11
|
+
readonly isMetered: WritableSignal<boolean>;
|
|
12
|
+
readonly connectivity: Signal<NativeConnectivity>;
|
|
13
|
+
constructor();
|
|
14
|
+
refresh(): void;
|
|
15
|
+
setOnlineStatus(online: boolean, metered?: boolean): void;
|
|
16
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NativeNetworkService, never>;
|
|
17
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { computed, Injectable, signal } from '@angular/core';
|
|
2
|
+
import { ensureNgNativeBridge } from '@ng-desktop/platform';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
/**
|
|
5
|
+
* Reactive OS Network Monitor backed by `GNetworkMonitor` (Linux GIO), `NWPathMonitor` (macOS),
|
|
6
|
+
* or `NetworkInformation` (Windows), exposing Signal-based online/metered state.
|
|
7
|
+
*/
|
|
8
|
+
export class NativeNetworkService {
|
|
9
|
+
bridge = ensureNgNativeBridge();
|
|
10
|
+
isOnline;
|
|
11
|
+
isMetered;
|
|
12
|
+
connectivity;
|
|
13
|
+
constructor() {
|
|
14
|
+
const initial = this.bridge.getNetworkStatus();
|
|
15
|
+
this.isOnline = signal(initial.online, /* @ts-ignore */
|
|
16
|
+
...(ngDevMode ? [{ debugName: "isOnline" }] : /* istanbul ignore next */ []));
|
|
17
|
+
this.isMetered = signal(initial.metered, /* @ts-ignore */
|
|
18
|
+
...(ngDevMode ? [{ debugName: "isMetered" }] : /* istanbul ignore next */ []));
|
|
19
|
+
this.connectivity = computed(() => {
|
|
20
|
+
if (!this.isOnline())
|
|
21
|
+
return 'offline';
|
|
22
|
+
return this.isMetered() ? 'limited' : 'full';
|
|
23
|
+
}, /* @ts-ignore */
|
|
24
|
+
...(ngDevMode ? [{ debugName: "connectivity" }] : /* istanbul ignore next */ []));
|
|
25
|
+
}
|
|
26
|
+
refresh() {
|
|
27
|
+
const current = this.bridge.getNetworkStatus();
|
|
28
|
+
this.isOnline.set(current.online);
|
|
29
|
+
this.isMetered.set(current.metered);
|
|
30
|
+
}
|
|
31
|
+
setOnlineStatus(online, metered = false) {
|
|
32
|
+
this.bridge.setNetworkStatus(online, metered);
|
|
33
|
+
this.isOnline.set(online);
|
|
34
|
+
this.isMetered.set(metered);
|
|
35
|
+
}
|
|
36
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeNetworkService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
37
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeNetworkService, providedIn: 'root' });
|
|
38
|
+
}
|
|
39
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeNetworkService, decorators: [{
|
|
40
|
+
type: Injectable,
|
|
41
|
+
args: [{ providedIn: 'root' }]
|
|
42
|
+
}], ctorParameters: () => [] });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Signal } from '@angular/core';
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
export interface NativeLiveQueryRef<T> {
|
|
4
|
+
readonly rows: Signal<T[]>;
|
|
5
|
+
readonly count: Signal<number>;
|
|
6
|
+
refresh(): T[];
|
|
7
|
+
destroy(): void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Reactive native SQLite service backed by Rust `libsqlite3.so.0` FFI (`NativeSqliteDatabase`)
|
|
11
|
+
* with Signal-based `liveQuery()` subscriptions that refresh automatically after mutations.
|
|
12
|
+
*/
|
|
13
|
+
export declare class NativeSqliteService {
|
|
14
|
+
private readonly bridge;
|
|
15
|
+
private readonly liveQueryRefreshers;
|
|
16
|
+
readonly mutationVersion: import("@angular/core").WritableSignal<number>;
|
|
17
|
+
execute(sql: string): boolean;
|
|
18
|
+
query<T = Record<string, string>>(sql: string, mapRow?: (row: Record<string, string>) => T): T[];
|
|
19
|
+
liveQuery<T = Record<string, string>>(sqlOrFn: string | (() => string), mapRow?: (row: Record<string, string>) => T): NativeLiveQueryRef<T>;
|
|
20
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NativeSqliteService, never>;
|
|
21
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { computed, DestroyRef, inject, Injectable, signal } from '@angular/core';
|
|
2
|
+
import { ensureNgNativeBridge } from '@ng-desktop/platform';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
/**
|
|
5
|
+
* Reactive native SQLite service backed by Rust `libsqlite3.so.0` FFI (`NativeSqliteDatabase`)
|
|
6
|
+
* with Signal-based `liveQuery()` subscriptions that refresh automatically after mutations.
|
|
7
|
+
*/
|
|
8
|
+
export class NativeSqliteService {
|
|
9
|
+
bridge = ensureNgNativeBridge();
|
|
10
|
+
liveQueryRefreshers = new Set();
|
|
11
|
+
mutationVersion = signal(0, /* @ts-ignore */
|
|
12
|
+
...(ngDevMode ? [{ debugName: "mutationVersion" }] : /* istanbul ignore next */ []));
|
|
13
|
+
execute(sql) {
|
|
14
|
+
const ok = this.bridge.sqliteExecute(sql);
|
|
15
|
+
if (ok) {
|
|
16
|
+
this.mutationVersion.update((v) => v + 1);
|
|
17
|
+
for (const refresh of this.liveQueryRefreshers) {
|
|
18
|
+
refresh();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return ok;
|
|
22
|
+
}
|
|
23
|
+
query(sql, mapRow) {
|
|
24
|
+
const rawRows = this.bridge.sqliteQuery(sql);
|
|
25
|
+
return mapRow ? rawRows.map(mapRow) : rawRows;
|
|
26
|
+
}
|
|
27
|
+
liveQuery(sqlOrFn, mapRow) {
|
|
28
|
+
const rowsSignal = signal([], /* @ts-ignore */
|
|
29
|
+
...(ngDevMode ? [{ debugName: "rowsSignal" }] : /* istanbul ignore next */ []));
|
|
30
|
+
const refresh = () => {
|
|
31
|
+
const sql = typeof sqlOrFn === 'function' ? sqlOrFn() : sqlOrFn;
|
|
32
|
+
const next = this.query(sql, mapRow);
|
|
33
|
+
rowsSignal.set(next);
|
|
34
|
+
return next;
|
|
35
|
+
};
|
|
36
|
+
refresh();
|
|
37
|
+
this.liveQueryRefreshers.add(refresh);
|
|
38
|
+
const destroy = () => {
|
|
39
|
+
this.liveQueryRefreshers.delete(refresh);
|
|
40
|
+
};
|
|
41
|
+
let destroyRef = null;
|
|
42
|
+
try {
|
|
43
|
+
destroyRef = inject(DestroyRef, { optional: true });
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
destroyRef = null;
|
|
47
|
+
}
|
|
48
|
+
destroyRef?.onDestroy(destroy);
|
|
49
|
+
return {
|
|
50
|
+
rows: rowsSignal.asReadonly(),
|
|
51
|
+
count: computed(() => rowsSignal().length),
|
|
52
|
+
refresh,
|
|
53
|
+
destroy,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeSqliteService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
57
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeSqliteService, providedIn: 'root' });
|
|
58
|
+
}
|
|
59
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeSqliteService, decorators: [{
|
|
60
|
+
type: Injectable,
|
|
61
|
+
args: [{ providedIn: 'root' }]
|
|
62
|
+
}] });
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ng-desktop/desktop",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Linux GTK4 / Desktop OS system services (Theme, Clipboard, Notifications, Dialogs, SQLite, Network, Compute, FileSystem, DropTarget)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"angular",
|
|
8
|
+
"angular22",
|
|
9
|
+
"desktop",
|
|
10
|
+
"native",
|
|
11
|
+
"gtk4",
|
|
12
|
+
"winui3",
|
|
13
|
+
"appkit",
|
|
14
|
+
"rust"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/Gaspar1992/ng-desktop-engine",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/Gaspar1992/ng-desktop-engine/issues"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/Gaspar1992/ng-desktop-engine.git",
|
|
23
|
+
"directory": "packages/desktop-native"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"type": "module",
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"files": [
|
|
31
|
+
"fesm2022",
|
|
32
|
+
"README.md",
|
|
33
|
+
"LICENSE",
|
|
34
|
+
"!**/*.map"
|
|
35
|
+
],
|
|
36
|
+
"main": "./fesm2022/index.js",
|
|
37
|
+
"module": "./fesm2022/index.js",
|
|
38
|
+
"types": "./fesm2022/index.d.ts",
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"types": "./fesm2022/index.d.ts",
|
|
42
|
+
"default": "./fesm2022/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./package.json": {
|
|
45
|
+
"default": "./package.json"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"@angular/core": ">=22.0.0",
|
|
50
|
+
"@ng-desktop/platform": ">=0.4.0"
|
|
51
|
+
}
|
|
52
|
+
}
|