@widget-js/core 0.1.26 → 0.1.29

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 (41) hide show
  1. package/dist/cjs/api/BrowserWindowApi.js +25 -34
  2. package/dist/cjs/api/Channel.js +2 -0
  3. package/dist/cjs/api/ClipboardApi.js +6 -5
  4. package/dist/cjs/api/HostedWidgetApi.js +5 -0
  5. package/dist/cjs/api/LogApi.js +24 -0
  6. package/dist/cjs/api/ScreenApi.js +6 -0
  7. package/dist/cjs/api/WidgetApi.js +2 -3
  8. package/dist/cjs/index.js +3 -2
  9. package/dist/cjs/model/Widget.js +25 -12
  10. package/dist/cjs/permission/permission.js +2 -0
  11. package/dist/cjs/utils/ElectronUtils.js +4 -0
  12. package/dist/esm/api/BrowserWindowApi.js +25 -34
  13. package/dist/esm/api/Channel.js +2 -0
  14. package/dist/esm/api/ClipboardApi.js +6 -5
  15. package/dist/esm/api/HostedWidgetApi.js +5 -0
  16. package/dist/esm/api/LogApi.js +20 -0
  17. package/dist/esm/api/ScreenApi.js +2 -0
  18. package/dist/esm/api/WidgetApi.js +2 -3
  19. package/dist/esm/index.js +3 -2
  20. package/dist/esm/model/Widget.js +25 -12
  21. package/dist/esm/permission/permission.js +1 -0
  22. package/dist/esm/utils/ElectronUtils.js +4 -0
  23. package/dist/types/api/BrowserWindowApi.d.ts +5 -2
  24. package/dist/types/api/Channel.d.ts +3 -1
  25. package/dist/types/api/ClipboardApi.d.ts +3 -5
  26. package/dist/types/api/HostedWidgetApi.d.ts +3 -0
  27. package/dist/types/api/LogApi.d.ts +6 -0
  28. package/dist/types/api/ScreenApi.d.ts +2 -0
  29. package/dist/types/index.d.ts +3 -2
  30. package/dist/types/model/Widget.d.ts +22 -1
  31. package/dist/types/model/event/NativeKeyboardEvent.d.ts +6 -0
  32. package/dist/types/permission/permission.d.ts +1 -0
  33. package/dist/types/utils/ElectronUtils.d.ts +1 -0
  34. package/dist/umd/index.js +1 -1
  35. package/package.json +17 -14
  36. package/dist/cjs/api/KeyboardApi.js +0 -16
  37. package/dist/esm/api/KeyboardApi.js +0 -12
  38. package/dist/types/api/KeyboardApi.d.ts +0 -7
  39. package/dist/types/model/event/AppKeyboardEvent.d.ts +0 -16
  40. /package/dist/cjs/model/event/{AppKeyboardEvent.js → NativeKeyboardEvent.js} +0 -0
  41. /package/dist/esm/model/event/{AppKeyboardEvent.js → NativeKeyboardEvent.js} +0 -0
@@ -5,44 +5,38 @@ const Channel_1 = require("./Channel");
5
5
  const ElectronUtils_1 = require("../utils/ElectronUtils");
6
6
  class BrowserWindowApi {
7
7
  static async setIgnoreMouseEvent(ignore) {
8
- var _a;
9
- await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.IGNORE_MOUSE_EVENT, ignore));
8
+ await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.IGNORE_MOUSE_EVENT, ignore);
10
9
  }
11
10
  static async show() {
12
- var _a;
13
- await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.WINDOW_VISIBILITY, true));
11
+ await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.WINDOW_VISIBILITY, true);
14
12
  }
15
13
  static async hide() {
16
- var _a;
17
- await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.WINDOW_VISIBILITY, false));
14
+ await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.WINDOW_VISIBILITY, false);
15
+ }
16
+ static async center() {
17
+ await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.CENTER, false);
18
18
  }
19
19
  /**
20
20
  * @deprecated
21
21
  * @param show
22
22
  */
23
23
  static async setWindowVisibility(show) {
24
- var _a;
25
- await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.WINDOW_VISIBILITY, show));
24
+ await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.WINDOW_VISIBILITY, show);
26
25
  }
