@dxos/plugin-native 0.8.3 → 0.8.4-main.5acf9ea
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/dist/lib/browser/chunk-E2JDGVJI.mjs +12 -0
- package/dist/lib/browser/chunk-E2JDGVJI.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +33 -14
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/updater-KSM3TUHI.mjs +133 -0
- package/dist/lib/browser/updater-KSM3TUHI.mjs.map +7 -0
- package/dist/types/src/NativePlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +2 -0
- package/dist/types/src/capabilities/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/updater.d.ts +4 -0
- package/dist/types/src/capabilities/updater.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +12 -0
- package/dist/types/src/translations.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -11
- package/src/NativePlugin.tsx +10 -10
- package/src/capabilities/index.ts +7 -0
- package/src/capabilities/updater.ts +79 -0
- package/src/translations.ts +20 -0
- package/dist/lib/browser/initialize-OGKEIRPC.mjs +0 -161
- package/dist/lib/browser/initialize-OGKEIRPC.mjs.map +0 -7
- package/dist/types/src/initialize.d.ts +0 -3
- package/dist/types/src/initialize.d.ts.map +0 -1
- package/src/initialize.ts +0 -175
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/plugin-native",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4-main.5acf9ea",
|
|
4
4
|
"description": "Composer plugin that runs when on a native device.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
13
|
"types": "./dist/types/src/index.d.ts",
|
|
14
|
-
"browser": "./dist/lib/browser/index.mjs"
|
|
14
|
+
"browser": "./dist/lib/browser/index.mjs",
|
|
15
|
+
"source": "./src/index.ts"
|
|
15
16
|
}
|
|
16
17
|
},
|
|
17
18
|
"types": "dist/types/src/index.d.ts",
|
|
@@ -23,19 +24,23 @@
|
|
|
23
24
|
"src"
|
|
24
25
|
],
|
|
25
26
|
"dependencies": {
|
|
26
|
-
"@
|
|
27
|
-
"
|
|
28
|
-
"@
|
|
29
|
-
"
|
|
30
|
-
"@dxos/
|
|
31
|
-
"@dxos/
|
|
32
|
-
"@dxos/
|
|
27
|
+
"@tauri-apps/plugin-os": "^2.3.0",
|
|
28
|
+
"@tauri-apps/plugin-process": "^2.3.0",
|
|
29
|
+
"@tauri-apps/plugin-updater": "^2.9.0",
|
|
30
|
+
"effect": "3.17.0",
|
|
31
|
+
"@dxos/log": "0.8.4-main.5acf9ea",
|
|
32
|
+
"@dxos/app-framework": "0.8.4-main.5acf9ea",
|
|
33
|
+
"@dxos/plugin-help": "0.8.4-main.5acf9ea",
|
|
34
|
+
"@dxos/plugin-navtree": "0.8.4-main.5acf9ea",
|
|
35
|
+
"@dxos/util": "0.8.4-main.5acf9ea"
|
|
33
36
|
},
|
|
34
37
|
"devDependencies": {
|
|
35
|
-
"vite": "5.4.7"
|
|
38
|
+
"vite": "5.4.7",
|
|
39
|
+
"@dxos/react-ui": "0.8.4-main.5acf9ea"
|
|
36
40
|
},
|
|
37
41
|
"peerDependencies": {
|
|
38
|
-
"effect": "^3.13.3"
|
|
42
|
+
"effect": "^3.13.3",
|
|
43
|
+
"@dxos/react-ui": "0.8.4-main.5acf9ea"
|
|
39
44
|
},
|
|
40
45
|
"publishConfig": {
|
|
41
46
|
"access": "public"
|
package/src/NativePlugin.tsx
CHANGED
|
@@ -2,22 +2,22 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import { definePlugin, Events, defineModule } from '@dxos/app-framework';
|
|
5
|
+
import { definePlugin, Events, defineModule, contributes, Capabilities } from '@dxos/app-framework';
|
|
7
6
|
|
|
7
|
+
import { Updater } from './capabilities';
|
|
8
8
|
import { meta } from './meta';
|
|
9
|
-
|
|
10
|
-
// TODO(burdon): Initial url has index.html, which must be caught/redirected.
|
|
9
|
+
import { translations } from './translations';
|
|
11
10
|
|
|
12
11
|
export const NativePlugin = () =>
|
|
13
12
|
definePlugin(meta, [
|
|
14
13
|
defineModule({
|
|
15
|
-
id: `${meta.id}/module/
|
|
14
|
+
id: `${meta.id}/module/translations`,
|
|
15
|
+
activatesOn: Events.SetupTranslations,
|
|
16
|
+
activate: () => contributes(Capabilities.Translations, translations),
|
|
17
|
+
}),
|
|
18
|
+
defineModule({
|
|
19
|
+
id: `${meta.id}/module/updater`,
|
|
16
20
|
activatesOn: Events.DispatcherReady,
|
|
17
|
-
activate:
|
|
18
|
-
const { initializeNativeApp } = await import('./initialize');
|
|
19
|
-
await initializeNativeApp(context);
|
|
20
|
-
return [];
|
|
21
|
-
},
|
|
21
|
+
activate: Updater,
|
|
22
22
|
}),
|
|
23
23
|
]);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type } from '@tauri-apps/plugin-os';
|
|
6
|
+
import { relaunch } from '@tauri-apps/plugin-process';
|
|
7
|
+
import { check, type DownloadEvent } from '@tauri-apps/plugin-updater';
|
|
8
|
+
import { Duration, Effect, Fiber, Match, pipe, Schedule } from 'effect';
|
|
9
|
+
|
|
10
|
+
import { Capabilities, contributes, createIntent, LayoutAction, type PluginContext } from '@dxos/app-framework';
|
|
11
|
+
import { log } from '@dxos/log';
|
|
12
|
+
|
|
13
|
+
import { NATIVE_PLUGIN } from '../meta';
|
|
14
|
+
|
|
15
|
+
const SUPPORTS_OTA = ['linux', 'macos', 'windows'];
|
|
16
|
+
|
|
17
|
+
export default (context: PluginContext) => {
|
|
18
|
+
const platform = type();
|
|
19
|
+
if (!SUPPORTS_OTA.includes(platform)) {
|
|
20
|
+
return contributes(Capabilities.Null, null);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const { dispatch } = context.getCapability(Capabilities.IntentDispatcher);
|
|
24
|
+
|
|
25
|
+
// https://tauri.app/plugin/updater/#checking-for-updates
|
|
26
|
+
const action = Effect.gen(function* () {
|
|
27
|
+
log.info('checking for updates');
|
|
28
|
+
const update = yield* Effect.tryPromise(() => check());
|
|
29
|
+
log.info('checked for updates', { version: update?.version, currentVersion: update?.currentVersion });
|
|
30
|
+
if (update) {
|
|
31
|
+
log.info('update available', update);
|
|
32
|
+
let downloaded = 0;
|
|
33
|
+
let contentLength = 0;
|
|
34
|
+
|
|
35
|
+
const handleDownload = Match.type<DownloadEvent>().pipe(
|
|
36
|
+
Match.when({ event: 'Started' }, (event) => {
|
|
37
|
+
contentLength = event.data.contentLength ?? 0;
|
|
38
|
+
log.info('download started', { contentLength });
|
|
39
|
+
}),
|
|
40
|
+
Match.when({ event: 'Progress' }, (event) => {
|
|
41
|
+
downloaded += event.data.chunkLength;
|
|
42
|
+
log.info('download progress', { downloaded, contentLength });
|
|
43
|
+
}),
|
|
44
|
+
Match.when({ event: 'Finished' }, () => {
|
|
45
|
+
log.info('download completed');
|
|
46
|
+
}),
|
|
47
|
+
Match.exhaustive,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
yield* Effect.tryPromise(() => update.downloadAndInstall(handleDownload));
|
|
51
|
+
|
|
52
|
+
yield* dispatch(
|
|
53
|
+
createIntent(LayoutAction.AddToast, {
|
|
54
|
+
part: 'toast',
|
|
55
|
+
subject: {
|
|
56
|
+
id: `${NATIVE_PLUGIN}/update-ready`,
|
|
57
|
+
title: ['update ready label', { ns: NATIVE_PLUGIN }],
|
|
58
|
+
description: ['update ready description', { ns: NATIVE_PLUGIN }],
|
|
59
|
+
duration: Infinity,
|
|
60
|
+
actionLabel: ['update label', { ns: NATIVE_PLUGIN }],
|
|
61
|
+
actionAlt: ['update alt', { ns: NATIVE_PLUGIN }],
|
|
62
|
+
onAction: () => relaunch(),
|
|
63
|
+
},
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const fiber = pipe(
|
|
70
|
+
// prettier-ignore
|
|
71
|
+
action,
|
|
72
|
+
Effect.repeat(Schedule.fixed(Duration.hours(1))),
|
|
73
|
+
Effect.runFork,
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
return contributes(Capabilities.Null, null, () => {
|
|
77
|
+
Effect.runSync(Fiber.interrupt(fiber));
|
|
78
|
+
});
|
|
79
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Resource } from '@dxos/react-ui';
|
|
6
|
+
|
|
7
|
+
import { meta } from './meta';
|
|
8
|
+
|
|
9
|
+
export const translations = [
|
|
10
|
+
{
|
|
11
|
+
'en-US': {
|
|
12
|
+
[meta.id]: {
|
|
13
|
+
'update ready label': 'Ready to update',
|
|
14
|
+
'update ready description': 'A new version of Composer is available.',
|
|
15
|
+
'update label': 'Update',
|
|
16
|
+
'update alt': 'Relaunch the app to update',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
] as const satisfies Resource[];
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
// packages/plugins/plugin-native/src/initialize.ts
|
|
2
|
-
import { SettingsAction, LayoutAction, createIntent, Capabilities } from "@dxos/app-framework";
|
|
3
|
-
import { HELP_PLUGIN } from "@dxos/plugin-help";
|
|
4
|
-
import { COMMANDS_DIALOG } from "@dxos/plugin-navtree";
|
|
5
|
-
import { safeParseJson } from "@dxos/util";
|
|
6
|
-
var KEY_WINDOW_SIZE = "dxos.org/plugin/native/window-size";
|
|
7
|
-
var loadSocketSupplyModules = async () => {
|
|
8
|
-
const module = "socket:application";
|
|
9
|
-
const app = await import(
|
|
10
|
-
/* @vite-ignore */
|
|
11
|
-
module
|
|
12
|
-
);
|
|
13
|
-
const windowModule = "socket:window";
|
|
14
|
-
const socketWindow = await import(
|
|
15
|
-
/* @vite-ignore */
|
|
16
|
-
windowModule
|
|
17
|
-
);
|
|
18
|
-
const osModule = "socket:os";
|
|
19
|
-
const socketOs = await import(
|
|
20
|
-
/* @vite-ignore */
|
|
21
|
-
osModule
|
|
22
|
-
);
|
|
23
|
-
const { meta_title: appName } = app.config;
|
|
24
|
-
return {
|
|
25
|
-
app,
|
|
26
|
-
socketWindow,
|
|
27
|
-
socketOs,
|
|
28
|
-
appName
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
var configureDesktopWindowSizing = async (app) => {
|
|
32
|
-
const { width, height } = safeParseJson(localStorage.getItem(KEY_WINDOW_SIZE), {});
|
|
33
|
-
if (width && height) {
|
|
34
|
-
const appWindow = await app.getCurrentWindow();
|
|
35
|
-
await appWindow.setSize({
|
|
36
|
-
width,
|
|
37
|
-
height
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
window.addEventListener("resize", async () => {
|
|
41
|
-
const appWindow = await app.getCurrentWindow();
|
|
42
|
-
const { width: width2, height: height2 } = appWindow.getSize();
|
|
43
|
-
localStorage.setItem(KEY_WINDOW_SIZE, JSON.stringify({
|
|
44
|
-
width: width2,
|
|
45
|
-
height: height2
|
|
46
|
-
}));
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
var configureSystemMenu = async (app, appName) => {
|
|
50
|
-
const itemsMac = `
|
|
51
|
-
Hide ${appName}: h + CommandOrControl
|
|
52
|
-
Hide Others: h + Control + Meta
|
|
53
|
-
---
|
|
54
|
-
`;
|
|
55
|
-
const menu = `
|
|
56
|
-
App Name:
|
|
57
|
-
About ${appName}: _
|
|
58
|
-
Settings...: , + CommandOrControl
|
|
59
|
-
---
|
|
60
|
-
Show shortcuts: / + CommandOrControl
|
|
61
|
-
Search commands: k + CommandOrControl
|
|
62
|
-
---
|
|
63
|
-
${itemsMac}
|
|
64
|
-
Quit: q + CommandOrControl
|
|
65
|
-
;
|
|
66
|
-
|
|
67
|
-
Edit:
|
|
68
|
-
Cut: x + CommandOrControl
|
|
69
|
-
Copy: c + CommandOrControl
|
|
70
|
-
Paste: v + CommandOrControl
|
|
71
|
-
Delete: _
|
|
72
|
-
Select All: a + CommandOrControl
|
|
73
|
-
;
|
|
74
|
-
`;
|
|
75
|
-
void app.setSystemMenu({
|
|
76
|
-
index: 0,
|
|
77
|
-
value: menu
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
var setupMenuItemListener = (dispatch, app) => {
|
|
81
|
-
window.addEventListener("menuItemSelected", async (event) => {
|
|
82
|
-
const id = `${event.detail.parent}:${event.detail.title}`;
|
|
83
|
-
switch (id) {
|
|
84
|
-
case "App Name:Search commands": {
|
|
85
|
-
void dispatch(createIntent(LayoutAction.UpdateDialog, {
|
|
86
|
-
part: "dialog",
|
|
87
|
-
subject: COMMANDS_DIALOG,
|
|
88
|
-
options: {
|
|
89
|
-
blockAlign: "start"
|
|
90
|
-
}
|
|
91
|
-
}));
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
case "App Name:Settings...": {
|
|
95
|
-
void dispatch(createIntent(SettingsAction.Open));
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
case "App Name:Show shortcuts": {
|
|
99
|
-
void dispatch(createIntent(LayoutAction.UpdateDialog, {
|
|
100
|
-
part: "dialog",
|
|
101
|
-
subject: `${HELP_PLUGIN}/Shortcuts`,
|
|
102
|
-
options: {
|
|
103
|
-
blockAlign: "center"
|
|
104
|
-
}
|
|
105
|
-
}));
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
case "App Name:Quit": {
|
|
109
|
-
await app.exit();
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
var setupApplicationUrlListener = (app, dispatch) => {
|
|
116
|
-
const appWindow = app.getCurrentWindow();
|
|
117
|
-
window.addEventListener("applicationurl", ({ url }) => {
|
|
118
|
-
appWindow.restore();
|
|
119
|
-
const location = url.toString().replace("composer://", "");
|
|
120
|
-
if (location.includes("InvitationCode")) {
|
|
121
|
-
window.location.href = location;
|
|
122
|
-
} else {
|
|
123
|
-
void dispatch(createIntent(LayoutAction.Open, {
|
|
124
|
-
part: "main",
|
|
125
|
-
subject: [
|
|
126
|
-
location
|
|
127
|
-
]
|
|
128
|
-
}));
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
};
|
|
132
|
-
var setupGlobalHotkey = async (socketWindow, appWindow, dispatch) => {
|
|
133
|
-
const binding = await socketWindow.hotkey.bind("cmd + k");
|
|
134
|
-
binding.addEventListener("hotkey", () => {
|
|
135
|
-
appWindow.restore();
|
|
136
|
-
void dispatch(createIntent(LayoutAction.UpdateDialog, {
|
|
137
|
-
part: "dialog",
|
|
138
|
-
subject: COMMANDS_DIALOG,
|
|
139
|
-
options: {
|
|
140
|
-
blockAlign: "start"
|
|
141
|
-
}
|
|
142
|
-
}));
|
|
143
|
-
});
|
|
144
|
-
};
|
|
145
|
-
var initializeNativeApp = async (context) => {
|
|
146
|
-
const { app, socketWindow, socketOs, appName } = await loadSocketSupplyModules();
|
|
147
|
-
const { dispatchPromise: dispatch } = context.getCapability(Capabilities.IntentDispatcher);
|
|
148
|
-
const platform = socketOs.platform();
|
|
149
|
-
document.body.setAttribute("data-platform", platform);
|
|
150
|
-
if (platform === "darwin" || platform === "win32") {
|
|
151
|
-
await configureDesktopWindowSizing(app);
|
|
152
|
-
await configureSystemMenu(app, appName);
|
|
153
|
-
setupMenuItemListener(dispatch, app);
|
|
154
|
-
setupApplicationUrlListener(app, dispatch);
|
|
155
|
-
await setupGlobalHotkey(socketWindow, app, dispatch);
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
export {
|
|
159
|
-
initializeNativeApp
|
|
160
|
-
};
|
|
161
|
-
//# sourceMappingURL=initialize-OGKEIRPC.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/initialize.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport type { PluginContext } from '@dxos/app-framework';\nimport { SettingsAction, LayoutAction, createIntent, Capabilities } from '@dxos/app-framework';\nimport { HELP_PLUGIN } from '@dxos/plugin-help';\nimport { COMMANDS_DIALOG } from '@dxos/plugin-navtree';\nimport { safeParseJson } from '@dxos/util';\n\n// TODO(burdon): Reconcile with other properties.\nconst KEY_WINDOW_SIZE = 'dxos.org/plugin/native/window-size';\n\n/**\n * Native code for socketsupply app.\n * https://www.npmjs.com/package/@socketsupply/socket\n * https://github.com/socketsupply/socket-examples\n */\n\nconst loadSocketSupplyModules = async () => {\n // SocketSupply implements the dynamic import.\n const module = 'socket:application';\n const app = await import(/* @vite-ignore */ module);\n const windowModule = 'socket:window';\n const socketWindow = await import(/* @vite-ignore */ windowModule);\n const osModule = 'socket:os';\n const socketOs = await import(/* @vite-ignore */ osModule);\n const { meta_title: appName } = app.config;\n\n return { app, socketWindow, socketOs, appName };\n};\n\nconst configureDesktopWindowSizing = async (app: any) => {\n const { width, height } = safeParseJson<{ width?: number; height?: number }>(\n localStorage.getItem(KEY_WINDOW_SIZE),\n {},\n );\n\n if (width && height) {\n const appWindow = await app.getCurrentWindow();\n await appWindow.setSize({ width, height });\n }\n\n window.addEventListener('resize', async () => {\n const appWindow = await app.getCurrentWindow();\n const { width, height } = appWindow.getSize();\n localStorage.setItem(KEY_WINDOW_SIZE, JSON.stringify({ width, height }));\n });\n};\n\nconst configureSystemMenu = async (app: any, appName: string) => {\n const itemsMac = `\n Hide ${appName}: h + CommandOrControl\n Hide Others: h + Control + Meta\n ---\n `;\n\n // TODO(mjamesderocher) Change menu names to use translations\n const menu = `\n App Name:\n About ${appName}: _\n Settings...: , + CommandOrControl\n ---\n Show shortcuts: / + CommandOrControl\n Search commands: k + CommandOrControl\n ---\n ${itemsMac}\n Quit: q + CommandOrControl\n ;\n\n Edit:\n Cut: x + CommandOrControl\n Copy: c + CommandOrControl\n Paste: v + CommandOrControl\n Delete: _\n Select All: a + CommandOrControl\n ;\n `;\n\n void app.setSystemMenu({ index: 0, value: menu });\n};\n\nconst setupMenuItemListener = (dispatch: any, app: any) => {\n window.addEventListener('menuItemSelected', async (event: any) => {\n const id = `${event.detail.parent}:${event.detail.title}`;\n switch (id) {\n case 'App Name:Search commands': {\n void dispatch(\n createIntent(LayoutAction.UpdateDialog, {\n part: 'dialog',\n subject: COMMANDS_DIALOG,\n options: {\n blockAlign: 'start',\n },\n }),\n );\n break;\n }\n case 'App Name:Settings...': {\n void dispatch(createIntent(SettingsAction.Open));\n break;\n }\n case 'App Name:Show shortcuts': {\n void dispatch(\n createIntent(LayoutAction.UpdateDialog, {\n part: 'dialog',\n subject: `${HELP_PLUGIN}/Shortcuts`,\n options: {\n blockAlign: 'center',\n },\n }),\n );\n break;\n }\n case 'App Name:Quit': {\n await app.exit();\n break;\n }\n }\n });\n};\n\nconst setupApplicationUrlListener = (app: any, dispatch: any) => {\n const appWindow = app.getCurrentWindow();\n\n // applicationurl is a custom event fired by the Socket Supply Runtime:\n // https://github.com/socketsupply/socket/blob/ef7fb5559876e41062d5896aafb7b79989fc96e5/api/internal/events.js#L6\n window.addEventListener('applicationurl', ({ url }: any) => {\n appWindow.restore();\n const location = url.toString().replace('composer://', '');\n if (location.includes('InvitationCode')) {\n // TODO(mjamesderocher): Integrate this with app routing.\n // Currently, the dialogs are controlled by Client Plugin and not the Layout Plugin.\n window.location.href = location;\n } else {\n // TODO(thure): What is `location` and is this right?\n void dispatch(createIntent(LayoutAction.Open, { part: 'main', subject: [location] }));\n }\n });\n};\n\nconst setupGlobalHotkey = async (socketWindow: any, appWindow: any, dispatch: any) => {\n const binding = await socketWindow.hotkey.bind('cmd + k');\n\n // Global hotkey listener\n binding.addEventListener('hotkey', () => {\n appWindow.restore();\n void dispatch(\n createIntent(LayoutAction.UpdateDialog, {\n part: 'dialog',\n subject: COMMANDS_DIALOG,\n options: {\n blockAlign: 'start',\n },\n }),\n );\n });\n};\n\nexport const initializeNativeApp = async (context: PluginContext) => {\n const { app, socketWindow, socketOs, appName } = await loadSocketSupplyModules();\n const { dispatchPromise: dispatch } = context.getCapability(Capabilities.IntentDispatcher);\n\n const platform = socketOs.platform();\n\n document.body.setAttribute('data-platform', platform);\n\n if (platform === 'darwin' || platform === 'win32') {\n await configureDesktopWindowSizing(app);\n await configureSystemMenu(app, appName);\n setupMenuItemListener(dispatch, app);\n setupApplicationUrlListener(app, dispatch);\n await setupGlobalHotkey(socketWindow, app, dispatch);\n }\n};\n"],
|
|
5
|
-
"mappings": ";AAKA,SAASA,gBAAgBC,cAAcC,cAAcC,oBAAoB;AACzE,SAASC,mBAAmB;AAC5B,SAASC,uBAAuB;AAChC,SAASC,qBAAqB;AAG9B,IAAMC,kBAAkB;AAQxB,IAAMC,0BAA0B,YAAA;AAE9B,QAAMC,SAAS;AACf,QAAMC,MAAM,MAAM;;IAA0BD;;AAC5C,QAAME,eAAe;AACrB,QAAMC,eAAe,MAAM;;IAA0BD;;AACrD,QAAME,WAAW;AACjB,QAAMC,WAAW,MAAM;;IAA0BD;;AACjD,QAAM,EAAEE,YAAYC,QAAO,IAAKN,IAAIO;AAEpC,SAAO;IAAEP;IAAKE;IAAcE;IAAUE;EAAQ;AAChD;AAEA,IAAME,+BAA+B,OAAOR,QAAAA;AAC1C,QAAM,EAAES,OAAOC,OAAM,IAAKC,cACxBC,aAAaC,QAAQhB,eAAAA,GACrB,CAAC,CAAA;AAGH,MAAIY,SAASC,QAAQ;AACnB,UAAMI,YAAY,MAAMd,IAAIe,iBAAgB;AAC5C,UAAMD,UAAUE,QAAQ;MAA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"COMMANDS_DIALOG", "safeParseJson", "KEY_WINDOW_SIZE", "loadSocketSupplyModules", "module", "app", "windowModule", "socketWindow", "osModule", "socketOs", "meta_title", "appName", "config", "configureDesktopWindowSizing", "width", "height", "safeParseJson", "localStorage", "getItem", "appWindow", "getCurrentWindow", "setSize", "window", "addEventListener", "getSize", "setItem", "JSON", "stringify", "configureSystemMenu", "itemsMac", "menu", "setSystemMenu", "index", "value", "setupMenuItemListener", "dispatch", "event", "id", "detail", "parent", "title", "createIntent", "LayoutAction", "UpdateDialog", "part", "subject", "COMMANDS_DIALOG", "options", "blockAlign", "SettingsAction", "Open", "HELP_PLUGIN", "exit", "setupApplicationUrlListener", "url", "restore", "location", "toString", "replace", "includes", "href", "setupGlobalHotkey", "binding", "hotkey", "bind", "initializeNativeApp", "context", "dispatchPromise", "getCapability", "Capabilities", "IntentDispatcher", "platform", "document", "body", "setAttribute"]
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../../../src/initialize.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AA2JzD,eAAO,MAAM,mBAAmB,GAAU,SAAS,aAAa,kBAe/D,CAAC"}
|
package/src/initialize.ts
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import type { PluginContext } from '@dxos/app-framework';
|
|
6
|
-
import { SettingsAction, LayoutAction, createIntent, Capabilities } from '@dxos/app-framework';
|
|
7
|
-
import { HELP_PLUGIN } from '@dxos/plugin-help';
|
|
8
|
-
import { COMMANDS_DIALOG } from '@dxos/plugin-navtree';
|
|
9
|
-
import { safeParseJson } from '@dxos/util';
|
|
10
|
-
|
|
11
|
-
// TODO(burdon): Reconcile with other properties.
|
|
12
|
-
const KEY_WINDOW_SIZE = 'dxos.org/plugin/native/window-size';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Native code for socketsupply app.
|
|
16
|
-
* https://www.npmjs.com/package/@socketsupply/socket
|
|
17
|
-
* https://github.com/socketsupply/socket-examples
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
const loadSocketSupplyModules = async () => {
|
|
21
|
-
// SocketSupply implements the dynamic import.
|
|
22
|
-
const module = 'socket:application';
|
|
23
|
-
const app = await import(/* @vite-ignore */ module);
|
|
24
|
-
const windowModule = 'socket:window';
|
|
25
|
-
const socketWindow = await import(/* @vite-ignore */ windowModule);
|
|
26
|
-
const osModule = 'socket:os';
|
|
27
|
-
const socketOs = await import(/* @vite-ignore */ osModule);
|
|
28
|
-
const { meta_title: appName } = app.config;
|
|
29
|
-
|
|
30
|
-
return { app, socketWindow, socketOs, appName };
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const configureDesktopWindowSizing = async (app: any) => {
|
|
34
|
-
const { width, height } = safeParseJson<{ width?: number; height?: number }>(
|
|
35
|
-
localStorage.getItem(KEY_WINDOW_SIZE),
|
|
36
|
-
{},
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
if (width && height) {
|
|
40
|
-
const appWindow = await app.getCurrentWindow();
|
|
41
|
-
await appWindow.setSize({ width, height });
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
window.addEventListener('resize', async () => {
|
|
45
|
-
const appWindow = await app.getCurrentWindow();
|
|
46
|
-
const { width, height } = appWindow.getSize();
|
|
47
|
-
localStorage.setItem(KEY_WINDOW_SIZE, JSON.stringify({ width, height }));
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const configureSystemMenu = async (app: any, appName: string) => {
|
|
52
|
-
const itemsMac = `
|
|
53
|
-
Hide ${appName}: h + CommandOrControl
|
|
54
|
-
Hide Others: h + Control + Meta
|
|
55
|
-
---
|
|
56
|
-
`;
|
|
57
|
-
|
|
58
|
-
// TODO(mjamesderocher) Change menu names to use translations
|
|
59
|
-
const menu = `
|
|
60
|
-
App Name:
|
|
61
|
-
About ${appName}: _
|
|
62
|
-
Settings...: , + CommandOrControl
|
|
63
|
-
---
|
|
64
|
-
Show shortcuts: / + CommandOrControl
|
|
65
|
-
Search commands: k + CommandOrControl
|
|
66
|
-
---
|
|
67
|
-
${itemsMac}
|
|
68
|
-
Quit: q + CommandOrControl
|
|
69
|
-
;
|
|
70
|
-
|
|
71
|
-
Edit:
|
|
72
|
-
Cut: x + CommandOrControl
|
|
73
|
-
Copy: c + CommandOrControl
|
|
74
|
-
Paste: v + CommandOrControl
|
|
75
|
-
Delete: _
|
|
76
|
-
Select All: a + CommandOrControl
|
|
77
|
-
;
|
|
78
|
-
`;
|
|
79
|
-
|
|
80
|
-
void app.setSystemMenu({ index: 0, value: menu });
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const setupMenuItemListener = (dispatch: any, app: any) => {
|
|
84
|
-
window.addEventListener('menuItemSelected', async (event: any) => {
|
|
85
|
-
const id = `${event.detail.parent}:${event.detail.title}`;
|
|
86
|
-
switch (id) {
|
|
87
|
-
case 'App Name:Search commands': {
|
|
88
|
-
void dispatch(
|
|
89
|
-
createIntent(LayoutAction.UpdateDialog, {
|
|
90
|
-
part: 'dialog',
|
|
91
|
-
subject: COMMANDS_DIALOG,
|
|
92
|
-
options: {
|
|
93
|
-
blockAlign: 'start',
|
|
94
|
-
},
|
|
95
|
-
}),
|
|
96
|
-
);
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
case 'App Name:Settings...': {
|
|
100
|
-
void dispatch(createIntent(SettingsAction.Open));
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
case 'App Name:Show shortcuts': {
|
|
104
|
-
void dispatch(
|
|
105
|
-
createIntent(LayoutAction.UpdateDialog, {
|
|
106
|
-
part: 'dialog',
|
|
107
|
-
subject: `${HELP_PLUGIN}/Shortcuts`,
|
|
108
|
-
options: {
|
|
109
|
-
blockAlign: 'center',
|
|
110
|
-
},
|
|
111
|
-
}),
|
|
112
|
-
);
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
case 'App Name:Quit': {
|
|
116
|
-
await app.exit();
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const setupApplicationUrlListener = (app: any, dispatch: any) => {
|
|
124
|
-
const appWindow = app.getCurrentWindow();
|
|
125
|
-
|
|
126
|
-
// applicationurl is a custom event fired by the Socket Supply Runtime:
|
|
127
|
-
// https://github.com/socketsupply/socket/blob/ef7fb5559876e41062d5896aafb7b79989fc96e5/api/internal/events.js#L6
|
|
128
|
-
window.addEventListener('applicationurl', ({ url }: any) => {
|
|
129
|
-
appWindow.restore();
|
|
130
|
-
const location = url.toString().replace('composer://', '');
|
|
131
|
-
if (location.includes('InvitationCode')) {
|
|
132
|
-
// TODO(mjamesderocher): Integrate this with app routing.
|
|
133
|
-
// Currently, the dialogs are controlled by Client Plugin and not the Layout Plugin.
|
|
134
|
-
window.location.href = location;
|
|
135
|
-
} else {
|
|
136
|
-
// TODO(thure): What is `location` and is this right?
|
|
137
|
-
void dispatch(createIntent(LayoutAction.Open, { part: 'main', subject: [location] }));
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
const setupGlobalHotkey = async (socketWindow: any, appWindow: any, dispatch: any) => {
|
|
143
|
-
const binding = await socketWindow.hotkey.bind('cmd + k');
|
|
144
|
-
|
|
145
|
-
// Global hotkey listener
|
|
146
|
-
binding.addEventListener('hotkey', () => {
|
|
147
|
-
appWindow.restore();
|
|
148
|
-
void dispatch(
|
|
149
|
-
createIntent(LayoutAction.UpdateDialog, {
|
|
150
|
-
part: 'dialog',
|
|
151
|
-
subject: COMMANDS_DIALOG,
|
|
152
|
-
options: {
|
|
153
|
-
blockAlign: 'start',
|
|
154
|
-
},
|
|
155
|
-
}),
|
|
156
|
-
);
|
|
157
|
-
});
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
export const initializeNativeApp = async (context: PluginContext) => {
|
|
161
|
-
const { app, socketWindow, socketOs, appName } = await loadSocketSupplyModules();
|
|
162
|
-
const { dispatchPromise: dispatch } = context.getCapability(Capabilities.IntentDispatcher);
|
|
163
|
-
|
|
164
|
-
const platform = socketOs.platform();
|
|
165
|
-
|
|
166
|
-
document.body.setAttribute('data-platform', platform);
|
|
167
|
-
|
|
168
|
-
if (platform === 'darwin' || platform === 'win32') {
|
|
169
|
-
await configureDesktopWindowSizing(app);
|
|
170
|
-
await configureSystemMenu(app, appName);
|
|
171
|
-
setupMenuItemListener(dispatch, app);
|
|
172
|
-
setupApplicationUrlListener(app, dispatch);
|
|
173
|
-
await setupGlobalHotkey(socketWindow, app, dispatch);
|
|
174
|
-
}
|
|
175
|
-
};
|