@dxos/plugin-native 0.8.4-main.1f223c7 → 0.8.4-main.2244d791bb

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/lib/browser/chunk-6374DBU4.mjs +15 -0
  2. package/dist/lib/browser/chunk-6374DBU4.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +33 -32
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/ollama-QOB3EVAJ.mjs +75 -0
  7. package/dist/lib/browser/ollama-QOB3EVAJ.mjs.map +7 -0
  8. package/dist/lib/browser/updater-AR27PYM4.mjs +190 -0
  9. package/dist/lib/browser/updater-AR27PYM4.mjs.map +7 -0
  10. package/dist/lib/browser/window-WKAABR3P.mjs +38 -0
  11. package/dist/lib/browser/window-WKAABR3P.mjs.map +7 -0
  12. package/dist/types/src/NativePlugin.d.ts +2 -1
  13. package/dist/types/src/NativePlugin.d.ts.map +1 -1
  14. package/dist/types/src/capabilities/index.d.ts +3 -3
  15. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  16. package/dist/types/src/capabilities/ollama/index.d.ts +3 -0
  17. package/dist/types/src/capabilities/ollama/index.d.ts.map +1 -0
  18. package/dist/types/src/capabilities/ollama/ollama.d.ts +7 -0
  19. package/dist/types/src/capabilities/ollama/ollama.d.ts.map +1 -0
  20. package/dist/types/src/capabilities/updater/index.d.ts +3 -0
  21. package/dist/types/src/capabilities/updater/index.d.ts.map +1 -0
  22. package/dist/types/src/capabilities/updater/updater.d.ts +5 -0
  23. package/dist/types/src/capabilities/updater/updater.d.ts.map +1 -0
  24. package/dist/types/src/capabilities/window/index.d.ts +3 -0
  25. package/dist/types/src/capabilities/window/index.d.ts.map +1 -0
  26. package/dist/types/src/capabilities/window/window.d.ts +11 -0
  27. package/dist/types/src/capabilities/window/window.d.ts.map +1 -0
  28. package/dist/types/src/index.d.ts +1 -0
  29. package/dist/types/src/index.d.ts.map +1 -1
  30. package/dist/types/src/meta.d.ts +2 -3
  31. package/dist/types/src/meta.d.ts.map +1 -1
  32. package/dist/types/tsconfig.tsbuildinfo +1 -1
  33. package/package.json +23 -17
  34. package/src/NativePlugin.tsx +21 -24
  35. package/src/capabilities/index.ts +3 -5
  36. package/src/capabilities/ollama/index.ts +7 -0
  37. package/src/capabilities/{ollama.ts → ollama/ollama.ts} +32 -23
  38. package/src/capabilities/updater/index.ts +7 -0
  39. package/src/capabilities/updater/updater.ts +120 -0
  40. package/src/capabilities/window/index.ts +7 -0
  41. package/src/capabilities/window/window.ts +72 -0
  42. package/src/index.ts +1 -0
  43. package/src/meta.ts +8 -5
  44. package/dist/lib/browser/chunk-E2JDGVJI.mjs +0 -12
  45. package/dist/lib/browser/chunk-E2JDGVJI.mjs.map +0 -7
  46. package/dist/lib/browser/ollama-7VZCJLY5.mjs +0 -87
  47. package/dist/lib/browser/ollama-7VZCJLY5.mjs.map +0 -7
  48. package/dist/lib/browser/updater-MNSUJ5ER.mjs +0 -133
  49. package/dist/lib/browser/updater-MNSUJ5ER.mjs.map +0 -7
  50. package/dist/lib/browser/window-5EBHZJJ4.mjs +0 -34
  51. package/dist/lib/browser/window-5EBHZJJ4.mjs.map +0 -7
  52. package/dist/types/src/capabilities/ollama.d.ts +0 -4
  53. package/dist/types/src/capabilities/ollama.d.ts.map +0 -1
  54. package/dist/types/src/capabilities/updater.d.ts +0 -4
  55. package/dist/types/src/capabilities/updater.d.ts.map +0 -1
  56. package/dist/types/src/capabilities/window.d.ts +0 -4
  57. package/dist/types/src/capabilities/window.d.ts.map +0 -1
  58. package/src/capabilities/updater.ts +0 -80
  59. package/src/capabilities/window.ts +0 -49