27
26
  static async setAlwaysOnTop(alwaysOnTop) {
28
- var _a;
29
- await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.ALWAYS_ON_TOP, alwaysOnTop));
27
+ await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.ALWAYS_ON_TOP, alwaysOnTop);
30
28
  }
31
29
  static async isAlwaysOnTop() {
32
- var _a;
33
- return await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.IS_ALWAYS_ON_TOP));
30
+ return await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.IS_ALWAYS_ON_TOP);
34
31
  }
35
32
  static async openUrl(url) {
36
- var _a;
37
- await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.OPEN_URL, url));
33
+ await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.OPEN_URL, url);
38
34
  }
39
35
  static async moveTop() {
40
- var _a;
41
- await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.MOVE_TOP));
36
+ await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.MOVE_TOP);
42
37
  }
43
38
  static async openDevTools() {
44
- var _a;
45
- await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.OPEN_DEV_TOOLS));
39
+ await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.OPEN_DEV_TOOLS);
46
40
  }
47
41
  /**
48
42
  * 设置窗口位置
@@ -51,49 +45,45 @@ class BrowserWindowApi {
51
45
  * @param animation 动画只在mac系统有效
52
46
  */
53
47
  static async setPosition(x, y, animation) {
54
- var _a;
55
- await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.SET_POSITION, x, y, animation));
48
+ await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.SET_POSITION, x, y, animation);
56
49
  }
57
50
  static async getPosition() {
58
- var _a;
59
- return await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.GET_POSITION));
51
+ return await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.GET_POSITION);
60
52
  }
61
53
  static async blur() {
62
- var _a;
63
- return await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.BLUR));
54
+ return await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.BLUR);
64
55
  }
65
56
  static async focus() {
66
- var _a;
67
- return await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.FOCUS));
57
+ return await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.FOCUS);
68
58
  }
69
59
  /**
70
60
  * 设置窗口是否可以拉伸
71
61
  * @param resizable
72
62
  */
73
63
  static async setResizable(resizable) {
74
- var _a;
75
- return await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.SET_RESIZABLE, resizable));
64
+ return await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.SET_RESIZABLE, resizable);
76
65
  }
77
66
  static async getBounds() {
78
- var _a;
79
- return await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.GET_BOUNDS));
67
+ return await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.GET_BOUNDS);
80
68
  }
81
69
  static async setBounds(bounds, animate) {
82
- var _a;
83
- return await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.SET_BOUNDS, bounds, animate));
70
+ return await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.SET_BOUNDS, bounds, animate);
71
+ }
72
+ static async alignToScreen(align) {
73
+ return await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.ALIGN_TO_SCREEN, align);
84
74
  }
85
75
  /**
86
76
  * 通过url检测窗口是否存在
87
77
  * @param url
88
78
  */
89
79
  static async existsByUrl(url) {
90
- var _a;
91
- return await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.EXISTS_BY_URL, url));
80
+ return await ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.BROWSER_WINDOW, this.EXISTS_BY_URL, url);
92
81
  }
93
82
  }
94
83
  exports.BrowserWindowApi = BrowserWindowApi;
95
84
  BrowserWindowApi.IGNORE_MOUSE_EVENT = "ignore-mouse-event";
96
85
  BrowserWindowApi.WINDOW_VISIBILITY = "window-visibility";
86
+ BrowserWindowApi.CENTER = "center";
97
87
  BrowserWindowApi.ALWAYS_ON_TOP = "always-on-top";
98
88
  BrowserWindowApi.IS_ALWAYS_ON_TOP = "is-always-on-top";
99
89
  BrowserWindowApi.OPEN_URL = "open-url";
@@ -106,5 +96,6 @@ BrowserWindowApi.FOCUS = "focus";
106
96
  BrowserWindowApi.SET_RESIZABLE = "set-resizable";
107
97
  BrowserWindowApi.GET_BOUNDS = "get-bounds";
108
98
  BrowserWindowApi.SET_BOUNDS = "set-bounds";
99
+ BrowserWindowApi.ALIGN_TO_SCREEN = "align-to-screen";
109
100
  BrowserWindowApi.EXISTS_BY_URL = "exists-by-url";
110
101
  BrowserWindowApi.SHOW = "show";
@@ -15,5 +15,7 @@ var Channel;
15
15
  Channel["CLIPBOARD"] = "channel::cn.widgetjs.core.clipboard";
