@dxos/plugin-native 0.6.8-main.046e6cf
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 +8 -0
- package/README.md +15 -0
- package/dist/lib/browser/chunk-GCPLQCSM.mjs +9 -0
- package/dist/lib/browser/chunk-GCPLQCSM.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +174 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/browser/meta.mjs +7 -0
- package/dist/lib/browser/meta.mjs.map +7 -0
- package/dist/types/src/NativePlugin.d.ts +3 -0
- package/dist/types/src/NativePlugin.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/meta.d.ts +5 -0
- package/dist/types/src/meta.d.ts.map +1 -0
- package/package.json +44 -0
- package/src/NativePlugin.tsx +172 -0
- package/src/index.ts +9 -0
- package/src/meta.ts +7 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
Copyright (c) 2022 DXOS
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @dxos/plugin-native
|
|
2
|
+
|
|
3
|
+
Composer plugin that runs when being used by the Socket Supply Co. runtime on a native device.
|
|
4
|
+
|
|
5
|
+
## DXOS Resources
|
|
6
|
+
|
|
7
|
+
- [Website](https://dxos.org)
|
|
8
|
+
- [Developer Documentation](https://docs.dxos.org)
|
|
9
|
+
- Talk to us on [Discord](https://dxos.org/discord)
|
|
10
|
+
|
|
11
|
+
## Contributions
|
|
12
|
+
|
|
13
|
+
Your ideas, issues, and code are most welcome. Please take a look at our [community code of conduct](https://github.com/dxos/dxos/blob/main/CODE_OF_CONDUCT.md), the [issue guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-issues), and the [PR contribution guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-prs).
|
|
14
|
+
|
|
15
|
+
License: [MIT](./LICENSE) Copyright 2023 © DXOS
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import {
|
|
2
|
+
meta_default
|
|
3
|
+
} from "./chunk-GCPLQCSM.mjs";
|
|
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
|
+
});
|
|
46
|
+
};
|
|
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
|
+
|
|
65
|
+
Edit:
|
|
66
|
+
Cut: x + CommandOrControl
|
|
67
|
+
Copy: c + CommandOrControl
|
|
68
|
+
Paste: v + CommandOrControl
|
|
69
|
+
Delete: _
|
|
70
|
+
Select All: a + CommandOrControl
|
|
71
|
+
;
|
|
72
|
+
`;
|
|
73
|
+
void app.setSystemMenu({
|
|
74
|
+
index: 0,
|
|
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
|
+
});
|
|
134
|
+
}
|
|
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;
|
|
170
|
+
export {
|
|
171
|
+
NativePlugin,
|
|
172
|
+
src_default as default
|
|
173
|
+
};
|
|
174
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/NativePlugin.tsx", "../../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport type { Plugin, PluginDefinition } from '@dxos/app-framework';\nimport { NavigationAction, SettingsAction, LayoutAction, parseIntentPlugin, resolvePlugin } from '@dxos/app-framework';\nimport { HELP_PLUGIN } from '@dxos/plugin-help/meta';\nimport { NAVTREE_PLUGIN } from '@dxos/plugin-navtree/meta';\nimport { safeParseJson } from '@dxos/util';\n\nimport meta from './meta';\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 = (intentPlugin: 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 intentPlugin?.provides.intent.dispatch({\n action: LayoutAction.SET_LAYOUT,\n data: { element: 'dialog', component: `${NAVTREE_PLUGIN}/Commands` },\n });\n break;\n }\n case 'App Name:Settings...': {\n void intentPlugin?.provides.intent.dispatch({\n action: SettingsAction.OPEN,\n });\n break;\n }\n case 'App Name:Show shortcuts': {\n void intentPlugin?.provides.intent.dispatch({\n action: LayoutAction.SET_LAYOUT,\n data: {\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, intentPlugin: 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 intentPlugin?.provides.intent.dispatch({\n action: NavigationAction.OPEN,\n // TODO(thure): what is `location` and is this right?\n data: { activeParts: { main: [location] } },\n });\n }\n });\n};\n\nconst setupGlobalHotkey = async (socketWindow: any, appWindow: any, intentPlugin: any) => {\n const binding = await socketWindow.hotkey.bind('cmd + k');\n\n // Global hotkey listener\n binding.addEventListener('hotkey', () => {\n appWindow.restore();\n void intentPlugin?.provides.intent.dispatch({\n action: LayoutAction.SET_LAYOUT,\n data: { element: 'dialog', component: `${NAVTREE_PLUGIN}/Commands` },\n });\n });\n};\n\nconst initializeNativeApp = async (plugins: Plugin[]) => {\n const { app, socketWindow, appName } = await loadSocketSupplyModules();\n const intentPlugin = resolvePlugin(plugins, parseIntentPlugin);\n\n if (process.platform === 'darwin' || process.platform === 'win32') {\n await configureDesktopWindowSizing(app);\n await configureSystemMenu(app, appName);\n setupMenuItemListener(intentPlugin, app);\n setupApplicationUrlListener(app, intentPlugin);\n await setupGlobalHotkey(socketWindow, app, intentPlugin);\n }\n};\n\n// TODO(burdon): Initial url has index.html, which must be caught/redirected.\nexport const NativePlugin = (): PluginDefinition => ({\n meta,\n ready: async (plugins) => {\n await initializeNativeApp(plugins);\n },\n});\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { NativePlugin } from './NativePlugin';\n\nexport default NativePlugin;\n\nexport * from './NativePlugin';\n"],
|
|
5
|
+
"mappings": ";;;;;AAKA,SAASA,kBAAkBC,gBAAgBC,cAAcC,mBAAmBC,qBAAqB;AACjG,SAASC,mBAAmB;AAC5B,SAASC,sBAAsB;AAC/B,SAASC,qBAAqB;AAK9B,IAAMC,kBAAkB;AAQxB,IAAMC,0BAA0B,YAAA;AAE9B,QAAMC,SAAS;AACf,QAAMC,MAAM,MAAM;;IAA0BD;;AAC5C,QAAME,eAAe;AACrB,QAAMC,eAAe,MAAM;;IAA0BD;;AACrD,QAAM,EAAEE,YAAYC,QAAO,IAAKJ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AQC,aAAa,YAAYD,QAAQC,aAAa,SAAS;AACjE,UAAM9D,6BAA6BN,GAAAA;AACnC,UAAMqB,oBAAoBrB,KAAKI,OAAAA;AAC/BuB,0BAAsBC,cAAc5B,GAAAA;AACpCgD,gCAA4BhD,KAAK4B,YAAAA;AACjC,UAAM+B,kBAAkBzD,cAAcF,KAAK4B,YAAAA;EAC7C;AACF;AAGO,IAAMyC,eAAe,OAAyB;EACnDC;EACAC,OAAO,OAAOP,YAAAA;AACZ,UAAMD,oBAAoBC,OAAAA;EAC5B;AACF;;;ACrKA,IAAA,cAAeQ;",
|
|
6
|
+
"names": ["NavigationAction", "SettingsAction", "LayoutAction", "parseIntentPlugin", "resolvePlugin", "HELP_PLUGIN", "NAVTREE_PLUGIN", "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", "intentPlugin", "event", "id", "detail", "parent", "title", "provides", "intent", "dispatch", "action", "LayoutAction", "SET_LAYOUT", "data", "element", "component", "NAVTREE_PLUGIN", "SettingsAction", "OPEN", "HELP_PLUGIN", "exit", "setupApplicationUrlListener", "url", "restore", "location", "toString", "replace", "includes", "href", "NavigationAction", "activeParts", "main", "setupGlobalHotkey", "binding", "hotkey", "bind", "initializeNativeApp", "plugins", "resolvePlugin", "parseIntentPlugin", "process", "platform", "NativePlugin", "meta", "ready", "NativePlugin"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"packages/plugins/experimental/plugin-native/src/meta.ts":{"bytes":603,"imports":[],"format":"esm"},"packages/plugins/experimental/plugin-native/src/NativePlugin.tsx":{"bytes":19687,"imports":[{"path":"@dxos/app-framework","kind":"import-statement","external":true},{"path":"@dxos/plugin-help/meta","kind":"import-statement","external":true},{"path":"@dxos/plugin-navtree/meta","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/plugins/experimental/plugin-native/src/meta.ts","kind":"import-statement","original":"./meta"}],"format":"esm"},"packages/plugins/experimental/plugin-native/src/index.ts":{"bytes":795,"imports":[{"path":"packages/plugins/experimental/plugin-native/src/NativePlugin.tsx","kind":"import-statement","original":"./NativePlugin"},{"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":9847},"packages/plugins/experimental/plugin-native/dist/lib/browser/index.mjs":{"imports":[{"path":"packages/plugins/experimental/plugin-native/dist/lib/browser/chunk-GCPLQCSM.mjs","kind":"import-statement"},{"path":"@dxos/app-framework","kind":"import-statement","external":true},{"path":"@dxos/plugin-help/meta","kind":"import-statement","external":true},{"path":"@dxos/plugin-navtree/meta","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["NativePlugin","default"],"entryPoint":"packages/plugins/experimental/plugin-native/src/index.ts","inputs":{"packages/plugins/experimental/plugin-native/src/NativePlugin.tsx":{"bytesInOutput":4680},"packages/plugins/experimental/plugin-native/src/index.ts":{"bytesInOutput":32}},"bytes":4985},"packages/plugins/experimental/plugin-native/dist/lib/browser/meta.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"packages/plugins/experimental/plugin-native/dist/lib/browser/meta.mjs":{"imports":[{"path":"packages/plugins/experimental/plugin-native/dist/lib/browser/chunk-GCPLQCSM.mjs","kind":"import-statement"}],"exports":["default"],"entryPoint":"packages/plugins/experimental/plugin-native/src/meta.ts","inputs":{},"bytes":127},"packages/plugins/experimental/plugin-native/dist/lib/browser/chunk-GCPLQCSM.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":246},"packages/plugins/experimental/plugin-native/dist/lib/browser/chunk-GCPLQCSM.mjs":{"imports":[],"exports":["meta_default"],"inputs":{"packages/plugins/experimental/plugin-native/src/meta.ts":{"bytesInOutput":55}},"bytes":186}}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativePlugin.d.ts","sourceRoot":"","sources":["../../../src/NativePlugin.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAU,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAkKpE,eAAO,MAAM,YAAY,QAAO,gBAK9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,eAAe,YAAY,CAAC;AAE5B,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../../src/meta.ts"],"names":[],"mappings":";;;AAIA,wBAEE"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dxos/plugin-native",
|
|
3
|
+
"version": "0.6.8-main.046e6cf",
|
|
4
|
+
"description": "Composer plugin that runs when on a native device.",
|
|
5
|
+
"homepage": "https://dxos.org",
|
|
6
|
+
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "DXOS.org",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"browser": "./dist/lib/browser/index.mjs",
|
|
12
|
+
"types": "./dist/types/src/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./meta": {
|
|
15
|
+
"browser": "./dist/lib/browser/meta.mjs",
|
|
16
|
+
"types": "./dist/types/src/meta.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"types": "dist/types/src/index.d.ts",
|
|
20
|
+
"typesVersions": {
|
|
21
|
+
"*": {
|
|
22
|
+
"meta": [
|
|
23
|
+
"dist/types/src/meta.d.ts"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"src"
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@dxos/app-framework": "0.6.8-main.046e6cf",
|
|
33
|
+
"@dxos/log": "0.6.8-main.046e6cf",
|
|
34
|
+
"@dxos/plugin-help": "0.6.8-main.046e6cf",
|
|
35
|
+
"@dxos/util": "0.6.8-main.046e6cf",
|
|
36
|
+
"@dxos/plugin-navtree": "0.6.8-main.046e6cf"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"vite": "^5.3.4"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import type { Plugin, PluginDefinition } from '@dxos/app-framework';
|
|
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
|
+
|
|
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
|
+
};
|
|
165
|
+
|
|
166
|
+
// TODO(burdon): Initial url has index.html, which must be caught/redirected.
|
|
167
|
+
export const NativePlugin = (): PluginDefinition => ({
|
|
168
|
+
meta,
|
|
169
|
+
ready: async (plugins) => {
|
|
170
|
+
await initializeNativeApp(plugins);
|
|
171
|
+
},
|
|
172
|
+
});
|
package/src/index.ts
ADDED