@widget-js/core 0.1.29 → 0.5.5

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 (70) hide show
  1. package/dist/cjs/api/AppApi.js +25 -23
  2. package/dist/cjs/api/BaseApi.js +13 -0
  3. package/dist/cjs/api/BroadcastApi.js +14 -13
  4. package/dist/cjs/api/BrowserWindowApi.js +58 -63
  5. package/dist/cjs/api/Channel.js +3 -4
  6. package/dist/cjs/api/ClipboardApi.js +16 -11
  7. package/dist/cjs/api/DeviceApi.js +16 -7
  8. package/dist/cjs/api/DialogApi.js +8 -6
  9. package/dist/cjs/api/HostedWidgetApi.js +24 -36
  10. package/dist/cjs/api/LogApi.js +14 -10
  11. package/dist/cjs/api/NotificationApi.js +44 -70
  12. package/dist/cjs/api/ShortcutApi.js +23 -0
  13. package/dist/cjs/api/WidgetApi.js +46 -39
  14. package/dist/cjs/index.js +2 -1
  15. package/dist/cjs/lang/LanguageCode.js +34 -0
  16. package/dist/cjs/model/Widget.js +4 -4
  17. package/dist/cjs/model/WidgetPackage.js +49 -2
  18. package/dist/cjs/model/event/BroadcastEvent.js +4 -8
  19. package/dist/cjs/model/msic/graphics.js +2 -0
  20. package/dist/cjs/repository/WidgetDataRepository.js +11 -5
  21. package/dist/cjs/utils/ElectronUtils.js +5 -1
  22. package/dist/cjs/utils/LanguageUtils.js +38 -0
  23. package/dist/esm/api/AppApi.js +24 -22
  24. package/dist/esm/api/BaseApi.js +9 -0
  25. package/dist/esm/api/BroadcastApi.js +13 -12
  26. package/dist/esm/api/BrowserWindowApi.js +56 -62
  27. package/dist/esm/api/Channel.js +3 -4
  28. package/dist/esm/api/ClipboardApi.js +15 -10
  29. package/dist/esm/api/DeviceApi.js +15 -6
  30. package/dist/esm/api/DialogApi.js +9 -6
  31. package/dist/esm/api/HostedWidgetApi.js +23 -35
  32. package/dist/esm/api/LogApi.js +15 -10
  33. package/dist/esm/api/NotificationApi.js +45 -70
  34. package/dist/esm/api/ShortcutApi.js +19 -0
  35. package/dist/esm/api/WidgetApi.js +45 -38
  36. package/dist/esm/index.js +2 -1
  37. package/dist/esm/lang/LanguageCode.js +33 -0
  38. package/dist/esm/model/Widget.js +4 -4
  39. package/dist/esm/model/WidgetPackage.js +49 -2
  40. package/dist/esm/model/event/BroadcastEvent.js +4 -8
  41. package/dist/esm/model/msic/graphics.js +1 -0
  42. package/dist/esm/repository/WidgetDataRepository.js +11 -5
  43. package/dist/esm/utils/ElectronUtils.js +5 -1
  44. package/dist/esm/utils/LanguageUtils.js +34 -0
  45. package/dist/types/api/AppApi.d.ts +23 -11
  46. package/dist/types/api/BaseApi.d.ts +5 -0
  47. package/dist/types/api/BroadcastApi.d.ts +19 -4
  48. package/dist/types/api/BrowserWindowApi.d.ts +56 -46
  49. package/dist/types/api/Channel.d.ts +4 -5
  50. package/dist/types/api/ClipboardApi.d.ts +9 -5
  51. package/dist/types/api/DeviceApi.d.ts +16 -7
  52. package/dist/types/api/DialogApi.d.ts +5 -7
  53. package/dist/types/api/HostedWidgetApi.d.ts +24 -18
  54. package/dist/types/api/LogApi.d.ts +8 -5
  55. package/dist/types/api/NotificationApi.d.ts +21 -16
  56. package/dist/types/api/ShortcutApi.d.ts +10 -0
  57. package/dist/types/api/WidgetApi.d.ts +39 -20
  58. package/dist/types/index.d.ts +2 -1
  59. package/dist/types/lang/LanguageCode.d.ts +40 -0
  60. package/dist/types/model/Widget.d.ts +7 -9
  61. package/dist/types/model/WidgetPackage.d.ts +55 -12
  62. package/dist/types/model/event/BroadcastEvent.d.ts +14 -10
  63. package/dist/types/model/msic/graphics.d.ts +8 -0
  64. package/dist/types/utils/ElectronUtils.d.ts +2 -1
  65. package/dist/types/utils/LanguageUtils.d.ts +8 -0
  66. package/dist/umd/index.js +1 -1
  67. package/package.json +15 -15
  68. package/dist/cjs/api/GlobalShortcutApi.js +0 -29
  69. package/dist/esm/api/GlobalShortcutApi.js +0 -25
  70. package/dist/types/api/GlobalShortcutApi.d.ts +0 -14