16
16
  Channel["DEVICE"] = "channel::cn.widgetjs.core.device";
17
17
  Channel["KEYBOARD"] = "channel::cn.widgetjs.core.keyboard";
18
+ Channel["SCREEN"] = "channel::cn.widgetjs.core.screen";
18
19
  Channel["SHORTCUT"] = "channel::cn.widgetjs.core.shortcut";
20
+ Channel["LOG"] = "channel::cn.widgetjs.core.log";
19
21
  })(Channel = exports.Channel || (exports.Channel = {}));
@@ -4,14 +4,15 @@ exports.ClipboardApi = void 0;
4
4
  const ElectronUtils_1 = require("../utils/ElectronUtils");
5
5
  const Channel_1 = require("./Channel");
6
6
  class ClipboardApi {
7
- /**
8
- * 选取单个文件
9
- * @param extensions 允许的文件后缀格式,如:["txt","docx","gif"]
10
- */
11
- static async getSelectedText(extensions) {
7
+ static async getSelectedText() {
12
8
  var _a;
13
9
  return await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.CLIPBOARD, this.GET_SELECTED_TEXT));
14
10
  }
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));
14
+ }
15
15
  }
16
16
  exports.ClipboardApi = ClipboardApi;
17
17
  ClipboardApi.GET_SELECTED_TEXT = "get-selected-text";
18
+ ClipboardApi.GET_TEXT = "get-text";
@@ -42,6 +42,10 @@ class HostedWidgetApi {
42
42
  var _a;
43
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);
44
44
  }
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);
48
+ }
45
49
  /**
46
50
  * 注册激活、呼出、置顶组件快捷键
47
51
  * @param widgetId 组件id
@@ -66,3 +70,4 @@ HostedWidgetApi.OPEN_DEV_TOOLS = "open-dev-tools";
66
70
  HostedWidgetApi.REGISTER_ACTIVE_SHORTCUT = "register-active-shortcut";
67
71
  HostedWidgetApi.SET_PROXY = "SET_PROXY";
68
72
  HostedWidgetApi.UPDATE = "UPDATE";
73
+ HostedWidgetApi.OPEN_CONFIG_ROUTE = "open-config-route";
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogApi = void 0;
4
+ const ElectronUtils_1 = require("../utils/ElectronUtils");
5
+ const Channel_1 = require("./Channel");
6
+ class LogApi {
7
+ static info(name, ...data) {
8
+ console.info(...data);
9
+ ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.LOG, name, 'info', ...data);
10
+ }
11
+ static error(name, ...data) {
12
+ console.error(...data);
13
+ ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.LOG, name, 'error', ...data);
14
+ }
15
+ static warn(name, ...data) {
16
+ console.warn(...data);
17
+ ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.LOG, name, 'warn', ...data);
18
+ }
19
+ static log(name, ...data) {
20
+ console.log(...data);
21
+ ElectronUtils_1.ElectronUtils.invoke(Channel_1.Channel.LOG, name, 'log', ...data);
22
+ }
23
+ }
24
+ exports.LogApi = LogApi;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ScreenApi = void 0;
4
+ class ScreenApi {
5
+ }
6
+ exports.ScreenApi = ScreenApi;
@@ -26,9 +26,8 @@ class WidgetApi {
26
26
  const data = await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.WIDGET, this.GET_WIDGETS));
27
27
  const widgets = [];
28
28
  if (data) {
29
- const arr = JSON.parse(data);
30
- for (const i in arr) {
31
- widgets.push(Widget_1.Widget.parseObject(arr[i]));
29
+ for (const item of data) {
30
+ widgets.push(Widget_1.Widget.parseObject(item));
32
31
  }
33
32
  }
34
33
  return widgets;
package/dist/cjs/index.js CHANGED
@@ -23,7 +23,7 @@ __exportStar(require("./model/AppNotification"), exports);
23
23
  __exportStar(require("./model/HostedMode"), exports);
24
24
  __exportStar(require("./model/HostedWidget"), exports);
25
25
  __exportStar(require("./model/interface/Rectangle"), exports);
26
- __exportStar(require("./model/event/AppKeyboardEvent"), exports);
26
+ __exportStar(require("./model/event/NativeKeyboardEvent"), exports);
27
27
  __exportStar(require("./model/event/AppMouseEvent"), exports);
28
28
  __exportStar(require("./model/WidgetPackage"), exports);
29
29
  __exportStar(require("./api/ElectronApi"), exports);
@@ -32,7 +32,6 @@ __exportStar(require("./api/BrowserWindowApi"), exports);
32
32
  __exportStar(require("./api/GlobalShortcutApi"), exports);
33
33
  __exportStar(require("./api/NotificationApi"), exports);
34
34
  __exportStar(require("./api/HostedWidgetApi"), exports);
35
- __exportStar(require("./api/KeyboardApi"), exports);
36
35
  __exportStar(require("./api/DeviceApi"), exports);
37
36
  __exportStar(require("./api/Channel"), exports);
38
37
  __exportStar(require("./api/ClipboardApi"), exports);
@@ -44,3 +43,5 @@ __exportStar(require("./api/DialogApi"), exports);
44
43
  __exportStar(require("./utils/ElectronUtils"), exports);
45
44
  __exportStar(require("./utils/UrlUtils"), exports);
46
45
  __exportStar(require("./router/query"), exports);
46
+ __exportStar(require("./api/LogApi"), exports);
47
+ __exportStar(require("./permission/permission"), exports);
@@ -4,7 +4,7 @@ exports.WidgetKeyword = exports.Widget = void 0;
4
4
  const HostedMode_1 = require("./HostedMode");
5
5
  class Widget {
6
6
  constructor(options) {
7
- var _a, _b, _c, _d, _e, _f, _g;
7
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
8
8
  /**
9
9
  * 组件默认语言
10
10
  */
