@flighthq/host-tauri 0.1.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.
Files changed (64) hide show
  1. package/dist/index.d.ts +13 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +13 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/tauriApp.d.ts +4 -0
  6. package/dist/tauriApp.d.ts.map +1 -0
  7. package/dist/tauriApp.js +159 -0
  8. package/dist/tauriApp.js.map +1 -0
  9. package/dist/tauriClipboard.d.ts +4 -0
  10. package/dist/tauriClipboard.d.ts.map +1 -0
  11. package/dist/tauriClipboard.js +108 -0
  12. package/dist/tauriClipboard.js.map +1 -0
  13. package/dist/tauriDialog.d.ts +4 -0
  14. package/dist/tauriDialog.d.ts.map +1 -0
  15. package/dist/tauriDialog.js +83 -0
  16. package/dist/tauriDialog.js.map +1 -0
  17. package/dist/tauriMenu.d.ts +4 -0
  18. package/dist/tauriMenu.d.ts.map +1 -0
  19. package/dist/tauriMenu.js +68 -0
  20. package/dist/tauriMenu.js.map +1 -0
  21. package/dist/tauriModule.d.ts +213 -0
  22. package/dist/tauriModule.d.ts.map +1 -0
  23. package/dist/tauriModule.js +25 -0
  24. package/dist/tauriModule.js.map +1 -0
  25. package/dist/tauriNotification.d.ts +4 -0
  26. package/dist/tauriNotification.d.ts.map +1 -0
  27. package/dist/tauriNotification.js +102 -0
  28. package/dist/tauriNotification.js.map +1 -0
  29. package/dist/tauriPlatform.d.ts +4 -0
  30. package/dist/tauriPlatform.d.ts.map +1 -0
  31. package/dist/tauriPlatform.js +33 -0
  32. package/dist/tauriPlatform.js.map +1 -0
  33. package/dist/tauriRegister.d.ts +3 -0
  34. package/dist/tauriRegister.d.ts.map +1 -0
  35. package/dist/tauriRegister.js +44 -0
  36. package/dist/tauriRegister.js.map +1 -0
  37. package/dist/tauriShell.d.ts +4 -0
  38. package/dist/tauriShell.d.ts.map +1 -0
  39. package/dist/tauriShell.js +67 -0
  40. package/dist/tauriShell.js.map +1 -0
  41. package/dist/tauriShortcut.d.ts +4 -0
  42. package/dist/tauriShortcut.d.ts.map +1 -0
  43. package/dist/tauriShortcut.js +53 -0
  44. package/dist/tauriShortcut.js.map +1 -0
  45. package/dist/tauriTray.d.ts +4 -0
  46. package/dist/tauriTray.d.ts.map +1 -0
  47. package/dist/tauriTray.js +167 -0
  48. package/dist/tauriTray.js.map +1 -0
  49. package/dist/tauriWindow.d.ts +4 -0
  50. package/dist/tauriWindow.d.ts.map +1 -0
  51. package/dist/tauriWindow.js +166 -0
  52. package/dist/tauriWindow.js.map +1 -0
  53. package/package.json +48 -0
  54. package/src/tauriApp.test.ts +80 -0
  55. package/src/tauriClipboard.test.ts +69 -0
  56. package/src/tauriDialog.test.ts +83 -0
  57. package/src/tauriMenu.test.ts +129 -0
  58. package/src/tauriNotification.test.ts +59 -0
  59. package/src/tauriPlatform.test.ts +56 -0
  60. package/src/tauriRegister.test.ts +67 -0
  61. package/src/tauriShell.test.ts +63 -0
  62. package/src/tauriShortcut.test.ts +77 -0
  63. package/src/tauriTray.test.ts +123 -0
  64. package/src/tauriWindow.test.ts +144 -0
