@dxos/plugin-native 0.7.4-staging.f7e8224 → 0.7.5-labs.5f04cf6
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/index.mjs +18 -167
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/initialize-6OEQRMUZ.mjs +151 -0
- package/dist/lib/browser/initialize-6OEQRMUZ.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/NativePlugin.d.ts +1 -2
- package/dist/types/src/NativePlugin.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/initialize.d.ts +3 -0
- package/dist/types/src/initialize.d.ts.map +1 -0
- package/dist/types/src/meta.d.ts +2 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +7 -15
- package/src/NativePlugin.tsx +16 -165
- package/src/index.ts +1 -4
- package/src/initialize.ts +167 -0
- package/src/meta.ts +4 -2
- package/dist/lib/browser/chunk-FIFLINF5.mjs +0 -9
- package/dist/lib/browser/chunk-FIFLINF5.mjs.map +0 -7
- package/dist/lib/browser/meta.mjs +0 -7
- package/dist/lib/browser/meta.mjs.map +0 -7
|
@@ -1,174 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// packages/plugins/experimental/plugin-native/src/NativePlugin.tsx
|
|
6
|
-
import { NavigationAction, SettingsAction, LayoutAction, parseIntentPlugin, resolvePlugin } from "@dxos/app-framework";
|
|
7
|
-
import { HELP_PLUGIN } from "@dxos/plugin-help/meta";
|
|
8
|
-
import { NAVTREE_PLUGIN } from "@dxos/plugin-navtree/meta";
|
|
9
|
-
import { safeParseJson } from "@dxos/util";
|
|
10
|
-
var KEY_WINDOW_SIZE = "dxos.org/plugin/native/window-size";
|
|
11
|
-
var loadSocketSupplyModules = async () => {
|
|
12
|
-
const module = "socket:application";
|
|
13
|
-
const app = await import(
|
|
14
|
-
/* @vite-ignore */
|
|
15
|
-
module
|
|
16
|
-
);
|
|
17
|
-
const windowModule = "socket:window";
|
|
18
|
-
const socketWindow = await import(
|
|
19
|
-
/* @vite-ignore */
|
|
20
|
-
windowModule
|
|
21
|
-
);
|
|
22
|
-
const { meta_title: appName } = app.config;
|
|
23
|
-
return {
|
|
24
|
-
app,
|
|
25
|
-
socketWindow,
|
|
26
|
-
appName
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
var configureDesktopWindowSizing = async (app) => {
|
|
30
|
-
const { width, height } = safeParseJson(localStorage.getItem(KEY_WINDOW_SIZE), {});
|
|
31
|
-
if (width && height) {
|
|
32
|
-
const appWindow = await app.getCurrentWindow();
|
|
33
|
-
await appWindow.setSize({
|
|
34
|
-
width,
|
|
35
|
-
height
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
window.addEventListener("resize", async () => {
|
|
39
|
-
const appWindow = await app.getCurrentWindow();
|
|
40
|
-
const { width: width2, height: height2 } = appWindow.getSize();
|
|
41
|
-
localStorage.setItem(KEY_WINDOW_SIZE, JSON.stringify({
|
|
42
|
-
width: width2,
|
|
43
|
-
height: height2
|
|
44
|
-
}));
|
|
45
|
-
});
|
|
1
|
+
// packages/plugins/experimental/plugin-native/src/meta.ts
|
|
2
|
+
var NATIVE_PLUGIN = "dxos.org/plugin/native";
|
|
3
|
+
var meta = {
|
|
4
|
+
id: NATIVE_PLUGIN
|
|
46
5
|
};
|
|
47
|
-
var configureSystemMenu = async (app, appName) => {
|
|
48
|
-
const itemsMac = `
|
|
49
|
-
Hide ${appName}: h + CommandOrControl
|
|
50
|
-
Hide Others: h + Control + Meta
|
|
51
|
-
---
|
|
52
|
-
`;
|
|
53
|
-
const menu = `
|
|
54
|
-
App Name:
|
|
55
|
-
About ${appName}: _
|
|
56
|
-
Settings...: , + CommandOrControl
|
|
57
|
-
---
|
|
58
|
-
Show shortcuts: / + CommandOrControl
|
|
59
|
-
Search commands: k + CommandOrControl
|
|
60
|
-
---
|
|
61
|
-
${itemsMac}
|
|
62
|
-
Quit: q + CommandOrControl
|
|
63
|
-
;
|
|
64
6
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
value: menu
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
var setupMenuItemListener = (intentPlugin, app) => {
|
|
79
|
-
window.addEventListener("menuItemSelected", async (event) => {
|
|
80
|
-
const id = `${event.detail.parent}:${event.detail.title}`;
|
|
81
|
-
switch (id) {
|
|
82
|
-
case "App Name:Search commands": {
|
|
83
|
-
void intentPlugin?.provides.intent.dispatch({
|
|
84
|
-
action: LayoutAction.SET_LAYOUT,
|
|
85
|
-
data: {
|
|
86
|
-
element: "dialog",
|
|
87
|
-
component: `${NAVTREE_PLUGIN}/Commands`
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
case "App Name:Settings...": {
|
|
93
|
-
void intentPlugin?.provides.intent.dispatch({
|
|
94
|
-
action: SettingsAction.OPEN
|
|
95
|
-
});
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
case "App Name:Show shortcuts": {
|
|
99
|
-
void intentPlugin?.provides.intent.dispatch({
|
|
100
|
-
action: LayoutAction.SET_LAYOUT,
|
|
101
|
-
data: {
|
|
102
|
-
element: "dialog",
|
|
103
|
-
component: `${HELP_PLUGIN}/Shortcuts`
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
case "App Name:Quit": {
|
|
109
|
-
await app.exit();
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
var setupApplicationUrlListener = (app, intentPlugin) => {
|
|
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 intentPlugin?.provides.intent.dispatch({
|
|
124
|
-
action: NavigationAction.OPEN,
|
|
125
|
-
// TODO(thure): what is `location` and is this right?
|
|
126
|
-
data: {
|
|
127
|
-
activeParts: {
|
|
128
|
-
main: [
|
|
129
|
-
location
|
|
130
|
-
]
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
});
|
|
7
|
+
// packages/plugins/experimental/plugin-native/src/NativePlugin.tsx
|
|
8
|
+
import { definePlugin, Events, defineModule } from "@dxos/app-framework";
|
|
9
|
+
var NativePlugin = () => definePlugin(meta, [
|
|
10
|
+
defineModule({
|
|
11
|
+
id: `${meta.id}/module/startup`,
|
|
12
|
+
activatesOn: Events.Startup,
|
|
13
|
+
activate: async (context) => {
|
|
14
|
+
const { initializeNativeApp } = await import("./initialize-6OEQRMUZ.mjs");
|
|
15
|
+
await initializeNativeApp(context);
|
|
16
|
+
return [];
|
|
134
17
|
}
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
var setupGlobalHotkey = async (socketWindow, appWindow, intentPlugin) => {
|
|
138
|
-
const binding = await socketWindow.hotkey.bind("cmd + k");
|
|
139
|
-
binding.addEventListener("hotkey", () => {
|
|
140
|
-
appWindow.restore();
|
|
141
|
-
void intentPlugin?.provides.intent.dispatch({
|
|
142
|
-
action: LayoutAction.SET_LAYOUT,
|
|
143
|
-
data: {
|
|
144
|
-
element: "dialog",
|
|
145
|
-
component: `${NAVTREE_PLUGIN}/Commands`
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
};
|
|
150
|
-
var initializeNativeApp = async (plugins) => {
|
|
151
|
-
const { app, socketWindow, appName } = await loadSocketSupplyModules();
|
|
152
|
-
const intentPlugin = resolvePlugin(plugins, parseIntentPlugin);
|
|
153
|
-
if (process.platform === "darwin" || process.platform === "win32") {
|
|
154
|
-
await configureDesktopWindowSizing(app);
|
|
155
|
-
await configureSystemMenu(app, appName);
|
|
156
|
-
setupMenuItemListener(intentPlugin, app);
|
|
157
|
-
setupApplicationUrlListener(app, intentPlugin);
|
|
158
|
-
await setupGlobalHotkey(socketWindow, app, intentPlugin);
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
var NativePlugin = () => ({
|
|
162
|
-
meta: meta_default,
|
|
163
|
-
ready: async (plugins) => {
|
|
164
|
-
await initializeNativeApp(plugins);
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
// packages/plugins/experimental/plugin-native/src/index.ts
|
|
169
|
-
var src_default = NativePlugin;
|
|
18
|
+
})
|
|
19
|
+
]);
|
|
170
20
|
export {
|
|
21
|
+
NATIVE_PLUGIN,
|
|
171
22
|
NativePlugin,
|
|
172
|
-
|
|
23
|
+
meta
|
|
173
24
|
};
|
|
174
25
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../../../src/meta.ts", "../../../src/NativePlugin.tsx"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type PluginMeta } from '@dxos/app-framework';\n\nexport const NATIVE_PLUGIN = 'dxos.org/plugin/native';\n\nexport const meta = {\n id: NATIVE_PLUGIN,\n} satisfies PluginMeta;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport type { PluginsContext } from '@dxos/app-framework';\nimport { definePlugin, Events, defineModule } from '@dxos/app-framework';\n\nimport { meta } from './meta';\n\n// TODO(burdon): Initial url has index.html, which must be caught/redirected.\n\nexport const NativePlugin = () =>\n definePlugin(meta, [\n defineModule({\n id: `${meta.id}/module/startup`,\n activatesOn: Events.Startup,\n activate: async (context: PluginsContext) => {\n const { initializeNativeApp } = await import('./initialize');\n await initializeNativeApp(context);\n return [];\n },\n }),\n ]);\n"],
|
|
5
|
+
"mappings": ";AAMO,IAAMA,gBAAgB;AAEtB,IAAMC,OAAO;EAClBC,IAAIF;AACN;;;ACLA,SAASG,cAAcC,QAAQC,oBAAoB;AAM5C,IAAMC,eAAe,MAC1BC,aAAaC,MAAM;EACjBC,aAAa;IACXC,IAAI,GAAGF,KAAKE,EAAE;IACdC,aAAaC,OAAOC;IACpBC,UAAU,OAAOC,YAAAA;AACf,YAAM,EAAEC,oBAAmB,IAAK,MAAM,OAAO,2BAAA;AAC7C,YAAMA,oBAAoBD,OAAAA;AAC1B,aAAO,CAAA;IACT;EACF,CAAA;CACD;",
|
|
6
|
+
"names": ["NATIVE_PLUGIN", "meta", "id", "definePlugin", "Events", "defineModule", "NativePlugin", "definePlugin", "meta", "defineModule", "id", "activatesOn", "Events", "Startup", "activate", "context", "initializeNativeApp"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// packages/plugins/experimental/plugin-native/src/initialize.ts
|
|
2
|
+
import { NavigationAction, 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 { meta_title: appName } = app.config;
|
|
19
|
+
return {
|
|
20
|
+
app,
|
|
21
|
+
socketWindow,
|
|
22
|
+
appName
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
var configureDesktopWindowSizing = async (app) => {
|
|
26
|
+
const { width, height } = safeParseJson(localStorage.getItem(KEY_WINDOW_SIZE), {});
|
|
27
|
+
if (width && height) {
|
|
28
|
+
const appWindow = await app.getCurrentWindow();
|
|
29
|
+
await appWindow.setSize({
|
|
30
|
+
width,
|
|
31
|
+
height
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
window.addEventListener("resize", async () => {
|
|
35
|
+
const appWindow = await app.getCurrentWindow();
|
|
36
|
+
const { width: width2, height: height2 } = appWindow.getSize();
|
|
37
|
+
localStorage.setItem(KEY_WINDOW_SIZE, JSON.stringify({
|
|
38
|
+
width: width2,
|
|
39
|
+
height: height2
|
|
40
|
+
}));
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
var configureSystemMenu = async (app, appName) => {
|
|
44
|
+
const itemsMac = `
|
|
45
|
+
Hide ${appName}: h + CommandOrControl
|
|
46
|
+
Hide Others: h + Control + Meta
|
|
47
|
+
---
|
|
48
|
+
`;
|
|
49
|
+
const menu = `
|
|
50
|
+
App Name:
|
|
51
|
+
About ${appName}: _
|
|
52
|
+
Settings...: , + CommandOrControl
|
|
53
|
+
---
|
|
54
|
+
Show shortcuts: / + CommandOrControl
|
|
55
|
+
Search commands: k + CommandOrControl
|
|
56
|
+
---
|
|
57
|
+
${itemsMac}
|
|
58
|
+
Quit: q + CommandOrControl
|
|
59
|
+
;
|
|
60
|
+
|
|
61
|
+
Edit:
|
|
62
|
+
Cut: x + CommandOrControl
|
|
63
|
+
Copy: c + CommandOrControl
|
|
64
|
+
Paste: v + CommandOrControl
|
|
65
|
+
Delete: _
|
|
66
|
+
Select All: a + CommandOrControl
|
|
67
|
+
;
|
|
68
|
+
`;
|
|
69
|
+
void app.setSystemMenu({
|
|
70
|
+
index: 0,
|
|
71
|
+
value: menu
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
var setupMenuItemListener = (dispatch, app) => {
|
|
75
|
+
window.addEventListener("menuItemSelected", async (event) => {
|
|
76
|
+
const id = `${event.detail.parent}:${event.detail.title}`;
|
|
77
|
+
switch (id) {
|
|
78
|
+
case "App Name:Search commands": {
|
|
79
|
+
void dispatch(createIntent(LayoutAction.SetLayout, {
|
|
80
|
+
element: "dialog",
|
|
81
|
+
component: COMMANDS_DIALOG,
|
|
82
|
+
dialogBlockAlign: "start"
|
|
83
|
+
}));
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
case "App Name:Settings...": {
|
|
87
|
+
void dispatch(createIntent(SettingsAction.Open));
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case "App Name:Show shortcuts": {
|
|
91
|
+
void dispatch(createIntent(LayoutAction.SetLayout, {
|
|
92
|
+
element: "dialog",
|
|
93
|
+
component: `${HELP_PLUGIN}/Shortcuts`
|
|
94
|
+
}));
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
case "App Name:Quit": {
|
|
98
|
+
await app.exit();
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
var setupApplicationUrlListener = (app, dispatch) => {
|
|
105
|
+
const appWindow = app.getCurrentWindow();
|
|
106
|
+
window.addEventListener("applicationurl", ({ url }) => {
|
|
107
|
+
appWindow.restore();
|
|
108
|
+
const location = url.toString().replace("composer://", "");
|
|
109
|
+
if (location.includes("InvitationCode")) {
|
|
110
|
+
window.location.href = location;
|
|
111
|
+
} else {
|
|
112
|
+
void dispatch(createIntent(
|
|
113
|
+
NavigationAction.Open,
|
|
114
|
+
// TODO(thure): what is `location` and is this right?
|
|
115
|
+
{
|
|
116
|
+
activeParts: {
|
|
117
|
+
main: [
|
|
118
|
+
location
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
));
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
var setupGlobalHotkey = async (socketWindow, appWindow, dispatch) => {
|
|
127
|
+
const binding = await socketWindow.hotkey.bind("cmd + k");
|
|
128
|
+
binding.addEventListener("hotkey", () => {
|
|
129
|
+
appWindow.restore();
|
|
130
|
+
void dispatch(createIntent(LayoutAction.SetLayout, {
|
|
131
|
+
element: "dialog",
|
|
132
|
+
component: COMMANDS_DIALOG,
|
|
133
|
+
dialogBlockAlign: "start"
|
|
134
|
+
}));
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
var initializeNativeApp = async (context) => {
|
|
138
|
+
const { app, socketWindow, appName } = await loadSocketSupplyModules();
|
|
139
|
+
const { dispatchPromise: dispatch } = context.requestCapability(Capabilities.IntentDispatcher);
|
|
140
|
+
if (process.platform === "darwin" || process.platform === "win32") {
|
|
141
|
+
await configureDesktopWindowSizing(app);
|
|
142
|
+
await configureSystemMenu(app, appName);
|
|
143
|
+
setupMenuItemListener(dispatch, app);
|
|
144
|
+
setupApplicationUrlListener(app, dispatch);
|
|
145
|
+
await setupGlobalHotkey(socketWindow, app, dispatch);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
export {
|
|
149
|
+
initializeNativeApp
|
|
150
|
+
};
|
|
151
|
+
//# sourceMappingURL=initialize-6OEQRMUZ.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/initialize.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport type { PluginsContext } from '@dxos/app-framework';\nimport { NavigationAction, 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 { meta_title: appName } = app.config;\n\n return { app, socketWindow, 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.SetLayout, {\n element: 'dialog',\n component: COMMANDS_DIALOG,\n dialogBlockAlign: 'start',\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.SetLayout, {\n element: 'dialog',\n component: `${HELP_PLUGIN}/Shortcuts`,\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 void dispatch(\n createIntent(\n NavigationAction.Open,\n // TODO(thure): what is `location` and is this right?\n { activeParts: { main: [location] } },\n ),\n );\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.SetLayout, {\n element: 'dialog',\n component: COMMANDS_DIALOG,\n dialogBlockAlign: 'start',\n }),\n );\n });\n};\n\nexport const initializeNativeApp = async (context: PluginsContext) => {\n const { app, socketWindow, appName } = await loadSocketSupplyModules();\n const { dispatchPromise: dispatch } = context.requestCapability(Capabilities.IntentDispatcher);\n\n if (process.platform === 'darwin' || process.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": "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",
|
|
6
|
+
"names": ["NavigationAction", "SettingsAction", "LayoutAction", "createIntent", "Capabilities", "HELP_PLUGIN", "COMMANDS_DIALOG", "safeParseJson", "KEY_WINDOW_SIZE", "loadSocketSupplyModules", "module", "app", "windowModule", "socketWindow", "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", "SetLayout", "element", "component", "COMMANDS_DIALOG", "dialogBlockAlign", "SettingsAction", "Open", "HELP_PLUGIN", "exit", "setupApplicationUrlListener", "url", "restore", "location", "toString", "replace", "includes", "href", "NavigationAction", "activeParts", "main", "setupGlobalHotkey", "binding", "hotkey", "bind", "initializeNativeApp", "context", "dispatchPromise", "requestCapability", "Capabilities", "IntentDispatcher", "process", "platform"]
|
|
7
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/plugins/experimental/plugin-native/src/meta.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/plugins/experimental/plugin-native/src/meta.ts":{"bytes":916,"imports":[],"format":"esm"},"packages/plugins/experimental/plugin-native/src/initialize.ts":{"bytes":18131,"imports":[{"path":"@dxos/app-framework","kind":"import-statement","external":true},{"path":"@dxos/plugin-help","kind":"import-statement","external":true},{"path":"@dxos/plugin-navtree","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/plugins/experimental/plugin-native/src/NativePlugin.tsx":{"bytes":2499,"imports":[{"path":"@dxos/app-framework","kind":"import-statement","external":true},{"path":"packages/plugins/experimental/plugin-native/src/meta.ts","kind":"import-statement","original":"./meta"},{"path":"packages/plugins/experimental/plugin-native/src/initialize.ts","kind":"dynamic-import","original":"./initialize"}],"format":"esm"},"packages/plugins/experimental/plugin-native/src/index.ts":{"bytes":607,"imports":[{"path":"packages/plugins/experimental/plugin-native/src/meta.ts","kind":"import-statement","original":"./meta"},{"path":"packages/plugins/experimental/plugin-native/src/NativePlugin.tsx","kind":"import-statement","original":"./NativePlugin"}],"format":"esm"}},"outputs":{"packages/plugins/experimental/plugin-native/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":1563},"packages/plugins/experimental/plugin-native/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/app-framework","kind":"import-statement","external":true},{"path":"packages/plugins/experimental/plugin-native/dist/lib/browser/initialize-6OEQRMUZ.mjs","kind":"dynamic-import"}],"exports":["NATIVE_PLUGIN","NativePlugin","meta"],"entryPoint":"packages/plugins/experimental/plugin-native/src/index.ts","inputs":{"packages/plugins/experimental/plugin-native/src/meta.ts":{"bytesInOutput":82},"packages/plugins/experimental/plugin-native/src/index.ts":{"bytesInOutput":0},"packages/plugins/experimental/plugin-native/src/NativePlugin.tsx":{"bytesInOutput":397}},"bytes":694},"packages/plugins/experimental/plugin-native/dist/lib/browser/initialize-6OEQRMUZ.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":9061},"packages/plugins/experimental/plugin-native/dist/lib/browser/initialize-6OEQRMUZ.mjs":{"imports":[{"path":"@dxos/app-framework","kind":"import-statement","external":true},{"path":"@dxos/plugin-help","kind":"import-statement","external":true},{"path":"@dxos/plugin-navtree","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["initializeNativeApp"],"entryPoint":"packages/plugins/experimental/plugin-native/src/initialize.ts","inputs":{"packages/plugins/experimental/plugin-native/src/initialize.ts":{"bytesInOutput":4316}},"bytes":4464}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativePlugin.d.ts","sourceRoot":"","sources":["../../../src/NativePlugin.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NativePlugin.d.ts","sourceRoot":"","sources":["../../../src/NativePlugin.tsx"],"names":[],"mappings":"AAWA,eAAO,MAAM,YAAY,4CAWrB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../../../src/initialize.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAuJ1D,eAAO,MAAM,mBAAmB,YAAmB,cAAc,kBAWhE,CAAC"}
|
package/dist/types/src/meta.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../../src/meta.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../../src/meta.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,aAAa,2BAA2B,CAAC;AAEtD,eAAO,MAAM,IAAI;;CAEK,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"5.7.2"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/plugin-native",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5-labs.5f04cf6",
|
|
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,30 +11,22 @@
|
|
|
11
11
|
".": {
|
|
12
12
|
"types": "./dist/types/src/index.d.ts",
|
|
13
13
|
"browser": "./dist/lib/browser/index.mjs"
|
|
14
|
-
},
|
|
15
|
-
"./meta": {
|
|
16
|
-
"types": "./dist/types/src/meta.d.ts",
|
|
17
|
-
"browser": "./dist/lib/browser/meta.mjs"
|
|
18
14
|
}
|
|
19
15
|
},
|
|
20
16
|
"types": "dist/types/src/index.d.ts",
|
|
21
17
|
"typesVersions": {
|
|
22
|
-
"*": {
|
|
23
|
-
"meta": [
|
|
24
|
-
"dist/types/src/meta.d.ts"
|
|
25
|
-
]
|
|
26
|
-
}
|
|
18
|
+
"*": {}
|
|
27
19
|
},
|
|
28
20
|
"files": [
|
|
29
21
|
"dist",
|
|
30
22
|
"src"
|
|
31
23
|
],
|
|
32
24
|
"dependencies": {
|
|
33
|
-
"@dxos/app-framework": "0.7.
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/
|
|
36
|
-
"@dxos/
|
|
37
|
-
"@dxos/
|
|
25
|
+
"@dxos/app-framework": "0.7.5-labs.5f04cf6",
|
|
26
|
+
"@dxos/plugin-help": "0.7.5-labs.5f04cf6",
|
|
27
|
+
"@dxos/log": "0.7.5-labs.5f04cf6",
|
|
28
|
+
"@dxos/plugin-navtree": "0.7.5-labs.5f04cf6",
|
|
29
|
+
"@dxos/util": "0.7.5-labs.5f04cf6"
|
|
38
30
|
},
|
|
39
31
|
"devDependencies": {
|
|
40
32
|
"vite": "5.4.7"
|
package/src/NativePlugin.tsx
CHANGED
|
@@ -2,171 +2,22 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import type {
|
|
6
|
-
import {
|
|
7
|
-
import { HELP_PLUGIN } from '@dxos/plugin-help/meta';
|
|
8
|
-
import { NAVTREE_PLUGIN } from '@dxos/plugin-navtree/meta';
|
|
9
|
-
import { safeParseJson } from '@dxos/util';
|
|
5
|
+
import type { PluginsContext } from '@dxos/app-framework';
|
|
6
|
+
import { definePlugin, Events, defineModule } from '@dxos/app-framework';
|
|
10
7
|
|
|
11
|
-
import meta from './meta';
|
|
12
|
-
|
|
13
|
-
// TODO(burdon): Reconcile with other properties.
|
|
14
|
-
const KEY_WINDOW_SIZE = 'dxos.org/plugin/native/window-size';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Native code for socketsupply app.
|
|
18
|
-
* https://www.npmjs.com/package/@socketsupply/socket
|
|
19
|
-
* https://github.com/socketsupply/socket-examples
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
const loadSocketSupplyModules = async () => {
|
|
23
|
-
// SocketSupply implements the dynamic import.
|
|
24
|
-
const module = 'socket:application';
|
|
25
|
-
const app = await import(/* @vite-ignore */ module);
|
|
26
|
-
const windowModule = 'socket:window';
|
|
27
|
-
const socketWindow = await import(/* @vite-ignore */ windowModule);
|
|
28
|
-
const { meta_title: appName } = app.config;
|
|
29
|
-
|
|
30
|
-
return { app, socketWindow, 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 = (intentPlugin: 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 intentPlugin?.provides.intent.dispatch({
|
|
89
|
-
action: LayoutAction.SET_LAYOUT,
|
|
90
|
-
data: { element: 'dialog', component: `${NAVTREE_PLUGIN}/Commands` },
|
|
91
|
-
});
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
case 'App Name:Settings...': {
|
|
95
|
-
void intentPlugin?.provides.intent.dispatch({
|
|
96
|
-
action: SettingsAction.OPEN,
|
|
97
|
-
});
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
case 'App Name:Show shortcuts': {
|
|
101
|
-
void intentPlugin?.provides.intent.dispatch({
|
|
102
|
-
action: LayoutAction.SET_LAYOUT,
|
|
103
|
-
data: {
|
|
104
|
-
element: 'dialog',
|
|
105
|
-
component: `${HELP_PLUGIN}/Shortcuts`,
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
case 'App Name:Quit': {
|
|
111
|
-
await app.exit();
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const setupApplicationUrlListener = (app: any, intentPlugin: any) => {
|
|
119
|
-
const appWindow = app.getCurrentWindow();
|
|
120
|
-
|
|
121
|
-
// applicationurl is a custom event fired by the Socket Supply Runtime:
|
|
122
|
-
// https://github.com/socketsupply/socket/blob/ef7fb5559876e41062d5896aafb7b79989fc96e5/api/internal/events.js#L6
|
|
123
|
-
window.addEventListener('applicationurl', ({ url }: any) => {
|
|
124
|
-
appWindow.restore();
|
|
125
|
-
const location = url.toString().replace('composer://', '');
|
|
126
|
-
if (location.includes('InvitationCode')) {
|
|
127
|
-
// TODO(mjamesderocher): Integrate this with app routing.
|
|
128
|
-
// Currently, the dialogs are controlled by Client Plugin and not the Layout Plugin.
|
|
129
|
-
window.location.href = location;
|
|
130
|
-
} else {
|
|
131
|
-
void intentPlugin?.provides.intent.dispatch({
|
|
132
|
-
action: NavigationAction.OPEN,
|
|
133
|
-
// TODO(thure): what is `location` and is this right?
|
|
134
|
-
data: { activeParts: { main: [location] } },
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const setupGlobalHotkey = async (socketWindow: any, appWindow: any, intentPlugin: any) => {
|
|
141
|
-
const binding = await socketWindow.hotkey.bind('cmd + k');
|
|
142
|
-
|
|
143
|
-
// Global hotkey listener
|
|
144
|
-
binding.addEventListener('hotkey', () => {
|
|
145
|
-
appWindow.restore();
|
|
146
|
-
void intentPlugin?.provides.intent.dispatch({
|
|
147
|
-
action: LayoutAction.SET_LAYOUT,
|
|
148
|
-
data: { element: 'dialog', component: `${NAVTREE_PLUGIN}/Commands` },
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
const initializeNativeApp = async (plugins: Plugin[]) => {
|
|
154
|
-
const { app, socketWindow, appName } = await loadSocketSupplyModules();
|
|
155
|
-
const intentPlugin = resolvePlugin(plugins, parseIntentPlugin);
|
|
156
|
-
|
|
157
|
-
if (process.platform === 'darwin' || process.platform === 'win32') {
|
|
158
|
-
await configureDesktopWindowSizing(app);
|
|
159
|
-
await configureSystemMenu(app, appName);
|
|
160
|
-
setupMenuItemListener(intentPlugin, app);
|
|
161
|
-
setupApplicationUrlListener(app, intentPlugin);
|
|
162
|
-
await setupGlobalHotkey(socketWindow, app, intentPlugin);
|
|
163
|
-
}
|
|
164
|
-
};
|
|
8
|
+
import { meta } from './meta';
|
|
165
9
|
|
|
166
10
|
// TODO(burdon): Initial url has index.html, which must be caught/redirected.
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
11
|
+
|
|
12
|
+
export const NativePlugin = () =>
|
|
13
|
+
definePlugin(meta, [
|
|
14
|
+
defineModule({
|
|
15
|
+
id: `${meta.id}/module/startup`,
|
|
16
|
+
activatesOn: Events.Startup,
|
|
17
|
+
activate: async (context: PluginsContext) => {
|
|
18
|
+
const { initializeNativeApp } = await import('./initialize');
|
|
19
|
+
await initializeNativeApp(context);
|
|
20
|
+
return [];
|
|
21
|
+
},
|
|
22
|
+
}),
|
|
23
|
+
]);
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import type { PluginsContext } from '@dxos/app-framework';
|
|
6
|
+
import { NavigationAction, 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 { meta_title: appName } = app.config;
|
|
27
|
+
|
|
28
|
+
return { app, socketWindow, appName };
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const configureDesktopWindowSizing = async (app: any) => {
|
|
32
|
+
const { width, height } = safeParseJson<{ width?: number; height?: number }>(
|
|
33
|
+
localStorage.getItem(KEY_WINDOW_SIZE),
|
|
34
|
+
{},
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
if (width && height) {
|
|
38
|
+
const appWindow = await app.getCurrentWindow();
|
|
39
|
+
await appWindow.setSize({ width, height });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
window.addEventListener('resize', async () => {
|
|
43
|
+
const appWindow = await app.getCurrentWindow();
|
|
44
|
+
const { width, height } = appWindow.getSize();
|
|
45
|
+
localStorage.setItem(KEY_WINDOW_SIZE, JSON.stringify({ width, height }));
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const configureSystemMenu = async (app: any, appName: string) => {
|
|
50
|
+
const itemsMac = `
|
|
51
|
+
Hide ${appName}: h + CommandOrControl
|
|
52
|
+
Hide Others: h + Control + Meta
|
|
53
|
+
---
|
|
54
|
+
`;
|
|
55
|
+
|
|
56
|
+
// TODO(mjamesderocher) Change menu names to use translations
|
|
57
|
+
const menu = `
|
|
58
|
+
App Name:
|
|
59
|
+
About ${appName}: _
|
|
60
|
+
Settings...: , + CommandOrControl
|
|
61
|
+
---
|
|
62
|
+
Show shortcuts: / + CommandOrControl
|
|
63
|
+
Search commands: k + CommandOrControl
|
|
64
|
+
---
|
|
65
|
+
${itemsMac}
|
|
66
|
+
Quit: q + CommandOrControl
|
|
67
|
+
;
|
|
68
|
+
|
|
69
|
+
Edit:
|
|
70
|
+
Cut: x + CommandOrControl
|
|
71
|
+
Copy: c + CommandOrControl
|
|
72
|
+
Paste: v + CommandOrControl
|
|
73
|
+
Delete: _
|
|
74
|
+
Select All: a + CommandOrControl
|
|
75
|
+
;
|
|
76
|
+
`;
|
|
77
|
+
|
|
78
|
+
void app.setSystemMenu({ index: 0, value: menu });
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const setupMenuItemListener = (dispatch: any, app: any) => {
|
|
82
|
+
window.addEventListener('menuItemSelected', async (event: any) => {
|
|
83
|
+
const id = `${event.detail.parent}:${event.detail.title}`;
|
|
84
|
+
switch (id) {
|
|
85
|
+
case 'App Name:Search commands': {
|
|
86
|
+
void dispatch(
|
|
87
|
+
createIntent(LayoutAction.SetLayout, {
|
|
88
|
+
element: 'dialog',
|
|
89
|
+
component: COMMANDS_DIALOG,
|
|
90
|
+
dialogBlockAlign: 'start',
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case 'App Name:Settings...': {
|
|
96
|
+
void dispatch(createIntent(SettingsAction.Open));
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
case 'App Name:Show shortcuts': {
|
|
100
|
+
void dispatch(
|
|
101
|
+
createIntent(LayoutAction.SetLayout, {
|
|
102
|
+
element: 'dialog',
|
|
103
|
+
component: `${HELP_PLUGIN}/Shortcuts`,
|
|
104
|
+
}),
|
|
105
|
+
);
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
case 'App Name:Quit': {
|
|
109
|
+
await app.exit();
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const setupApplicationUrlListener = (app: any, dispatch: any) => {
|
|
117
|
+
const appWindow = app.getCurrentWindow();
|
|
118
|
+
|
|
119
|
+
// applicationurl is a custom event fired by the Socket Supply Runtime:
|
|
120
|
+
// https://github.com/socketsupply/socket/blob/ef7fb5559876e41062d5896aafb7b79989fc96e5/api/internal/events.js#L6
|
|
121
|
+
window.addEventListener('applicationurl', ({ url }: any) => {
|
|
122
|
+
appWindow.restore();
|
|
123
|
+
const location = url.toString().replace('composer://', '');
|
|
124
|
+
if (location.includes('InvitationCode')) {
|
|
125
|
+
// TODO(mjamesderocher): Integrate this with app routing.
|
|
126
|
+
// Currently, the dialogs are controlled by Client Plugin and not the Layout Plugin.
|
|
127
|
+
window.location.href = location;
|
|
128
|
+
} else {
|
|
129
|
+
void dispatch(
|
|
130
|
+
createIntent(
|
|
131
|
+
NavigationAction.Open,
|
|
132
|
+
// TODO(thure): what is `location` and is this right?
|
|
133
|
+
{ activeParts: { main: [location] } },
|
|
134
|
+
),
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const setupGlobalHotkey = async (socketWindow: any, appWindow: any, dispatch: any) => {
|
|
141
|
+
const binding = await socketWindow.hotkey.bind('cmd + k');
|
|
142
|
+
|
|
143
|
+
// Global hotkey listener
|
|
144
|
+
binding.addEventListener('hotkey', () => {
|
|
145
|
+
appWindow.restore();
|
|
146
|
+
void dispatch(
|
|
147
|
+
createIntent(LayoutAction.SetLayout, {
|
|
148
|
+
element: 'dialog',
|
|
149
|
+
component: COMMANDS_DIALOG,
|
|
150
|
+
dialogBlockAlign: 'start',
|
|
151
|
+
}),
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export const initializeNativeApp = async (context: PluginsContext) => {
|
|
157
|
+
const { app, socketWindow, appName } = await loadSocketSupplyModules();
|
|
158
|
+
const { dispatchPromise: dispatch } = context.requestCapability(Capabilities.IntentDispatcher);
|
|
159
|
+
|
|
160
|
+
if (process.platform === 'darwin' || process.platform === 'win32') {
|
|
161
|
+
await configureDesktopWindowSizing(app);
|
|
162
|
+
await configureSystemMenu(app, appName);
|
|
163
|
+
setupMenuItemListener(dispatch, app);
|
|
164
|
+
setupApplicationUrlListener(app, dispatch);
|
|
165
|
+
await setupGlobalHotkey(socketWindow, app, dispatch);
|
|
166
|
+
}
|
|
167
|
+
};
|
package/src/meta.ts
CHANGED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/meta.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type PluginMeta } from '@dxos/app-framework';\n\nexport default {\n id: 'dxos.org/plugin/native',\n} satisfies PluginMeta;\n"],
|
|
5
|
-
"mappings": ";AAMA,IAAA,eAAe;EACbA,IAAI;AACN;",
|
|
6
|
-
"names": ["id"]
|
|
7
|
-
}
|