@@ -16,17 +16,19 @@ class Widget {
16
16
  this.lang = options.lang;
17
17
  this.width = options.width;
18
18
  this.height = options.height;
19
- this.maxWidth = (_a = options.maxWidth) !== null && _a !== void 0 ? _a : options.width;
20
- this.maxHeight = (_b = options.maxHeight) !== null && _b !== void 0 ? _b : options.height;
21
- this.minWidth = (_c = options.minWidth) !== null && _c !== void 0 ? _c : options.width;
22
- this.minHeight = (_d = options.minHeight) !== null && _d !== void 0 ? _d : options.height;
23
- this.backgroundThrottling = (_e = options.backgroundThrottling) !== null && _e !== void 0 ? _e : true;
19
+ this.movable = (_a = options.movable) !== null && _a !== void 0 ? _a : true;
20
+ this.permissions = (_b = options.permissions) !== null && _b !== void 0 ? _b : [];
21
+ this.maxWidth = (_c = options.maxWidth) !== null && _c !== void 0 ? _c : options.width;
22
+ this.maxHeight = (_d = options.maxHeight) !== null && _d !== void 0 ? _d : options.height;
23
+ this.minWidth = (_e = options.minWidth) !== null && _e !== void 0 ? _e : options.width;
24
+ this.minHeight = (_f = options.minHeight) !== null && _f !== void 0 ? _f : options.height;
25
+ this.backgroundThrottling = (_g = options.backgroundThrottling) !== null && _g !== void 0 ? _g : true;
24
26
  this.packageName = options.packageName;
25
27
  this.previewImage = options.previewImage;
26
28
  this.shortcut = options.shortcut;
27
- this.refreshWhenResided = (_f = options.refreshWhenResided) !== null && _f !== void 0 ? _f : false;
29
+ this.refreshWhenResided = (_h = options.refreshWhenResided) !== null && _h !== void 0 ? _h : false;
28
30
  this.hideWhenBlur = options.hideWhenBlur == null ? false : options.hideWhenBlur;
29
- this.supportHostedMode = (_g = options.supportHostedMode) !== null && _g !== void 0 ? _g : HostedMode_1.HostedMode.NORMAL | HostedMode_1.HostedMode.OVERLAP;
31
+ this.supportHostedMode = (_j = options.supportHostedMode) !== null && _j !== void 0 ? _j : HostedMode_1.HostedMode.NORMAL | HostedMode_1.HostedMode.OVERLAP;
30
32
  this.routes = options.routes;
31
33
  }