@@ -1,16 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AppApi = void 0;
4
- const ElectronUtils_1 = require("../utils/ElectronUtils");
3
+ exports.AppApiEvent = exports.AppApi = void 0;
5
4
  const Channel_1 = require("./Channel");
6
- class AppApi {
7
- static async setConfig(key, value) {
8
- var _a;
9
- await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.APP, this.SET_CONFIG, key, value));
5
+ const BaseApi_1 = require("./BaseApi");
6
+ var AppApiEvent;
7
+ (function (AppApiEvent) {
8
+ AppApiEvent["CONFIG_CHANGED"] = "event::cn.widgetjs.core.app.config.changed";
9
+ })(AppApiEvent || (AppApiEvent = {}));
10
+ exports.AppApiEvent = AppApiEvent;
11
+ class AppApiImpl extends BaseApi_1.BaseApi {
12
+ getChannel() {
13
+ return Channel_1.Channel.APP;
10
14
  }
11
- static async getConfig(key, defaultValue) {
12
- var _a;
13
- const value = await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.APP, this.GET_CONFIG, key));
15
+ async setConfig(key, value) {
16
+ return await this.invokeMethod('setConfig', key, value);
17
+ }
18
+ async getConfig(key, defaultValue) {
19
+ const value = await this.invokeMethod("getConfig", key);
14
20
  if (value === null || value === undefined) {
15
21
  return defaultValue;
16
22
  }
@@ -22,25 +28,21 @@ class AppApi {
22
28
  }
23
29
  return value;
24
30
  }