@@ -1,133 +0,0 @@
1
- import {
2
- NATIVE_PLUGIN
3
- } from "./chunk-E2JDGVJI.mjs";
4
-
5
- // src/capabilities/updater.ts
6
- import { type } from "@tauri-apps/plugin-os";
7
- import { relaunch } from "@tauri-apps/plugin-process";
8
- import { check } from "@tauri-apps/plugin-updater";
9
- import { Duration, Effect, Fiber, Match, Schedule, pipe } from "effect";
10
- import { Capabilities, LayoutAction, contributes, createIntent } from "@dxos/app-framework";
11
- import { log } from "@dxos/log";
12
- var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-native/src/capabilities/updater.ts";
13
- var SUPPORTS_OTA = [
14
- "linux",
15
- "macos",
16
- "windows"
17
- ];
18
- var updater_default = (context) => {
19
- const platform = type();
20
- if (!SUPPORTS_OTA.includes(platform) || window.location.hostname === "localhost") {
21
- return contributes(Capabilities.Null, null);
22
- }
23
- const { dispatch } = context.getCapability(Capabilities.IntentDispatcher);
24
- const action = Effect.gen(function* () {
25
- log.info("checking for updates", void 0, {
26
- F: __dxlog_file,
27
- L: 28,
28
- S: this,
29
- C: (f, a) => f(...a)
30
- });
31
- const update = yield* Effect.tryPromise(() => check());
32
- log.info("checked for updates", {
33
- version: update?.version,
34
- currentVersion: update?.currentVersion
35
- }, {
36
- F: __dxlog_file,
37
- L: 30,
38
- S: this,
39
- C: (f, a) => f(...a)
40
- });
41
- if (update) {
42
- log.info("update available", update, {
43
- F: __dxlog_file,
44
- L: 32,
45
- S: this,
46
- C: (f, a) => f(...a)
47
- });
48
- let downloaded = 0;
49
- let contentLength = 0;
50
- const handleDownload = Match.type().pipe(Match.when({
51
- event: "Started"
52
- }, (event) => {
53
- contentLength = event.data.contentLength ?? 0;
54
- log.info("download started", {
55
- contentLength
56
- }, {
57
- F: __dxlog_file,
58
- L: 39,
59
- S: this,
60
- C: (f, a) => f(...a)
61
- });
62
- }), Match.when({
63
- event: "Progress"
64
- }, (event) => {
65
- downloaded += event.data.chunkLength;
66
- log.verbose("download progress", {
67
- downloaded,
68
- contentLength
69
- }, {
70
- F: __dxlog_file,
71
- L: 43,
72
- S: this,
73
- C: (f, a) => f(...a)
74
- });
75
- }), Match.when({
76
- event: "Finished"
77
- }, () => {
78
- log.info("download completed", void 0, {
79
- F: __dxlog_file,
80
- L: 46,
81
- S: this,
82
- C: (f, a) => f(...a)
83
- });
84
- }), Match.exhaustive);
85
- yield* Effect.tryPromise(() => update.downloadAndInstall(handleDownload));
86
- yield* dispatch(createIntent(LayoutAction.AddToast, {
87
- part: "toast",
88
- subject: {
89
- id: `${NATIVE_PLUGIN}/update-ready`,
90
- title: [
91
- "update ready label",
92
- {
93
- ns: NATIVE_PLUGIN
94
- }
95
- ],
96
- description: [
97
- "update ready description",
98
- {
99
- ns: NATIVE_PLUGIN
100
- }
101
- ],
102
- duration: Infinity,
103
- actionLabel: [
104
- "update label",
105
- {
106
- ns: NATIVE_PLUGIN
107
- }
108
- ],
109
- actionAlt: [
110
- "update alt",
111
- {
112
- ns: NATIVE_PLUGIN
113
- }
114
- ],
115
- onAction: () => relaunch()
116
- }
117
- }));
118
- }
119
- });
120
- const fiber = pipe(
121
- // prettier-ignore
122
- action,
123
- Effect.repeat(Schedule.fixed(Duration.hours(1))),
124
- Effect.runFork
125
- );
126
- return contributes(Capabilities.Null, null, () => {
127
- Effect.runSync(Fiber.interrupt(fiber));
128
- });
129
- };
130
- export {
131
- updater_default as default
132
- };
133
- //# sourceMappingURL=updater-MNSUJ5ER.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/capabilities/updater.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type } from '@tauri-apps/plugin-os';\nimport { relaunch } from '@tauri-apps/plugin-process';\nimport { type DownloadEvent, check } from '@tauri-apps/plugin-updater';\nimport { Duration, Effect, Fiber, Match, Schedule, pipe } from 'effect';\n\nimport { Capabilities, LayoutAction, type PluginContext, contributes, createIntent } from '@dxos/app-framework';\nimport { log } from '@dxos/log';\n\nimport { NATIVE_PLUGIN } from '../meta';\n\nconst SUPPORTS_OTA = ['linux', 'macos', 'windows'];\n\nexport default (context: PluginContext) => {\n // Skip updates if not supported or in dev mode.\n const platform = type();\n if (!SUPPORTS_OTA.includes(platform) || window.location.hostname === 'localhost') {\n return contributes(Capabilities.Null, null);\n }\n\n const { dispatch } = context.getCapability(Capabilities.IntentDispatcher);\n\n // https://tauri.app/plugin/updater/#checking-for-updates\n const action = Effect.gen(function* () {\n log.info('checking for updates');\n const update = yield* Effect.tryPromise(() => check());\n log.info('checked for updates', { version: update?.version, currentVersion: update?.currentVersion });\n if (update) {\n log.info('update available', update);\n let downloaded = 0;\n let contentLength = 0;\n\n const handleDownload = Match.type<DownloadEvent>().pipe(\n Match.when({ event: 'Started' }, (event) => {\n contentLength = event.data.contentLength ?? 0;\n log.info('download started', { contentLength });\n }),\n Match.when({ event: 'Progress' }, (event) => {\n downloaded += event.data.chunkLength;\n log.verbose('download progress', { downloaded, contentLength });\n }),\n Match.when({ event: 'Finished' }, () => {\n log.info('download completed');\n }),\n Match.exhaustive,\n );\n\n yield* Effect.tryPromise(() => update.downloadAndInstall(handleDownload));\n\n yield* dispatch(\n createIntent(LayoutAction.AddToast, {\n part: 'toast',\n subject: {\n id: `${NATIVE_PLUGIN}/update-ready`,\n title: ['update ready label', { ns: NATIVE_PLUGIN }],\n description: ['update ready description', { ns: NATIVE_PLUGIN }],\n duration: Infinity,\n actionLabel: ['update label', { ns: NATIVE_PLUGIN }],\n actionAlt: ['update alt', { ns: NATIVE_PLUGIN }],\n onAction: () => relaunch(),\n },\n }),\n );\n }\n });\n\n const fiber = pipe(\n // prettier-ignore\n action,\n Effect.repeat(Schedule.fixed(Duration.hours(1))),\n Effect.runFork,\n );\n\n return contributes(Capabilities.Null, null, () => {\n Effect.runSync(Fiber.interrupt(fiber));\n });\n};\n"],
5
- "mappings": ";;;;;AAIA,SAASA,YAAY;AACrB,SAASC,gBAAgB;AACzB,SAA6BC,aAAa;AAC1C,SAASC,UAAUC,QAAQC,OAAOC,OAAOC,UAAUC,YAAY;AAE/D,SAASC,cAAcC,cAAkCC,aAAaC,oBAAoB;AAC1F,SAASC,WAAW;;AAIpB,IAAMC,eAAe;EAAC;EAAS;EAAS;;AAExC,IAAA,kBAAe,CAACC,YAAAA;AAEd,QAAMC,WAAWC,KAAAA;AACjB,MAAI,CAACH,aAAaI,SAASF,QAAAA,KAAaG,OAAOC,SAASC,aAAa,aAAa;AAChF,WAAOC,YAAYC,aAAaC,MAAM,IAAA;EACxC;AAEA,QAAM,EAAEC,SAAQ,IAAKV,QAAQW,cAAcH,aAAaI,gBAAgB;AAGxE,QAAMC,SAASC,OAAOC,IAAI,aAAA;AACxBC,QAAIC,KAAK,wBAAA,QAAA;;;;;;AACT,UAAMC,SAAS,OAAOJ,OAAOK,WAAW,MAAMC,MAAAA,CAAAA;AAC9CJ,QAAIC,KAAK,uBAAuB;MAAEI,SAASH,QAAQG;MAASC,gBAAgBJ,QAAQI;IAAe,GAAA;;;;;;AACnG,QAAIJ,QAAQ;AACVF,UAAIC,KAAK,oBAAoBC,QAAAA;;;;;;AAC7B,UAAIK,aAAa;AACjB,UAAIC,gBAAgB;AAEpB,YAAMC,iBAAiBC,MAAMxB,KAAI,EAAkByB,KACjDD,MAAME,KAAK;QAAEC,OAAO;MAAU,GAAG,CAACA,UAAAA;AAChCL,wBAAgBK,MAAMC,KAAKN,iBAAiB;AAC5CR,YAAIC,KAAK,oBAAoB;UAAEO;QAAc,GAAA;;;;;;MAC/C,CAAA,GACAE,MAAME,KAAK;QAAEC,OAAO;MAAW,GAAG,CAACA,UAAAA;AACjCN,sBAAcM,MAAMC,KAAKC;AACzBf,YAAIgB,QAAQ,qBAAqB;UAAET;UAAYC;QAAc,GAAA;;;;;;MAC/D,CAAA,GACAE,MAAME,KAAK;QAAEC,OAAO;MAAW,GAAG,MAAA;AAChCb,YAAIC,KAAK,sBAAA,QAAA;;;;;;MACX,CAAA,GACAS,MAAMO,UAAU;AAGlB,aAAOnB,OAAOK,WAAW,MAAMD,OAAOgB,mBAAmBT,cAAAA,CAAAA;AAEzD,aAAOf,SACLyB,aAAaC,aAAaC,UAAU;QAClCC,MAAM;QACNC,SAAS;UACPC,IAAI,GAAGC,aAAAA;UACPC,OAAO;YAAC;YAAsB;cAAEC,IAAIF;YAAc;;UAClDG,aAAa;YAAC;YAA4B;cAAED,IAAIF;YAAc;;UAC9DI,UAAUC;UACVC,aAAa;YAAC;YAAgB;cAAEJ,IAAIF;YAAc;;UAClDO,WAAW;YAAC;YAAc;cAAEL,IAAIF;YAAc;;UAC9CQ,UAAU,MAAMC,SAAAA;QAClB;MACF,CAAA,CAAA;IAEJ;EACF,CAAA;AAEA,QAAMC,QAAQxB;;IAEZd;IACAC,OAAOsC,OAAOC,SAASC,MAAMC,SAASC,MAAM,CAAA,CAAA,CAAA;IAC5C1C,OAAO2C;EAAO;AAGhB,SAAOlD,YAAYC,aAAaC,MAAM,MAAM,MAAA;AAC1CK,WAAO4C,QAAQC,MAAMC,UAAUT,KAAAA,CAAAA;EACjC,CAAA;AACF;",
6
- "names": ["type", "relaunch", "check", "Duration", "Effect", "Fiber", "Match", "Schedule", "pipe", "Capabilities", "LayoutAction", "contributes", "createIntent", "log", "SUPPORTS_OTA", "context", "platform", "type", "includes", "window", "location", "hostname", "contributes", "Capabilities", "Null", "dispatch", "getCapability", "IntentDispatcher", "action", "Effect", "gen", "log", "info", "update", "tryPromise", "check", "version", "currentVersion", "downloaded", "contentLength", "handleDownload", "Match", "pipe", "when", "event", "data", "chunkLength", "verbose", "exhaustive", "downloadAndInstall", "createIntent", "LayoutAction", "AddToast", "part", "subject", "id", "NATIVE_PLUGIN", "title", "ns", "description", "duration", "Infinity", "actionLabel", "actionAlt", "onAction", "relaunch", "fiber", "repeat", "Schedule", "fixed", "Duration", "hours", "runFork", "runSync", "Fiber", "interrupt"]
7
- }
@@ -1,34 +0,0 @@
1
- // src/capabilities/window.ts
2
- import { LogicalPosition, LogicalSize, getCurrentWindow } from "@tauri-apps/api/window";
3
- import { Capabilities, contributes } from "@dxos/app-framework";
4
- var window_default = (_context) => {
5
- return contributes(Capabilities.Null, null, () => {
6
- const appWindow = getCurrentWindow();
7
- async function saveWindowState() {
8
- const size = await appWindow.innerSize();
9
- const position = await appWindow.innerPosition();
10
- localStorage.setItem("windowState", JSON.stringify({
11
- width: size.width,
12
- height: size.height,
13
- x: position.x,
14
- y: position.y
15
- }));
16
- }
17
- async function restoreWindowState() {
18
- const savedState = localStorage.getItem("windowState");
19
- if (savedState) {
20
- const state = JSON.parse(savedState);
21
- await appWindow.setSize(new LogicalSize(state.width, state.height));
22
- await appWindow.setPosition(new LogicalPosition(state.x, state.y));
23
- }
24
- }
25
- void appWindow.listen("tauri://resize", saveWindowState);
26
- void appWindow.listen("tauri://move", saveWindowState);
27
- document.addEventListener("DOMContentLoaded", restoreWindowState);
28
- window.addEventListener("beforeunload", saveWindowState);
29
- });
30
- };
31
- export {
32
- window_default as default
33
- };
34
- //# sourceMappingURL=window-5EBHZJJ4.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/capabilities/window.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { LogicalPosition, LogicalSize, getCurrentWindow } from '@tauri-apps/api/window';\n\nimport { Capabilities, type PluginContext, contributes } from '@dxos/app-framework';\n\nexport default (_context: PluginContext) => {\n return contributes(Capabilities.Null, null, () => {\n const appWindow = getCurrentWindow();\n\n // Save window state to localStorage.\n async function saveWindowState() {\n const size = await appWindow.innerSize();\n const position = await appWindow.innerPosition();\n localStorage.setItem(\n 'windowState',\n JSON.stringify({\n width: size.width,\n height: size.height,\n x: position.x,\n y: position.y,\n }),\n );\n }\n\n // Restore window state from localStorage.\n async function restoreWindowState() {\n const savedState = localStorage.getItem('windowState');\n if (savedState) {\n const state = JSON.parse(savedState);\n\n await appWindow.setSize(new LogicalSize(state.width, state.height));\n await appWindow.setPosition(new LogicalPosition(state.x, state.y));\n }\n }\n\n // Listen for window events and save state.\n void appWindow.listen('tauri://resize', saveWindowState);\n void appWindow.listen('tauri://move', saveWindowState);\n\n // Restore state when app loads.\n document.addEventListener('DOMContentLoaded', restoreWindowState);\n\n // Save state before closing.\n window.addEventListener('beforeunload', saveWindowState);\n });\n};\n"],
5
- "mappings": ";AAIA,SAASA,iBAAiBC,aAAaC,wBAAwB;AAE/D,SAASC,cAAkCC,mBAAmB;AAE9D,IAAA,iBAAe,CAACC,aAAAA;AACd,SAAOC,YAAYC,aAAaC,MAAM,MAAM,MAAA;AAC1C,UAAMC,YAAYC,iBAAAA;AAGlB,mBAAeC,kBAAAA;AACb,YAAMC,OAAO,MAAMH,UAAUI,UAAS;AACtC,YAAMC,WAAW,MAAML,UAAUM,cAAa;AAC9CC,mBAAaC,QACX,eACAC,KAAKC,UAAU;QACbC,OAAOR,KAAKQ;QACZC,QAAQT,KAAKS;QACbC,GAAGR,SAASQ;QACZC,GAAGT,SAASS;MACd,CAAA,CAAA;IAEJ;AAGA,mBAAeC,qBAAAA;AACb,YAAMC,aAAaT,aAAaU,QAAQ,aAAA;AACxC,UAAID,YAAY;AACd,cAAME,QAAQT,KAAKU,MAAMH,UAAAA;AAEzB,cAAMhB,UAAUoB,QAAQ,IAAIC,YAAYH,MAAMP,OAAOO,MAAMN,MAAM,CAAA;AACjE,cAAMZ,UAAUsB,YAAY,IAAIC,gBAAgBL,MAAML,GAAGK,MAAMJ,CAAC,CAAA;MAClE;IACF;AAGA,SAAKd,UAAUwB,OAAO,kBAAkBtB,eAAAA;AACxC,SAAKF,UAAUwB,OAAO,gBAAgBtB,eAAAA;AAGtCuB,aAASC,iBAAiB,oBAAoBX,kBAAAA;AAG9CY,WAAOD,iBAAiB,gBAAgBxB,eAAAA;EAC1C,CAAA;AACF;",
6
- "names": ["LogicalPosition", "LogicalSize", "getCurrentWindow", "Capabilities", "contributes", "_context", "contributes", "Capabilities", "Null", "appWindow", "getCurrentWindow", "saveWindowState", "size", "innerSize", "position", "innerPosition", "localStorage", "setItem", "JSON", "stringify", "width", "height", "x", "y", "restoreWindowState", "savedState", "getItem", "state", "parse", "setSize", "LogicalSize", "setPosition", "LogicalPosition", "listen", "document", "addEventListener", "window"]
7
- }
@@ -1,4 +0,0 @@
1
- import { type Capability, type PluginContext } from '@dxos/app-framework';
2
- declare const _default: (_context: PluginContext) => Capability<any>;
3
- export default _default;
4
- //# sourceMappingURL=ollama.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ollama.d.ts","sourceRoot":"","sources":["../../../../src/capabilities/ollama.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,aAAa,EAAe,MAAM,qBAAqB,CAAC;yBAOvE,UAAU,aAAa,KAAG,UAAU,CAAC,GAAG,CAAC;AAAzD,wBAeE"}
@@ -1,4 +0,0 @@
1
- import { type PluginContext } from '@dxos/app-framework';
2
- declare const _default: (context: PluginContext) => import("@dxos/app-framework").Capability<import("@dxos/app-framework").InterfaceDef<null>>;
3
- export default _default;
4
- //# sourceMappingURL=updater.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"updater.d.ts","sourceRoot":"","sources":["../../../../src/capabilities/updater.ts"],"names":[],"mappings":"AASA,OAAO,EAA8B,KAAK,aAAa,EAA6B,MAAM,qBAAqB,CAAC;yBAOhG,SAAS,aAAa;AAAtC,wBA+DE"}
@@ -1,4 +0,0 @@
1
- import { type PluginContext } from '@dxos/app-framework';
2
- declare const _default: (_context: PluginContext) => import("@dxos/app-framework").Capability<import("@dxos/app-framework").InterfaceDef<null>>;
3
- export default _default;
4
- //# sourceMappingURL=window.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"window.d.ts","sourceRoot":"","sources":["../../../../src/capabilities/window.ts"],"names":[],"mappings":"AAMA,OAAO,EAAgB,KAAK,aAAa,EAAe,MAAM,qBAAqB,CAAC;yBAEpE,UAAU,aAAa;AAAvC,wBAwCE"}
@@ -1,80 +0,0 @@
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 { type DownloadEvent, check } from '@tauri-apps/plugin-updater';
8
- import { Duration, Effect, Fiber, Match, Schedule, pipe } from 'effect';
9
-
10
- import { Capabilities, LayoutAction, type PluginContext, contributes, createIntent } 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
- // Skip updates if not supported or in dev mode.
19
- const platform = type();
20
- if (!SUPPORTS_OTA.includes(platform) || window.location.hostname === 'localhost') {
21
- return contributes(Capabilities.Null, null);
22
- }
23
-
24
- const { dispatch } = context.getCapability(Capabilities.IntentDispatcher);
25
-
26
- // https://tauri.app/plugin/updater/#checking-for-updates
27
- const action = Effect.gen(function* () {
28
- log.info('checking for updates');
29
- const update = yield* Effect.tryPromise(() => check());
30
- log.info('checked for updates', { version: update?.version, currentVersion: update?.currentVersion });
31
- if (update) {
32
- log.info('update available', update);
33
- let downloaded = 0;
34
- let contentLength = 0;
35
-
36
- const handleDownload = Match.type<DownloadEvent>().pipe(
37
- Match.when({ event: 'Started' }, (event) => {
38
- contentLength = event.data.contentLength ?? 0;
39
- log.info('download started', { contentLength });
40
- }),
41
- Match.when({ event: 'Progress' }, (event) => {
42
- downloaded += event.data.chunkLength;
43
- log.verbose('download progress', { downloaded, contentLength });
44
- }),
45
- Match.when({ event: 'Finished' }, () => {
46
- log.info('download completed');
47
- }),
48
- Match.exhaustive,
49
- );
50
-
51
- yield* Effect.tryPromise(() => update.downloadAndInstall(handleDownload));
52
-
53
- yield* dispatch(
54
- createIntent(LayoutAction.AddToast, {
55
- part: 'toast',
56
- subject: {
57
- id: `${NATIVE_PLUGIN}/update-ready`,
58
- title: ['update ready label', { ns: NATIVE_PLUGIN }],
59
- description: ['update ready description', { ns: NATIVE_PLUGIN }],
60
- duration: Infinity,
61
- actionLabel: ['update label', { ns: NATIVE_PLUGIN }],
62
- actionAlt: ['update alt', { ns: NATIVE_PLUGIN }],
63
- onAction: () => relaunch(),
64
- },
65
- }),
66
- );
67
- }
68
- });
69
-
70
- const fiber = pipe(
71
- // prettier-ignore
72
- action,
73
- Effect.repeat(Schedule.fixed(Duration.hours(1))),
74
- Effect.runFork,
75
- );
76
-
77
- return contributes(Capabilities.Null, null, () => {
78
- Effect.runSync(Fiber.interrupt(fiber));
79
- });
80
- };
@@ -1,49 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { LogicalPosition, LogicalSize, getCurrentWindow } from '@tauri-apps/api/window';
6
-
7
- import { Capabilities, type PluginContext, contributes } from '@dxos/app-framework';
8
-
9
- export default (_context: PluginContext) => {
10
- return contributes(Capabilities.Null, null, () => {
11
- const appWindow = getCurrentWindow();
12
-
13
- // Save window state to localStorage.
14
- async function saveWindowState() {
15
- const size = await appWindow.innerSize();
16
- const position = await appWindow.innerPosition();
17
- localStorage.setItem(
18
- 'windowState',
19
- JSON.stringify({
20
- width: size.width,
21
- height: size.height,
22
- x: position.x,
23
- y: position.y,
24
- }),
25
- );
26
- }
27
-
28
- // Restore window state from localStorage.
29
- async function restoreWindowState() {
30
- const savedState = localStorage.getItem('windowState');
31
- if (savedState) {
32
- const state = JSON.parse(savedState);
33
-
34
- await appWindow.setSize(new LogicalSize(state.width, state.height));
35
- await appWindow.setPosition(new LogicalPosition(state.x, state.y));
36
- }
37
- }
38
-
39
- // Listen for window events and save state.
40
- void appWindow.listen('tauri://resize', saveWindowState);
41
- void appWindow.listen('tauri://move', saveWindowState);
42
-
43
- // Restore state when app loads.
44
- document.addEventListener('DOMContentLoaded', restoreWindowState);
45
-
46
- // Save state before closing.
47
- window.addEventListener('beforeunload', saveWindowState);
48
- });
49
- };