32
34
  getIndexRoute() {
@@ -34,8 +36,10 @@ class Widget {
34
36
  return result;
35
37
  }
36
38
  getConfigRoute() {
37
- const result = this.routes.find((it) => it.name.toLowerCase() == 'config');
38
- return result;
39
+ return this.routes.find((it) => it.name.toLowerCase() == 'config');
40
+ }
41
+ isConfigurable() {
42
+ return this.getConfigRoute() != null;
39
43
  }
40
44
  /**
41
45
  * 获取组件标题
@@ -57,9 +61,18 @@ class Widget {
57
61
  return this.parseObject(object);
58
62
  }
59
63
  static parseObject(obj) {
60
- return new Widget({
61
- ...obj
64
+ let widget = new Widget({
65
+ description: {},
66
+ height: 0,
67
+ keywords: [],
68
+ lang: "",
69
+ name: "",
70
+ routes: [],
71
+ title: {},
72
+ width: 0
62
73
  });
74
+ Object.assign(widget, obj);
75
+ return widget;
63
76
  }
64
77
  /**
65
78
  * 是否支持悬浮窗
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -20,5 +20,9 @@ class ElectronUtils {
20
20
  }
21
21
  return null;
22
22
  }
23
+ static async invoke(channel, method, ...args) {
24
+ var _a;
25
+ return (_a = this.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(channel, method, ...args);
26
+ }
23
27
  }
24
28
  exports.ElectronUtils = ElectronUtils;
@@ -2,44 +2,38 @@ import { Channel } from "./Channel";
2
2
  import { ElectronUtils } from "../utils/ElectronUtils";
3
3
  export class BrowserWindowApi {
4
4
  static async setIgnoreMouseEvent(ignore) {
5
- var _a;
6
- await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.IGNORE_MOUSE_EVENT, ignore));
5
+ await ElectronUtils.invoke(Channel.BROWSER_WINDOW, this.IGNORE_MOUSE_EVENT, ignore);
7
6
  }
8
7
  static async show() {
9
- var _a;
10
- await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.WINDOW_VISIBILITY, true));
8
+ await ElectronUtils.invoke(Channel.BROWSER_WINDOW, this.WINDOW_VISIBILITY, true);
11
9
  }
12
10
  static async hide() {
13
- var _a;
14
- await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.WINDOW_VISIBILITY, false));
11
+ await ElectronUtils.invoke(Channel.BROWSER_WINDOW, this.WINDOW_VISIBILITY, false);
12
+ }
13
+ static async center() {
14
+ await ElectronUtils.invoke(Channel.BROWSER_WINDOW, this.CENTER, false);
15
15
  }
16
16
  /**
17
17
  * @deprecated
18
18
  * @param show
19
19
  */
20
20
  static async setWindowVisibility(show) {
21
- var _a;
22
- await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.WINDOW_VISIBILITY, show));
21
+ await ElectronUtils.invoke(Channel.BROWSER_WINDOW, this.WINDOW_VISIBILITY, show);
23
22
  }
24
23
  static async setAlwaysOnTop(alwaysOnTop) {
25
- var _a;
26
- await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.ALWAYS_ON_TOP, alwaysOnTop));
24
+ await ElectronUtils.invoke(Channel.BROWSER_WINDOW, this.ALWAYS_ON_TOP, alwaysOnTop);
27
25
  }
28
26
  static async isAlwaysOnTop() {
29
- var _a;
30
- return await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.IS_ALWAYS_ON_TOP));
27
+ return await ElectronUtils.invoke(Channel.BROWSER_WINDOW, this.IS_ALWAYS_ON_TOP);
31
28
  }
32
29
  static async openUrl(url) {
33
- var _a;
34
- await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.OPEN_URL, url));
30
+ await ElectronUtils.invoke(Channel.BROWSER_WINDOW, this.OPEN_URL, url);
35
31
  }
36
32
  static async moveTop() {
37
- var _a;
38
- await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.MOVE_TOP));
33
+ await ElectronUtils.invoke(Channel.BROWSER_WINDOW, this.MOVE_TOP);
39
34
  }
40
35
  static async openDevTools() {
41
- var _a;
42
- await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.OPEN_DEV_TOOLS));
36
+ await ElectronUtils.invoke(Channel.BROWSER_WINDOW, this.OPEN_DEV_TOOLS);
43
37
  }
44
38
  /**
45
39
  * 设置窗口位置
@@ -48,48 +42,44 @@ export class BrowserWindowApi {
48
42
  * @param animation 动画只在mac系统有效
49
43
  */