25
- static openAddWidgetWindow() {
26
- var _a;
27
- (_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.APP, this.OPEN_ADD_WIDGET_WINDOW);
31
+ async openAddWidgetWindow() {
32
+ return this.invokeMethod('openAddWidgetWindow');
28
33
  }
29
34
  /**
30
35
  * 获取应用版本号,格式为 x.y.z
31
36
  */
32
- static async getVersion() {
33
- var _a;
34
- return (_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.APP, this.GET_VERSION);
37
+ async getVersion() {
38
+ return this.invokeMethod('getVersion');
39
+ }
40
+ async getPreloadPath() {
41
+ return this.invokeMethod('getPreloadPath');
35
42
  }
36
- static openSettingWindow() {
37
- var _a;
38
- (_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.APP, this.OPEN_SETTING_WINDOW);
43
+ async openSettingWindow() {
44
+ return this.invokeMethod('openSettingWindow');
39
45
  }
40
46
  }
47
+ const AppApi = new AppApiImpl();
41
48
  exports.AppApi = AppApi;
42
- AppApi.SET_CONFIG = "SET_CONFIG";
43
- AppApi.GET_CONFIG = "GET_CONFIG";
44
- AppApi.OPEN_ADD_WIDGET_WINDOW = "open-add-widget-window";
45
- AppApi.OPEN_SETTING_WINDOW = "open-setting-window";
46
- AppApi.GET_VERSION = "get-version";
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseApi = void 0;
4
+ const ElectronUtils_1 = require("../utils/ElectronUtils");
5
+ class BaseApi {
6
+ async invokeMethod(method, ...args) {
7
+ return await ElectronUtils_1.ElectronUtils.invokeMethod(this.getChannel(), method, ...args);
8
+ }
9
+ async invoke(...args) {
10
+ return await ElectronUtils_1.ElectronUtils.invoke(this.getChannel(), ...args);
11
+ }
12
+ }
13
+ exports.BaseApi = BaseApi;
@@ -1,21 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BroadcastApi = void 0;
4
- const ElectronUtils_1 = require("../utils/ElectronUtils");
3
+ exports.BroadcastApi = exports.BroadcastApiImpl = void 0;
5
4
  const Channel_1 = require("./Channel");
6
- const ElectronApi_1 = require("./ElectronApi");
7
- class BroadcastApi {
8
- static async sendBroadcastEvent(event) {
9
- var _a;
10
- await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROADCAST, JSON.stringify(event)));
5
+ const BaseApi_1 = require("./BaseApi");
6
+ class BroadcastApiImpl extends BaseApi_1.BaseApi {
7
+ async send(event) {
8
+ await this.invokeMethod('send', event);
11
9
  }
12
- static async registerBroadcast(callback) {
13
- await ElectronApi_1.ElectronApi.addIpcListener(Channel_1.Channel.BROADCAST, (json) => {
14
- callback(JSON.parse(json));
15
- });
10
+ async register(...event) {
11
+ await this.invokeMethod('register', event);
16
12
  }
17
- static async unregisterBroadcast() {
18
- await ElectronApi_1.ElectronApi.removeIpcListener(Channel_1.Channel.BROADCAST);
13
+ async unregister(...event) {
14
+ await this.invokeMethod('unregister', event);
15
+ }
16
+ getChannel() {
17
+ return Channel_1.Channel.BROADCAST;
19
18
  }
20
19
  }
20
+ exports.BroadcastApiImpl = BroadcastApiImpl;
21
+ const BroadcastApi = new BroadcastApiImpl();
21
22
  exports.BroadcastApi = BroadcastApi;
@@ -1,42 +1,47 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BrowserWindowApi = void 0;
3
+ exports.BrowserWindowApiEvent = exports.BrowserWindowApi = exports.BrowserWindowApiImpl = void 0;
4
4
  const Channel_1 = require("./Channel");
5
- const ElectronUtils_1 = require("../utils/ElectronUtils");
6
- class BrowserWindowApi {
7
- static async setIgnoreMouseEvent(ignore) {
8
- await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.IGNORE_MOUSE_EVENT, ignore);
5
+ const BaseApi_1 = require("./BaseApi");
6
+ var BrowserWindowApiEvent;
7
+ (function (BrowserWindowApiEvent) {
8
+ BrowserWindowApiEvent["BLUR"] = "event::cn.widgetjs.core.browser-window.blur";
9
+ BrowserWindowApiEvent["FOCUS"] = "event::cn.widgetjs.core.browser-window.focus";
10
+ })(BrowserWindowApiEvent || (BrowserWindowApiEvent = {}));
11
+ exports.BrowserWindowApiEvent = BrowserWindowApiEvent;
12
+ class BrowserWindowApiImpl extends BaseApi_1.BaseApi {
13
+ getChannel() {
14
+ return Channel_1.Channel.BROWSER_WINDOW;
9
15
  }
10
- static async show() {
11
- await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.WINDOW_VISIBILITY, true);
16
+ async setIgnoreMouseEvent(ignore) {
17
+ await this.invokeMethod('setIgnoreMouseEvent', ignore);
12
18
  }
13
- static async hide() {
14
- await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.WINDOW_VISIBILITY, false);
19
+ async show() {
20
+ await this.invokeMethod('show', true);
15
21
  }
16
- static async center() {
17
- await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.CENTER, false);
22
+ async showInactive() {
23
+ await this.invokeMethod('showInactive', true);
18
24
  }
19
- /**
20
- * @deprecated
21
- * @param show
22
- */
23
- static async setWindowVisibility(show) {
24
- await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.WINDOW_VISIBILITY, show);
25
+ async hide() {
26
+ await this.invokeMethod('hide', false);
27
+ }
28
+ async center() {
29
+ await this.invokeMethod('center', false);
25
30
  }
26
- static async setAlwaysOnTop(alwaysOnTop) {
27
- await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.ALWAYS_ON_TOP, alwaysOnTop);
31
+ async setAlwaysOnTop(alwaysOnTop) {
32
+ await this.invokeMethod('setAlwaysOnTop', alwaysOnTop);
28
33
  }
29
- static async isAlwaysOnTop() {
30
- return await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.IS_ALWAYS_ON_TOP);
34
+ async isAlwaysOnTop() {
35
+ return await this.invokeMethod('isAlwaysOnTop');
31
36
  }
32
- static async openUrl(url) {
33
- await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.OPEN_URL, url);
37
+ async openUrl(url) {
38
+ await this.invokeMethod('openUrl', url);
34
39
  }
35
- static async moveTop() {
36
- await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.MOVE_TOP);
40
+ async moveTop() {
41
+ await this.invokeMethod('moveTop');
37
42
  }
38
- static async openDevTools() {
39
- await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.OPEN_DEV_TOOLS);
43
+ async openDevTools() {
44
+ await this.invokeMethod('openDevTools');
40
45
  }
41
46
  /**
42
47
  * 设置窗口位置
@@ -44,58 +49,48 @@ class BrowserWindowApi {
44
49
  * @param y
45
50
  * @param animation 动画只在mac系统有效
46
51
  */
47
- static async setPosition(x, y, animation) {
48
- await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.SET_POSITION, x, y, animation);
52
+ async setPosition(x, y, animation) {
53
+ await this.invokeMethod('setPosition', x, y, animation);
49
54
  }
50
- static async getPosition() {
51
- return await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.GET_POSITION);
55
+ async getPosition() {
56
+ return await this.invokeMethod('getPosition');
52
57
  }
53
- static async blur() {
54
- return await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.BLUR);
58
+ async blur() {
59
+ return await this.invokeMethod('blur');
55
60
  }
56
- static async focus() {
57
- return await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.FOCUS);
61
+ async focus() {
62
+ return await this.invokeMethod('focus');
58
63
  }
59
64
  /**
60
65
  * 设置窗口是否可以拉伸
61
66
  * @param resizable
62
67
  */
63
- static async setResizable(resizable) {
64
- return await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.SET_RESIZABLE, resizable);
68
+ async setResizable(resizable) {
69
+ return await this.invokeMethod('setResizable', resizable);
70
+ }
71
+ async getBounds() {
72
+ return await this.invokeMethod('getBounds');
73
+ }
74
+ async setBounds(bounds, animate) {
75
+ return await this.invokeMethod("setBounds", bounds, animate);
65
76
  }
66
- static async getBounds() {
67
- return await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.GET_BOUNDS);
77
+ async alignToScreen(align) {
78
+ return await this.invokeMethod('alignToScreen', align);
68
79
  }
69
- static async setBounds(bounds, animate) {
70
- return await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.SET_BOUNDS, bounds, animate);
80
+ async startDraggingWindow() {
81
+ return await this.invokeMethod('startDraggingWindow');
71
82
  }
72
- static async alignToScreen(align) {
73
- return await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.ALIGN_TO_SCREEN, align);
83
+ async stopDraggingWindow() {
84
+ return await this.invokeMethod('stopDraggingWindow');
74
85
  }
75
86
  /**
76
87
  * 通过url检测窗口是否存在
77
88
  * @param url
78
89
  */
79
- static async existsByUrl(url) {
80
- return await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.EXISTS_BY_URL, url);
90
+ async existsByUrl(url) {
91
+ return await this.invokeMethod('existsByUrl', url);
81
92
  }
82
93
  }
94
+ exports.BrowserWindowApiImpl = BrowserWindowApiImpl;
95
+ const BrowserWindowApi = new BrowserWindowApiImpl();
83
96
  exports.BrowserWindowApi = BrowserWindowApi;
84
- BrowserWindowApi.IGNORE_MOUSE_EVENT = "ignore-mouse-event";
85
- BrowserWindowApi.WINDOW_VISIBILITY = "window-visibility";
86
- BrowserWindowApi.CENTER = "center";
87
- BrowserWindowApi.ALWAYS_ON_TOP = "always-on-top";
88
- BrowserWindowApi.IS_ALWAYS_ON_TOP = "is-always-on-top";
89
- BrowserWindowApi.OPEN_URL = "open-url";
90
- BrowserWindowApi.MOVE_TOP = "move-top";
91
- BrowserWindowApi.OPEN_DEV_TOOLS = "open-dev-tools";
92
- BrowserWindowApi.SET_POSITION = "set-position";
93
- BrowserWindowApi.GET_POSITION = "get-position";
94
- BrowserWindowApi.BLUR = "blur";
95
- BrowserWindowApi.FOCUS = "focus";
96
- BrowserWindowApi.SET_RESIZABLE = "set-resizable";
97
- BrowserWindowApi.GET_BOUNDS = "get-bounds";
98
- BrowserWindowApi.SET_BOUNDS = "set-bounds";
99
- BrowserWindowApi.ALIGN_TO_SCREEN = "align-to-screen";
100
- BrowserWindowApi.EXISTS_BY_URL = "exists-by-url";
101
- BrowserWindowApi.SHOW = "show";
@@ -9,13 +9,12 @@ var Channel;
9
9
  Channel["WIDGET"] = "channel::cn.widgetjs.core.widget";
10
10
  Channel["HOSTED_WIDGET"] = "channel::cn.widgetjs.core.hosted_widget";
11
11
  Channel["APP"] = "channel::cn.widgetjs.core.app";
12
- Channel["MOUSE_EVENT"] = "channel::cn.widgetjs.core.mouse_event";
13
- Channel["KEYBOARD_EVENT"] = "channel::cn.widgetjs.core.keyboard_event";
14
12
  Channel["DIALOG"] = "channel::cn.widgetjs.core.dialog";
15
13
  Channel["CLIPBOARD"] = "channel::cn.widgetjs.core.clipboard";
16
- Channel["DEVICE"] = "channel::cn.widgetjs.core.device";
17
- Channel["KEYBOARD"] = "channel::cn.widgetjs.core.keyboard";
18
14
  Channel["SCREEN"] = "channel::cn.widgetjs.core.screen";
19
15
  Channel["SHORTCUT"] = "channel::cn.widgetjs.core.shortcut";
20
16
  Channel["LOG"] = "channel::cn.widgetjs.core.log";
17
+ Channel["DEVICE"] = "channel::cn.widgetjs.core.device";
18
+ Channel["MOUSE"] = "channel::cn.widgetjs.core.mouse";
19
+ Channel["KEYBOARD"] = "channel::cn.widgetjs.core.keyboard";
21
20
  })(Channel = exports.Channel || (exports.Channel = {}));
@@ -1,18 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClipboardApi = void 0;
4
- const ElectronUtils_1 = require("../utils/ElectronUtils");
3
+ exports.ClipboardApiEvent = exports.ClipboardApi = void 0;
5
4
  const Channel_1 = require("./Channel");
6
- class ClipboardApi {
7
- static async getSelectedText() {
8
- var _a;
9
- return await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.CLIPBOARD, this.GET_SELECTED_TEXT));
5
+ const BaseApi_1 = require("./BaseApi");
6
+ var ClipboardApiEvent;
7
+ (function (ClipboardApiEvent) {
8
+ ClipboardApiEvent["CHANGED"] = "clipboard-changed";
9
+ })(ClipboardApiEvent || (ClipboardApiEvent = {}));
10
+ exports.ClipboardApiEvent = ClipboardApiEvent;
11
+ class ClipboardApiImpl extends BaseApi_1.BaseApi {
12
+ async getSelectedText() {
13
+ return this.invokeMethod('getSelectedText');
10
14
  }
11
- static async getText() {
12
- var _a;
13
- return await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.CLIPBOARD, this.GET_TEXT));
15
+ async getText() {
16
+ return this.invokeMethod('getText');
17
+ }
18
+ getChannel() {
19
+ return Channel_1.Channel.CLIPBOARD;
14
20
  }
15
21
  }
22
+ const ClipboardApi = new ClipboardApiImpl();
16
23
  exports.ClipboardApi = ClipboardApi;
17
- ClipboardApi.GET_SELECTED_TEXT = "get-selected-text";
18
- ClipboardApi.GET_TEXT = "get-text";
@@ -1,16 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DeviceApi = void 0;
4
- const ElectronUtils_1 = require("../utils/ElectronUtils");
3
+ exports.DeviceApi = exports.DeviceApiImpl = void 0;
5
4
  const Channel_1 = require("./Channel");
6
- class DeviceApi {
5
+ const BaseApi_1 = require("./BaseApi");
6
+ class DeviceApiImpl extends BaseApi_1.BaseApi {
7
7
  /**
8
8
  * 获取当前鼠标位置
9
9
  */
10
- static async getCursorScreenPoint() {
11
- var _a;
12
- return await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.DEVICE, this.GET_CURSOR_SCREEN_POINT));
10
+ async getCursorScreenPoint() {
11
+ return this.invokeMethod('getCursorScreenPoint');
12
+ }
13
+ /**
14
+ * 判断是否所有按键都已经释放
15
+ */
16
+ async isAllKeyReleased() {
17
+ return this.invokeMethod('isAllKeyReleased');
18
+ }
19
+ getChannel() {
20
+ return Channel_1.Channel.DEVICE;
13
21
  }
14
22
  }
23
+ exports.DeviceApiImpl = DeviceApiImpl;
24
+ const DeviceApi = new DeviceApiImpl();
15
25
  exports.DeviceApi = DeviceApi;
16
- DeviceApi.GET_CURSOR_SCREEN_POINT = "get-cursor-screen-point";
@@ -1,17 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DialogApi = void 0;
4
- const ElectronUtils_1 = require("../utils/ElectronUtils");
5
4
  const Channel_1 = require("./Channel");
6
- class DialogApi {
5
+ const BaseApi_1 = require("./BaseApi");
6
+ class DialogApiImpl extends BaseApi_1.BaseApi {
7
+ getChannel() {
8
+ return Channel_1.Channel.DIALOG;
9
+ }
7
10
  /**
8
11
  * 选取单个文件
9
12
  * @param extensions 允许的文件后缀格式,如:["txt","docx","gif"]
10
13
  */
11
- static async pickFile(extensions) {
12
- var _a;
13
- return await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.DIALOG, this.PICK_FILE, extensions));
14
+ pickFile(extensions) {
15
+ return this.invokeMethod('pickFile', extensions);
14
16
  }
15
17
  }
18
+ const DialogApi = new DialogApiImpl();
16
19
  exports.DialogApi = DialogApi;
17
- DialogApi.PICK_FILE = "pick-file";
@@ -1,36 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HostedWidgetApi = void 0;
4
- const ElectronUtils_1 = require("../utils/ElectronUtils");
3
+ exports.HostedWidgetApi = exports.HostedWidgetApiImpl = void 0;
5
4
  const Channel_1 = require("./Channel");
6
- class HostedWidgetApi {
5
+ const BaseApi_1 = require("./BaseApi");
6
+ class HostedWidgetApiImpl extends BaseApi_1.BaseApi {
7
+ getChannel() {
8
+ return Channel_1.Channel.HOSTED_WIDGET;
9
+ }
7
10
  /**
8
11
  * 移除组件
9
12
  * @param id
10
13
  */
11
- static async removeHostedWidget(id) {
12
- var _a;
13
- return (_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.HOSTED_WIDGET, this.REMOVE_HOSTED_WIDGET, id);
14
+ async removeHostedWidget(id) {
15
+ return this.invokeMethod('removeHostedWidget', id);
14
16
  }
15
17
  /**
16
18
  * 通过组件名移除已添加的组件
17
19
  * @param name 组件名
18
20
  */
19
- static async removeHostedWidgetByName(name) {
20
- var _a;
21
- return (_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.HOSTED_WIDGET, this.REMOVE_HOSTED_WIDGET_BY_NAME, name);
21
+ async removeHostedWidgetByName(name) {
22
+ return this.invokeMethod('removeHostedWidgetByName', name);
22
23
  }
23
24
  /**
24
25
  * 获取已添加的组件
25
26
  * @param name 组件名,可以不传
26
27
  */
27
- static async getHostedWidgets(name) {
28
- var _a;
29
- return (_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.HOSTED_WIDGET, this.GET_HOSTED_WIDGETS, name);
28
+ async getHostedWidgets(name) {
29
+ return this.invokeMethod('getHostedWidgets', name);
30
30
  }
31
- static async getHostedWidget(id) {
32
- var _a;
33
- return (_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.HOSTED_WIDGET, this.GET_HOSTED_WIDGET, id);
31
+ async getHostedWidget(id) {
32
+ return this.invokeMethod('getHostedWidget', id);
34
33
  }
35
34
  /**
36
35
  * Opens the dev tools for a widget with the specified ID.
@@ -38,13 +37,11 @@ class HostedWidgetApi {
38
37
  * @param {string} widgetId - The ID of the widget to open the dev tools for.
39
38
  * @return {Promise} A Promise that resolves when the dev tools are opened.
40
39
  */
41
- static async openDevTools(widgetId) {
42
- var _a;
43
- return (_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.HOSTED_WIDGET, this.OPEN_DEV_TOOLS, widgetId);
40
+ async openDevTools(widgetId) {
41
+ return this.invokeMethod('openDevTools', widgetId);
44
42
  }
45
- static async openConfigRoute(widgetId, params) {
46
- var _a;
47
- return (_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.HOSTED_WIDGET, this.OPEN_CONFIG_ROUTE, widgetId, params);
43
+ async openConfigRoute(widgetId, params) {
44
+ return this.invokeMethod('openConfigRoute', widgetId, params);
48
45
  }
49
46
  /**
50
47
  * 注册激活、呼出、置顶组件快捷键
@@ -52,22 +49,13 @@ class HostedWidgetApi {
52
49
  * @param shortcut 如果传空或者不传,则会取消快捷键。更多快捷键配置,请查看Accelerator用法
53
50
  * https://www.electronjs.org/docs/latest/api/accelerator
54
51
  */
55
- static async registerActiveShortcut(widgetId, shortcut) {
56
- var _a;
57
- return (_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.HOSTED_WIDGET, this.REGISTER_ACTIVE_SHORTCUT, widgetId, shortcut);
52
+ async registerActiveShortcut(widgetId, shortcut) {
53
+ return this.invokeMethod('registerActiveShortcut', widgetId, shortcut);
58
54
  }
59
- static async setProxy(widgetId, proxy) {
60
- var _a;
61
- return (_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.HOSTED_WIDGET, this.SET_PROXY, widgetId, proxy);
55
+ async setProxy(widgetId, proxy) {
56
+ return this.invokeMethod('setProxy', widgetId, proxy);
62
57
  }
63
58
  }
59
+ exports.HostedWidgetApiImpl = HostedWidgetApiImpl;
60
+ const HostedWidgetApi = new HostedWidgetApiImpl();
64
61
  exports.HostedWidgetApi = HostedWidgetApi;
65
- HostedWidgetApi.REMOVE_HOSTED_WIDGET = "remove-hosted-widget";
66
- HostedWidgetApi.REMOVE_HOSTED_WIDGET_BY_NAME = "remove-hosted-widget-by-name";
67
- HostedWidgetApi.GET_HOSTED_WIDGETS = "get-hosted-widgets";
68
- HostedWidgetApi.GET_HOSTED_WIDGET = "get-hosted-widget";
69
- HostedWidgetApi.OPEN_DEV_TOOLS = "open-dev-tools";
70
- HostedWidgetApi.REGISTER_ACTIVE_SHORTCUT = "register-active-shortcut";
71
- HostedWidgetApi.SET_PROXY = "SET_PROXY";
72
- HostedWidgetApi.UPDATE = "UPDATE";
73
- HostedWidgetApi.OPEN_CONFIG_ROUTE = "open-config-route";
@@ -1,24 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LogApi = void 0;
4
- const ElectronUtils_1 = require("../utils/ElectronUtils");
5
4
  const Channel_1 = require("./Channel");
6
- class LogApi {
7
- static info(name, ...data) {
5
+ const BaseApi_1 = require("./BaseApi");
6
+ class LogApiImpl extends BaseApi_1.BaseApi {
7
+ getChannel() {
8
+ return Channel_1.Channel.LOG;
9
+ }
10
+ info(...data) {
8
11
  console.info(...data);
9
- ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.LOG, name, 'info', ...data);
12
+ this.invokeMethod('info', ...data);
10
13
  }
11
- static error(name, ...data) {
14
+ error(...data) {
12
15
  console.error(...data);
13
- ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.LOG, name, 'error', ...data);
16
+ this.invokeMethod('error', ...data);
14
17
  }
15
- static warn(name, ...data) {
18
+ warn(...data) {
16
19
  console.warn(...data);
17
- ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.LOG, name, 'warn', ...data);
20
+ this.invokeMethod('warn', ...data);
18
21
  }
19
- static log(name, ...data) {
22
+ log(...data) {
20
23
  console.log(...data);
21
- ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.LOG, name, 'log', ...data);
24
+ this.invokeMethod('log', ...data);
22
25
  }
23
26
  }
27
+ const LogApi = new LogApiImpl();
24
28
  exports.LogApi = LogApi;