@@ -0,0 +1,144 @@
1
+ import { createApplicationWindow } from '@flighthq/application';
2
+ import { connectSignal } from '@flighthq/signals';
3
+
4
+ import type { TauriApi, TauriLogicalSizeLike, TauriPhysicalPositionLike } from './tauriModule';
5
+ import { createTauriWindowBackend } from './tauriWindow';
6
+
7
+ interface FakeWindowState {
8
+ calls: { method: string; args: unknown[] }[];
9
+ moved: ((event: { payload: TauriPhysicalPositionLike }) => void) | null;
10
+ resized: ((event: { payload: TauriLogicalSizeLike }) => void) | null;
11
+ focusChanged: ((event: { payload: boolean }) => void) | null;
12
+ closeRequested: (() => void) | null;
13
+ }
14
+
15
+ function fakeTauri() {
16
+ const state: FakeWindowState = { calls: [], moved: null, resized: null, focusChanged: null, closeRequested: null };
17
+ const record =
18
+ (method: string) =>
19
+ async (...args: unknown[]) => {
20
+ state.calls.push({ method, args });
21
+ };
22
+ const window = {
23
+ setTitle: record('setTitle'),
24
+ setSize: record('setSize'),
25
+ setPosition: record('setPosition'),
26
+ setResizable: record('setResizable'),
27
+ setAlwaysOnTop: record('setAlwaysOnTop'),
28
+ setFullscreen: record('setFullscreen'),
29
+ setMinSize: record('setMinSize'),
30
+ setMaxSize: record('setMaxSize'),
31
+ setFocus: record('setFocus'),
32
+ setIcon: record('setIcon'),
33
+ setSkipTaskbar: record('setSkipTaskbar'),
34
+ setContentProtected: record('setContentProtected'),
35
+ setShadow: record('setShadow'),
36
+ requestUserAttention: record('requestUserAttention'),
37
+ minimize: record('minimize'),
38
+ maximize: record('maximize'),
39
+ unmaximize: record('unmaximize'),
40
+ show: record('show'),
41
+ hide: record('hide'),
42
+ center: record('center'),
43
+ close: record('close'),
44
+ async onMoved(handler: (event: { payload: TauriPhysicalPositionLike }) => void) {
45
+ state.moved = handler;
46
+ return () => {};
47
+ },
48
+ async onResized(handler: (event: { payload: TauriLogicalSizeLike }) => void) {
49
+ state.resized = handler;
50
+ return () => {};
51
+ },
52
+ async onFocusChanged(handler: (event: { payload: boolean }) => void) {
53
+ state.focusChanged = handler;
54
+ return () => {};
55
+ },
56
+ async onCloseRequested(handler: () => void) {
57
+ state.closeRequested = handler;
58
+ return () => {};
59
+ },
60
+ };
61
+ const tauri = {
62
+ window: {
63
+ getCurrentWindow: () => window,
64
+ LogicalPosition: class {
65
+ constructor(
66
+ public x: number,
67
+ public y: number,
68
+ ) {}
69
+ },
70
+ LogicalSize: class {
71
+ constructor(
72
+ public width: number,
73
+ public height: number,
74
+ ) {}
75
+ },
76
+ },
77
+ } as unknown as TauriApi;
78
+ return { tauri, state };
79
+ }
80
+
81
+ function methods(state: FakeWindowState): string[] {
82
+ return state.calls.map((c) => c.method);
83
+ }
84
+
85
+ describe('createTauriWindowBackend', () => {
86
+ it('opens the current window and applies options', () => {
87
+ const { tauri, state } = fakeTauri();
88
+ const backend = createTauriWindowBackend(tauri);
89
+ const win = createApplicationWindow();
90
+ expect(backend.open(win, { title: 'Hi', width: 640, height: 480, resizable: false, visible: true })).toBe(true);
91
+ expect(methods(state)).toContain('setTitle');
92
+ expect(methods(state)).toContain('setSize');
93
+ expect(methods(state)).toContain('setResizable');
94
+ expect(methods(state)).toContain('show');
95
+ });
96
+
97
+ it('mirrors native move/resize/focus events onto the entity and its signals', () => {
98
+ const { tauri, state } = fakeTauri();
99
+ const backend = createTauriWindowBackend(tauri);
100
+ const win = createApplicationWindow();
101
+ let moves = 0;
102
+ connectSignal(win.onMove, () => moves++);
103
+ backend.open(win, {});
104
+ state.moved!({ payload: { x: 12, y: 34 } });
105
+ expect(win.x).toBe(12);
106
+ expect(win.y).toBe(34);
107
+ expect(moves).toBe(1);
108
+ state.resized!({ payload: { width: 800, height: 600 } });
109
+ expect(win.width).toBe(800);
110
+ expect(win.height).toBe(600);
111
+ state.focusChanged!({ payload: true });
112
+ expect(win.focused).toBe(true);
113
+ });
114
+
115
+ it('routes control methods to the current window and no-ops before open', () => {
116
+ const { tauri, state } = fakeTauri();
117
+ const backend = createTauriWindowBackend(tauri);
118
+ const win = createApplicationWindow();
119
+ // Not opened yet: nothing routes through.
120
+ backend.setTitle(win, 'ignored');
121
+ expect(state.calls).toHaveLength(0);
122
+ backend.open(win, {});
123
+ state.calls.length = 0;
124
+ backend.setTitle(win, 'New');
125
+ backend.minimize(win);
126
+ backend.setFullscreen(win, true);
127
+ backend.requestAttention(win, true);
128
+ expect(methods(state)).toEqual(['setTitle', 'minimize', 'setFullscreen', 'requestUserAttention']);
129
+ });
130
+
131
+ it('reports mirrored bounds from the entity', () => {
132
+ const { tauri } = fakeTauri();
133
+ const backend = createTauriWindowBackend(tauri);
134
+ const win = createApplicationWindow();
135
+ win.x = 5;
136
+ win.y = 6;
137
+ win.width = 100;
138
+ win.height = 200;
139
+ backend.open(win, {});
140
+ const out = { x: 0, y: 0, width: 0, height: 0 };
141
+ expect(backend.getBounds(win, out)).toBe(out);
142
+ expect(out).toEqual({ x: 5, y: 6, width: 100, height: 200 });
143
+ });
144
+ });