50
44
  static async setPosition(x, y, animation) {
51
- var _a;
52
- await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.SET_POSITION, x, y, animation));
45
+ await ElectronUtils.invoke(Channel.BROWSER_WINDOW, this.SET_POSITION, x, y, animation);
53
46
  }
54
47
  static async getPosition() {
55
- var _a;
56
- return await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.GET_POSITION));
48
+ return await ElectronUtils.invoke(Channel.BROWSER_WINDOW, this.GET_POSITION);
57
49
  }
58
50
  static async blur() {
59
- var _a;
60
- return await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.BLUR));
51
+ return await ElectronUtils.invoke(Channel.BROWSER_WINDOW, this.BLUR);
61
52
  }
62
53
  static async focus() {
63
- var _a;
64
- return await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.FOCUS));
54
+ return await ElectronUtils.invoke(Channel.BROWSER_WINDOW, this.FOCUS);
65
55
  }
66
56
  /**
67
57
  * 设置窗口是否可以拉伸
68
58
  * @param resizable
69
59
  */
70
60
  static async setResizable(resizable) {
71
- var _a;
72
- return await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.SET_RESIZABLE, resizable));
61
+ return await ElectronUtils.invoke(Channel.BROWSER_WINDOW, this.SET_RESIZABLE, resizable);
73
62
  }
74
63
  static async getBounds() {
75
- var _a;
76
- return await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.GET_BOUNDS));
64
+ return await ElectronUtils.invoke(Channel.BROWSER_WINDOW, this.GET_BOUNDS);
77
65
  }
78
66
  static async setBounds(bounds, animate) {
79
- var _a;
80
- return await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.SET_BOUNDS, bounds, animate));
67
+ return await ElectronUtils.invoke(Channel.BROWSER_WINDOW, this.SET_BOUNDS, bounds, animate);
68
+ }
69
+ static async alignToScreen(align) {
70
+ return await ElectronUtils.invoke(Channel.BROWSER_WINDOW, this.ALIGN_TO_SCREEN, align);
81
71
  }
82
72
  /**
83
73
  * 通过url检测窗口是否存在
84
74
  * @param url
85
75
  */
86
76
  static async existsByUrl(url) {
87
- var _a;
88
- return await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.EXISTS_BY_URL, url));
77
+ return await ElectronUtils.invoke(Channel.BROWSER_WINDOW, this.EXISTS_BY_URL, url);
89
78
  }
90
79
  }
91
80
  BrowserWindowApi.IGNORE_MOUSE_EVENT = "ignore-mouse-event";
92
81
  BrowserWindowApi.WINDOW_VISIBILITY = "window-visibility";
82
+ BrowserWindowApi.CENTER = "center";
93
83
  BrowserWindowApi.ALWAYS_ON_TOP = "always-on-top";
94
84
  BrowserWindowApi.IS_ALWAYS_ON_TOP = "is-always-on-top";
95
85
  BrowserWindowApi.OPEN_URL = "open-url";
@@ -102,5 +92,6 @@ BrowserWindowApi.FOCUS = "focus";
102
92
  BrowserWindowApi.SET_RESIZABLE = "set-resizable";
103
93
  BrowserWindowApi.GET_BOUNDS = "get-bounds";
104
94
  BrowserWindowApi.SET_BOUNDS = "set-bounds";
95
+ BrowserWindowApi.ALIGN_TO_SCREEN = "align-to-screen";
105
96
  BrowserWindowApi.EXISTS_BY_URL = "exists-by-url";
106
97
  BrowserWindowApi.SHOW = "show";
@@ -12,5 +12,7 @@ export var Channel;
12
12
  Channel["CLIPBOARD"] = "channel::cn.widgetjs.core.clipboard";
13
13
  Channel["DEVICE"] = "channel::cn.widgetjs.core.device";
14
14
  Channel["KEYBOARD"] = "channel::cn.widgetjs.core.keyboard";
15
+ Channel["SCREEN"] = "channel::cn.widgetjs.core.screen";
15
16
  Channel["SHORTCUT"] = "channel::cn.widgetjs.core.shortcut";
17
+ Channel["LOG"] = "channel::cn.widgetjs.core.log";
16
18
  })(Channel || (Channel = {}));
