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