@@ -1,13 +1,14 @@
1
1
  import { ElectronUtils } from "../utils/ElectronUtils";
2
2
  import { Channel } from "./Channel";
3
3
  export class ClipboardApi {
4
- /**
5
- * 选取单个文件
6
- * @param extensions 允许的文件后缀格式,如:["txt","docx","gif"]
7
- */
8
- static async getSelectedText(extensions) {
4
+ static async getSelectedText() {
9
5
  var _a;
10
6
  return await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.CLIPBOARD, this.GET_SELECTED_TEXT));
11
7
  }
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
+ }
12
12
  }
13
13
  ClipboardApi.GET_SELECTED_TEXT = "get-selected-text";
14
+ ClipboardApi.GET_TEXT = "get-text";
@@ -39,6 +39,10 @@ export class HostedWidgetApi {
39
39
  var _a;
40
40
  return (_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.HOSTED_WIDGET, this.OPEN_DEV_TOOLS, widgetId);
41
41
  }
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);
45
+ }
42
46
  /**
43
47
  * 注册激活、呼出、置顶组件快捷键
44
48
  * @param widgetId 组件id
@@ -62,3 +66,4 @@ HostedWidgetApi.OPEN_DEV_TOOLS = "open-dev-tools";
62
66
  HostedWidgetApi.REGISTER_ACTIVE_SHORTCUT = "register-active-shortcut";
63
67
  HostedWidgetApi.SET_PROXY = "SET_PROXY";
64
68
  HostedWidgetApi.UPDATE = "UPDATE";
69
+ HostedWidgetApi.OPEN_CONFIG_ROUTE = "open-config-route";
@@ -0,0 +1,20 @@
1
+ import { ElectronUtils } from '../utils/ElectronUtils';
2
+ import { Channel } from "./Channel";
3
+ export class LogApi {
4
+ static info(name, ...data) {
5
+ console.info(...data);
6
+ ElectronUtils.invoke(Channel.LOG, name, 'info', ...data);
7
+ }
8
+ static error(name, ...data) {
9
+ console.error(...data);
10
+ ElectronUtils.invoke(Channel.LOG, name, 'error', ...data);
11
+ }
12
+ static warn(name, ...data) {
13
+ console.warn(...data);
14
+ ElectronUtils.invoke(Channel.LOG, name, 'warn', ...data);
15
+ }
16
+ static log(name, ...data) {
17
+ console.log(...data);
18
+ ElectronUtils.invoke(Channel.LOG, name, 'log', ...data);
19
+ }
20
+ }
@@ -0,0 +1,2 @@
1
+ export class ScreenApi {
2
+ }
@@ -20,9 +20,8 @@ export class WidgetApi {
20
20
  const data = await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.WIDGET, this.GET_WIDGETS));
21
21
  const widgets = [];
22
22
  if (data) {
23
- const arr = JSON.parse(data);
24
- for (const i in arr) {
25
- widgets.push(Widget.parseObject(arr[i]));
23
+ for (const item of data) {
24
+ widgets.push(Widget.parseObject(item));
26
25
  }
27
26
  }
28
27
  return widgets;
package/dist/esm/index.js CHANGED
@@ -7,7 +7,7 @@ export * from "./model/AppNotification";
7
7
  export * from "./model/HostedMode";
8
8
  export * from "./model/HostedWidget";
9
9
  export * from "./model/interface/Rectangle";
10
- export * from "./model/event/AppKeyboardEvent";
10
+ export * from "./model/event/NativeKeyboardEvent";
11
11
  export * from "./model/event/AppMouseEvent";
12
12
  export * from "./model/WidgetPackage";
13
13
  export * from "./api/ElectronApi";
@@ -16,7 +16,6 @@ export * from "./api/BrowserWindowApi";
16
16
  export * from "./api/GlobalShortcutApi";
17
17
  export * from "./api/NotificationApi";
18
18
  export * from "./api/HostedWidgetApi";
19
- export * from "./api/KeyboardApi";
20
19
  export * from "./api/DeviceApi";
21
20
  export * from "./api/Channel";
22
21
  export * from "./api/ClipboardApi";
@@ -28,3 +27,5 @@ export * from "./api/DialogApi";
28
27
  export * from "./utils/ElectronUtils";
29
28
  export * from "./utils/UrlUtils";
30
29
  export * from "./router/query";
30
+ export * from "./api/LogApi";
31
+ export * from "./permission/permission";
@@ -1,7 +1,7 @@
1
1
  import { HostedMode } from "./HostedMode";
2
2
  export class Widget {
3
3
  constructor(options) {
4
- var _a, _b, _c, _d, _e, _f, _g;
4
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
5
5
  /**
6
6
  * 组件默认语言
7
7
  */
@@ -13,17 +13,19 @@ export class Widget {
13
13
  this.lang = options.lang;
14
14
  this.width = options.width;
15
15
  this.height = options.height;
16
- this.maxWidth = (_a = options.maxWidth) !== null && _a !== void 0 ? _a : options.width;
17
- this.maxHeight = (_b = options.maxHeight) !== null && _b !== void 0 ? _b : options.height;
18
- this.minWidth = (_c = options.minWidth) !== null && _c !== void 0 ? _c : options.width;
19
- this.minHeight = (_d = options.minHeight) !== null && _d !== void 0 ? _d : options.height;
20
- this.backgroundThrottling = (_e = options.backgroundThrottling) !== null && _e !== void 0 ? _e : true;
16
+ this.movable = (_a = options.movable) !== null && _a !== void 0 ? _a : true;
17
+ this.permissions = (_b = options.permissions) !== null && _b !== void 0 ? _b : [];
18
+ this.maxWidth = (_c = options.maxWidth) !== null && _c !== void 0 ? _c : options.width;
19
+ this.maxHeight = (_d = options.maxHeight) !== null && _d !== void 0 ? _d : options.height;
20
+ this.minWidth = (_e = options.minWidth) !== null && _e !== void 0 ? _e : options.width;
21
+ this.minHeight = (_f = options.minHeight) !== null && _f !== void 0 ? _f : options.height;
22
+ this.backgroundThrottling = (_g = options.backgroundThrottling) !== null && _g !== void 0 ? _g : true;
21
23
  this.packageName = options.packageName;
22
24
  this.previewImage = options.previewImage;
23
25
  this.shortcut = options.shortcut;
24
- this.refreshWhenResided = (_f = options.refreshWhenResided) !== null && _f !== void 0 ? _f : false;
26
+ this.refreshWhenResided = (_h = options.refreshWhenResided) !== null && _h !== void 0 ? _h : false;
25
27
  this.hideWhenBlur = options.hideWhenBlur == null ? false : options.hideWhenBlur;
26
- this.supportHostedMode = (_g = options.supportHostedMode) !== null && _g !== void 0 ? _g : HostedMode.NORMAL | HostedMode.OVERLAP;
28
+ this.supportHostedMode = (_j = options.supportHostedMode) !== null && _j !== void 0 ? _j : HostedMode.NORMAL | HostedMode.OVERLAP;
27
29
  this.routes = options.routes;
28
30
  }
29
31
  getIndexRoute() {
@@ -31,8 +33,10 @@ export class Widget {
31
33
  return result;
32
34
  }
33
35
  getConfigRoute() {
34
- const result = this.routes.find((it) => it.name.toLowerCase() == 'config');
35
- return result;
36
+ return this.routes.find((it) => it.name.toLowerCase() == 'config');
37
+ }
38
+ isConfigurable() {
39
+ return this.getConfigRoute() != null;
36
40
  }
37
41
  /**
38
42
  * 获取组件标题
@@ -54,9 +58,18 @@ export class Widget {
54
58
  return this.parseObject(object);
55
59
  }
56
60
  static parseObject(obj) {
57
- return new Widget({
58
- ...obj
61
+ let widget = new Widget({
62
+ description: {},
63
+ height: 0,
64
+ keywords: [],
65
+ lang: "",
66
+ name: "",
67
+ routes: [],
68
+ title: {},
69
+ width: 0
59
70
  });
71
+ Object.assign(widget, obj);
72
+ return widget;
60
73
  }
61
74
  /**
62
75
  * 是否支持悬浮窗
@@ -0,0 +1 @@
1
+ export {};
@@ -17,4 +17,8 @@ export class ElectronUtils {
17
17
  }
18
18
  return null;
19
19
  }
20
+ static async invoke(channel, method, ...args) {
21
+ var _a;
22
+ return (_a = this.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(channel, method, ...args);
23
+ }
20
24
  }