@widget-js/core 0.1.5 → 0.1.9

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 (72) hide show
  1. package/LICENSE +21 -21
  2. package/dist/cjs/api/ApiConstants.js +8 -8
  3. package/dist/cjs/api/AppApi.js +31 -31
  4. package/dist/cjs/api/BroadcastApi.js +20 -20
  5. package/dist/cjs/api/BrowserWindowApi.js +42 -24
  6. package/dist/cjs/api/Channel.js +11 -11
  7. package/dist/cjs/api/ElectronApi.js +13 -13
  8. package/dist/cjs/api/NotificationApi.js +83 -83
  9. package/dist/cjs/api/WidgetApi.js +58 -49
  10. package/dist/cjs/index.js +35 -34
  11. package/dist/cjs/model/HostedMode.js +14 -0
  12. package/dist/cjs/model/Notification.js +15 -15
  13. package/dist/cjs/model/SocialInfo.js +10 -10
  14. package/dist/cjs/model/Widget.js +79 -79
  15. package/dist/cjs/model/WidgetData.js +16 -16
  16. package/dist/cjs/model/WidgetPackage.js +21 -6
  17. package/dist/cjs/model/WidgetParams.js +139 -144
  18. package/dist/cjs/model/event/BroadcastEvent.js +14 -14
  19. package/dist/cjs/model/event/WebSocketEvent.js +14 -14
  20. package/dist/cjs/model/interface/IHostedWidget.js +2 -0
  21. package/dist/cjs/repository/WidgetDataRepository.js +71 -71
  22. package/dist/cjs/router/encoding.js +144 -144
  23. package/dist/cjs/router/query.js +84 -84
  24. package/dist/cjs/utils/ElectronUtils.js +24 -24
  25. package/dist/esm/api/ApiConstants.js +4 -4
  26. package/dist/esm/api/AppApi.js +27 -27
  27. package/dist/esm/api/BroadcastApi.js +16 -16
  28. package/dist/esm/api/BrowserWindowApi.js +38 -20
  29. package/dist/esm/api/Channel.js +8 -8
  30. package/dist/esm/api/ElectronApi.js +9 -9
  31. package/dist/esm/api/NotificationApi.js +79 -79
  32. package/dist/esm/api/WidgetApi.js +54 -45
  33. package/dist/esm/index.js +19 -18
  34. package/dist/esm/model/HostedMode.js +11 -0
  35. package/dist/esm/model/Notification.js +11 -11
  36. package/dist/esm/model/SocialInfo.js +6 -6
  37. package/dist/esm/model/Widget.js +75 -75
  38. package/dist/esm/model/WidgetData.js +12 -12
  39. package/dist/esm/model/WidgetPackage.js +17 -2
  40. package/dist/esm/model/WidgetParams.js +135 -140
  41. package/dist/esm/model/event/BroadcastEvent.js +10 -10
  42. package/dist/esm/model/event/WebSocketEvent.js +10 -10
  43. package/dist/esm/model/interface/IHostedWidget.js +1 -0
  44. package/dist/esm/repository/WidgetDataRepository.js +64 -64
  45. package/dist/esm/router/encoding.js +135 -135
  46. package/dist/esm/router/query.js +79 -79
  47. package/dist/esm/utils/ElectronUtils.js +20 -20
  48. package/dist/types/api/ApiConstants.d.ts +4 -4
  49. package/dist/types/api/AppApi.d.ts +10 -10
  50. package/dist/types/api/BroadcastApi.d.ts +6 -6
  51. package/dist/types/api/BrowserWindowApi.d.ts +27 -10
  52. package/dist/types/api/Channel.d.ts +7 -7
  53. package/dist/types/api/ElectronApi.d.ts +4 -4
  54. package/dist/types/api/NotificationApi.d.ts +14 -14
  55. package/dist/types/api/WidgetApi.d.ts +30 -24
  56. package/dist/types/index.d.ts +19 -18
  57. package/dist/types/model/HostedMode.d.ts +10 -0
  58. package/dist/types/model/Notification.d.ts +16 -16
  59. package/dist/types/model/SocialInfo.d.ts +6 -6
  60. package/dist/types/model/Widget.d.ts +96 -85
  61. package/dist/types/model/WidgetData.d.ts +35 -35
  62. package/dist/types/model/WidgetPackage.d.ts +43 -41
  63. package/dist/types/model/WidgetParams.d.ts +60 -63
  64. package/dist/types/model/event/BroadcastEvent.d.ts +12 -12
  65. package/dist/types/model/event/WebSocketEvent.d.ts +8 -8
  66. package/dist/types/model/interface/IHostedWidget.d.ts +13 -0
  67. package/dist/types/repository/WidgetDataRepository.d.ts +26 -26
  68. package/dist/types/router/encoding.d.ts +62 -62
  69. package/dist/types/router/query.d.ts +53 -53
  70. package/dist/types/utils/ElectronUtils.d.ts +8 -8
  71. package/dist/umd/index.js +1 -1
  72. package/package.json +2 -2
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Widget-App
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Widget-App
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,8 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiConstants = void 0;
4
- class ApiConstants {
5
- }
6
- exports.ApiConstants = ApiConstants;
7
- ApiConstants.CONFIG_LAUNCH_AT_STARTUP = "CONFIG_LAUNCH_AT_STARTUP";
8
- ApiConstants.CONFIG_WIDGET_TITLE_COLOR = "CONFIG_WIDGET_TITLE_COLOR";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiConstants = void 0;
4
+ class ApiConstants {
5
+ }
6
+ exports.ApiConstants = ApiConstants;
7
+ ApiConstants.CONFIG_LAUNCH_AT_STARTUP = "CONFIG_LAUNCH_AT_STARTUP";
8
+ ApiConstants.CONFIG_WIDGET_TITLE_COLOR = "CONFIG_WIDGET_TITLE_COLOR";
@@ -1,31 +1,31 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AppApi = void 0;
4
- const ElectronUtils_1 = require("../utils/ElectronUtils");
5
- const Channel_1 = require("./Channel");
6
- class AppApi {
7
- static async setConfig(key, value) {
8
- await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.APP, this.SET_CONFIG, key, value);
9
- }
10
- static async getConfig(key, defaultValue) {
11
- const value = await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.APP, this.GET_CONFIG, key);
12
- if (value === null || value === undefined) {
13
- return defaultValue;
14
- }
15
- if (typeof defaultValue == "boolean") {
16
- return value === "true";
17
- }
18
- return value;
19
- }
20
- static openAddWidgetWindow() {
21
- ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.APP, this.OPEN_ADD_WIDGET_WINDOW);
22
- }
23
- static openSettingWindow() {
24
- ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.APP, this.OPEN_SETTING_WINDOW);
25
- }
26
- }
27
- exports.AppApi = AppApi;
28
- AppApi.SET_CONFIG = "SET_CONFIG";
29
- AppApi.GET_CONFIG = "GET_CONFIG";
30
- AppApi.OPEN_ADD_WIDGET_WINDOW = "open-add-widget-window";
31
- AppApi.OPEN_SETTING_WINDOW = "open-setting-window";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppApi = void 0;
4
+ const ElectronUtils_1 = require("../utils/ElectronUtils");
5
+ const Channel_1 = require("./Channel");
6
+ class AppApi {
7
+ static async setConfig(key, value) {
8
+ await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.APP, this.SET_CONFIG, key, value);
9
+ }
10
+ static async getConfig(key, defaultValue) {
11
+ const value = await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.APP, this.GET_CONFIG, key);
12
+ if (value === null || value === undefined) {
13
+ return defaultValue;
14
+ }
15
+ if (typeof defaultValue == "boolean") {
16
+ return value === "true";
17
+ }
18
+ return value;
19
+ }
20
+ static openAddWidgetWindow() {
21
+ ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.APP, this.OPEN_ADD_WIDGET_WINDOW);
22
+ }
23
+ static openSettingWindow() {
24
+ ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.APP, this.OPEN_SETTING_WINDOW);
25
+ }
26
+ }
27
+ exports.AppApi = AppApi;
28
+ AppApi.SET_CONFIG = "SET_CONFIG";
29
+ AppApi.GET_CONFIG = "GET_CONFIG";
30
+ AppApi.OPEN_ADD_WIDGET_WINDOW = "open-add-widget-window";
31
+ AppApi.OPEN_SETTING_WINDOW = "open-setting-window";
@@ -1,20 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BroadcastApi = void 0;
4
- const ElectronUtils_1 = require("../utils/ElectronUtils");
5
- const Channel_1 = require("./Channel");
6
- const ElectronApi_1 = require("./ElectronApi");
7
- class BroadcastApi {
8
- static async sendBroadcastEvent(event) {
9
- await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.BROADCAST, JSON.stringify(event));
10
- }
11
- static async registerBroadcast(callback) {
12
- await ElectronApi_1.ElectronApi.addIpcListener(Channel_1.Channel.BROADCAST, (json) => {
13
- callback(JSON.parse(json));
14
- });
15
- }
16
- static async unregisterBroadcast() {
17
- await ElectronApi_1.ElectronApi.removeIpcListener(Channel_1.Channel.BROADCAST);
18
- }
19
- }
20
- exports.BroadcastApi = BroadcastApi;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BroadcastApi = void 0;
4
+ const ElectronUtils_1 = require("../utils/ElectronUtils");
5
+ const Channel_1 = require("./Channel");
6
+ const ElectronApi_1 = require("./ElectronApi");
7
+ class BroadcastApi {
8
+ static async sendBroadcastEvent(event) {
9
+ await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.BROADCAST, JSON.stringify(event));
10
+ }
11
+ static async registerBroadcast(callback) {
12
+ await ElectronApi_1.ElectronApi.addIpcListener(Channel_1.Channel.BROADCAST, (json) => {
13
+ callback(JSON.parse(json));
14
+ });
15
+ }
16
+ static async unregisterBroadcast() {
17
+ await ElectronApi_1.ElectronApi.removeIpcListener(Channel_1.Channel.BROADCAST);
18
+ }
19
+ }
20
+ exports.BroadcastApi = BroadcastApi;
@@ -1,24 +1,42 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BrowserWindowApi = void 0;
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.getAPI().invoke(Channel_1.Channel.BROWSER_WINDOW, this.IGNORE_MOUSE_EVENT, ignore);
9
- }
10
- static async setWindowVisibility(show) {
11
- await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.BROWSER_WINDOW, this.WINDOW_VISIBILITY, show);
12
- }
13
- static async setAlwaysOnTop(alwaysOnTop) {
14
- await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.BROWSER_WINDOW, this.ALWAYS_ON_TOP, alwaysOnTop);
15
- }
16
- static async openUrl(url) {
17
- await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.BROWSER_WINDOW, this.OPEN_URL, url);
18
- }
19
- }
20
- exports.BrowserWindowApi = BrowserWindowApi;
21
- BrowserWindowApi.IGNORE_MOUSE_EVENT = "ignore-mouse-event";
22
- BrowserWindowApi.WINDOW_VISIBILITY = "window-visibility";
23
- BrowserWindowApi.ALWAYS_ON_TOP = "always-on-top";
24
- BrowserWindowApi.OPEN_URL = "open-url";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BrowserWindowApi = void 0;
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.getAPI().invoke(Channel_1.Channel.BROWSER_WINDOW, this.IGNORE_MOUSE_EVENT, ignore);
9
+ }
10
+ static async setWindowVisibility(show) {
11
+ await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.BROWSER_WINDOW, this.WINDOW_VISIBILITY, show);
12
+ }
13
+ static async setAlwaysOnTop(alwaysOnTop) {
14
+ await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.BROWSER_WINDOW, this.ALWAYS_ON_TOP, alwaysOnTop);
15
+ }
16
+ static async isAlwaysOnTop() {
17
+ return await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.BROWSER_WINDOW, this.IS_ALWAYS_ON_TOP);
18
+ }
19
+ static async openUrl(url) {
20
+ await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.BROWSER_WINDOW, this.OPEN_URL, url);
21
+ }
22
+ /**
23
+ * 设置窗口位置
24
+ * @param x
25
+ * @param y
26
+ * @param animation 动画只在mac系统有效
27
+ */
28
+ static async setPosition(x, y, animation) {
29
+ await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.BROWSER_WINDOW, this.SET_POSITION, x, y, animation);
30
+ }
31
+ static async getPosition() {
32
+ return await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.BROWSER_WINDOW, this.GET_POSITION);
33
+ }
34
+ }
35
+ exports.BrowserWindowApi = BrowserWindowApi;
36
+ BrowserWindowApi.IGNORE_MOUSE_EVENT = "ignore-mouse-event";
37
+ BrowserWindowApi.WINDOW_VISIBILITY = "window-visibility";
38
+ BrowserWindowApi.ALWAYS_ON_TOP = "always-on-top";
39
+ BrowserWindowApi.IS_ALWAYS_ON_TOP = "is-always-on-top";
40
+ BrowserWindowApi.OPEN_URL = "open-url";
41
+ BrowserWindowApi.SET_POSITION = "set-position";
42
+ BrowserWindowApi.GET_POSITION = "get-position";
@@ -1,11 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Channel = void 0;
4
- var Channel;
5
- (function (Channel) {
6
- Channel["NOTIFICATION"] = "channel::fun.zujian.core.notification";
7
- Channel["BROWSER_WINDOW"] = "channel::fun.zujian.core.browser_window";
8
- Channel["BROADCAST"] = "channel::fun.zujian.core.broadcast";
9
- Channel["WIDGET"] = "channel::fun.zujian.core.widget";
10
- Channel["APP"] = "channel::fun.zujian.core.app";
11
- })(Channel = exports.Channel || (exports.Channel = {}));
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Channel = void 0;
4
+ var Channel;
5
+ (function (Channel) {
6
+ Channel["NOTIFICATION"] = "channel::cn.widgetjs.core.notification";
7
+ Channel["BROWSER_WINDOW"] = "channel::cn.widgetjs.core.browser_window";
8
+ Channel["BROADCAST"] = "channel::cn.widgetjs.core.broadcast";
9
+ Channel["WIDGET"] = "channel::cn.widgetjs.core.widget";
10
+ Channel["APP"] = "channel::cn.widgetjs.core.app";
11
+ })(Channel = exports.Channel || (exports.Channel = {}));
@@ -1,13 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ElectronApi = void 0;
4
- const ElectronUtils_1 = require("../utils/ElectronUtils");
5
- class ElectronApi {
6
- static async addIpcListener(key, f) {
7
- await ElectronUtils_1.ElectronUtils.getAPI().addIpcListener(key, f);
8
- }
9
- static async removeIpcListener(key) {
10
- await ElectronUtils_1.ElectronUtils.getAPI().removeIpcListener(key);
11
- }
12
- }
13
- exports.ElectronApi = ElectronApi;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ElectronApi = void 0;
4
+ const ElectronUtils_1 = require("../utils/ElectronUtils");
5
+ class ElectronApi {
6
+ static async addIpcListener(key, f) {
7
+ await ElectronUtils_1.ElectronUtils.getAPI().addIpcListener(key, f);
8
+ }
9
+ static async removeIpcListener(key) {
10
+ await ElectronUtils_1.ElectronUtils.getAPI().removeIpcListener(key);
11
+ }
12
+ }
13
+ exports.ElectronApi = ElectronApi;
@@ -1,83 +1,83 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NotificationApi = void 0;
4
- const Notification_1 = require("../model/Notification");
5
- const Channel_1 = require("./Channel");
6
- const ElectronUtils_1 = require("../utils/ElectronUtils");
7
- class NotificationApi {
8
- static async call(duration = 5000) {
9
- ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.NOTIFICATION, new Notification_1.Notification({
10
- title: "章鱼哥",
11
- type: "call",
12
- message: "下班提醒",
13
- duration: duration
14
- }));
15
- }
16
- static async advanceCountdown(message, targetTime, title) {
17
- ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.NOTIFICATION, new Notification_1.Notification({
18
- title,
19
- message,
20
- targetTime,
21
- type: "advance-countdown"
22
- }));
23
- }
24
- static async countdown(message, targetTime) {
25
- ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.NOTIFICATION, new Notification_1.Notification({
26
- message,
27
- targetTime,
28
- type: "countdown"
29
- }));
30
- }
31
- static async success(message, duration = 5000) {
32
- if (ElectronUtils_1.ElectronUtils.hasElectronApi()) {
33
- ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.NOTIFICATION, new Notification_1.Notification({
34
- message,
35
- type: "success",
36
- duration
37
- }));
38
- }
39
- else {
40
- this.callback("success", message, duration);
41
- }
42
- }
43
- static async error(message, duration = 5000) {
44
- if (ElectronUtils_1.ElectronUtils.hasElectronApi()) {
45
- ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.NOTIFICATION, new Notification_1.Notification({
46
- message,
47
- type: "error",
48
- duration
49
- }));
50
- }
51
- else {
52
- this.callback("error", message, duration);
53
- }
54
- }
55
- static async warning(message, duration = 5000) {
56
- if (ElectronUtils_1.ElectronUtils.hasElectronApi()) {
57
- ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.NOTIFICATION, new Notification_1.Notification({
58
- message,
59
- type: "warning",
60
- duration
61
- }));
62
- }
63
- else {
64
- this.callback("warning", message, duration);
65
- }
66
- }
67
- static async message(message, duration = 5000) {
68
- if (ElectronUtils_1.ElectronUtils.hasElectronApi()) {
69
- ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.NOTIFICATION, new Notification_1.Notification({
70
- message,
71
- type: "message",
72
- duration
73
- }));
74
- }
75
- else {
76
- this.callback("message", message, duration);
77
- }
78
- }
79
- static setDebugNotification(callback) {
80
- this.callback = callback;
81
- }
82
- }
83
- exports.NotificationApi = NotificationApi;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotificationApi = void 0;
4
+ const Notification_1 = require("../model/Notification");
5
+ const Channel_1 = require("./Channel");
6
+ const ElectronUtils_1 = require("../utils/ElectronUtils");
7
+ class NotificationApi {
8
+ static async call(duration = 5000) {
9
+ ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.NOTIFICATION, new Notification_1.Notification({
10
+ title: "章鱼哥",
11
+ type: "call",
12
+ message: "下班提醒",
13
+ duration: duration
14
+ }));
15
+ }
16
+ static async advanceCountdown(message, targetTime, title) {
17
+ ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.NOTIFICATION, new Notification_1.Notification({
18
+ title,
19
+ message,
20
+ targetTime,
21
+ type: "advance-countdown"
22
+ }));
23
+ }
24
+ static async countdown(message, targetTime) {
25
+ ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.NOTIFICATION, new Notification_1.Notification({
26
+ message,
27
+ targetTime,
28
+ type: "countdown"
29
+ }));
30
+ }
31
+ static async success(message, duration = 5000) {
32
+ if (ElectronUtils_1.ElectronUtils.hasElectronApi()) {
33
+ ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.NOTIFICATION, new Notification_1.Notification({
34
+ message,
35
+ type: "success",
36
+ duration
37
+ }));
38
+ }
39
+ else {
40
+ this.callback("success", message, duration);
41
+ }
42
+ }
43
+ static async error(message, duration = 5000) {
44
+ if (ElectronUtils_1.ElectronUtils.hasElectronApi()) {
45
+ ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.NOTIFICATION, new Notification_1.Notification({
46
+ message,
47
+ type: "error",
48
+ duration
49
+ }));
50
+ }
51
+ else {
52
+ this.callback("error", message, duration);
53
+ }
54
+ }
55
+ static async warning(message, duration = 5000) {
56
+ if (ElectronUtils_1.ElectronUtils.hasElectronApi()) {
57
+ ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.NOTIFICATION, new Notification_1.Notification({
58
+ message,
59
+ type: "warning",
60
+ duration
61
+ }));
62
+ }
63
+ else {
64
+ this.callback("warning", message, duration);
65
+ }
66
+ }
67
+ static async message(message, duration = 5000) {
68
+ if (ElectronUtils_1.ElectronUtils.hasElectronApi()) {
69
+ ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.NOTIFICATION, new Notification_1.Notification({
70
+ message,
71
+ type: "message",
72
+ duration
73
+ }));
74
+ }
75
+ else {
76
+ this.callback("message", message, duration);
77
+ }
78
+ }
79
+ static setDebugNotification(callback) {
80
+ this.callback = callback;
81
+ }
82
+ }
83
+ exports.NotificationApi = NotificationApi;
@@ -1,49 +1,58 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WidgetApi = void 0;
4
- const Widget_1 = require("../model/Widget");
5
- const ElectronUtils_1 = require("../utils/ElectronUtils");
6
- const Channel_1 = require("./Channel");
7
- class WidgetApi {
8
- static async registerWidgets(widgets) {
9
- await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.WIDGET, this.REGISTER_WIDGETS, JSON.stringify(widgets));
10
- }
11
- static async registerWidgetPackage(widgetPackage) {
12
- await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.WIDGET, this.REGISTER_WIDGET_PACKAGE, JSON.stringify(widgetPackage));
13
- }
14
- static async getWidgets() {
15
- const data = await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.WIDGET, this.GET_WIDGETS);
16
- const widgets = [];
17
- if (data) {
18
- const arr = JSON.parse(data);
19
- for (const i in arr) {
20
- widgets.push(Widget_1.Widget.parseObject(arr[i]));
21
- }
22
- }
23
- return widgets;
24
- }
25
- static async getWidgetPackages() {
26
- return await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.WIDGET, this.GET_WIDGET_PACKAGES);
27
- }
28
- /**
29
- *
30
- * @param name package name
31
- */
32
- static async getWidget(name) {
33
- return await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.WIDGET, this.GET_WIDGET, name);
34
- }
35
- /**
36
- *
37
- * @param name package name
38
- */
39
- static async getWidgetPackage(name) {
40
- return await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.WIDGET, this.GET_WIDGET_PACKAGE, name);
41
- }
42
- }
43
- exports.WidgetApi = WidgetApi;
44
- WidgetApi.REGISTER_WIDGETS = "register-widgets";
45
- WidgetApi.REGISTER_WIDGET_PACKAGE = "register-widget-package";
46
- WidgetApi.GET_WIDGETS = "get-widgets";
47
- WidgetApi.GET_WIDGET = "get-widget";
48
- WidgetApi.GET_WIDGET_PACKAGE = "get-widget-package";
49
- WidgetApi.GET_WIDGET_PACKAGES = "get-widget-packages";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WidgetApi = void 0;
4
+ const Widget_1 = require("../model/Widget");
5
+ const ElectronUtils_1 = require("../utils/ElectronUtils");
6
+ const WidgetPackage_1 = require("../model/WidgetPackage");
7
+ const Channel_1 = require("./Channel");
8
+ class WidgetApi {
9
+ static async registerWidgets(widgets) {
10
+ await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.WIDGET, this.REGISTER_WIDGETS, JSON.stringify(widgets));
11
+ }
12
+ static async registerWidgetPackage(widgetPackage) {
13
+ await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.WIDGET, this.REGISTER_WIDGET_PACKAGE, JSON.stringify(widgetPackage));
14
+ }
15
+ static async getWidgets() {
16
+ const data = await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.WIDGET, this.GET_WIDGETS);
17
+ const widgets = [];
18
+ if (data) {
19
+ const arr = JSON.parse(data);
20
+ for (const i in arr) {
21
+ widgets.push(Widget_1.Widget.parseObject(arr[i]));
22
+ }
23
+ }
24
+ return widgets;
25
+ }
26
+ static async getWidgetPackages() {
27
+ return await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.WIDGET, this.GET_WIDGET_PACKAGES);
28
+ }
29
+ /**
30
+ *
31
+ * @param name package name
32
+ */
33
+ static async getWidget(name) {
34
+ return Widget_1.Widget.parseObject(await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.WIDGET, this.GET_WIDGET, name));
35
+ }
36
+ /**
37
+ *
38
+ * @param name package name
39
+ */
40
+ static async getWidgetPackage(name) {
41
+ return WidgetPackage_1.WidgetPackage.parseObject(await ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.WIDGET, this.GET_WIDGET_PACKAGE, name));
42
+ }
43
+ /**
44
+ * 移除组件
45
+ * @param id
46
+ */
47
+ static async removeHostedWidget(id) {
48
+ return ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.WIDGET, this.REMOVE_HOSTED_WIDGET, id);
49
+ }
50
+ }
51
+ exports.WidgetApi = WidgetApi;
52
+ WidgetApi.REGISTER_WIDGETS = "register-widgets";
53
+ WidgetApi.REGISTER_WIDGET_PACKAGE = "register-widget-package";
54
+ WidgetApi.GET_WIDGETS = "get-widgets";
55
+ WidgetApi.GET_WIDGET = "get-widget";
56
+ WidgetApi.GET_WIDGET_PACKAGE = "get-widget-package";
57
+ WidgetApi.GET_WIDGET_PACKAGES = "get-widget-packages";
58
+ WidgetApi.REMOVE_HOSTED_WIDGET = "remove-hosted-widget";
package/dist/cjs/index.js CHANGED
@@ -1,34 +1,35 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./model/Widget"), exports);
18
- __exportStar(require("./model/event/BroadcastEvent"), exports);
19
- __exportStar(require("./model/event/WebSocketEvent"), exports);
20
- __exportStar(require("./model/WidgetData"), exports);
21
- __exportStar(require("./model/WidgetParams"), exports);
22
- __exportStar(require("./model/Notification"), exports);
23
- __exportStar(require("./model/WidgetPackage"), exports);
24
- __exportStar(require("./api/ElectronApi"), exports);
25
- __exportStar(require("./repository/WidgetDataRepository"), exports);
26
- __exportStar(require("./api/BrowserWindowApi"), exports);
27
- __exportStar(require("./api/NotificationApi"), exports);
28
- __exportStar(require("./api/Channel"), exports);
29
- __exportStar(require("./api/WidgetApi"), exports);
30
- __exportStar(require("./api/ApiConstants"), exports);
31
- __exportStar(require("./api/BroadcastApi"), exports);
32
- __exportStar(require("./api/AppApi"), exports);
33
- __exportStar(require("./utils/ElectronUtils"), exports);
34
- __exportStar(require("./router/query"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./model/Widget"), exports);
18
+ __exportStar(require("./model/event/BroadcastEvent"), exports);
19
+ __exportStar(require("./model/event/WebSocketEvent"), exports);
20
+ __exportStar(require("./model/WidgetData"), exports);
21
+ __exportStar(require("./model/WidgetParams"), exports);
22
+ __exportStar(require("./model/Notification"), exports);
23
+ __exportStar(require("./model/HostedMode"), exports);
24
+ __exportStar(require("./model/WidgetPackage"), exports);
25
+ __exportStar(require("./api/ElectronApi"), exports);
26
+ __exportStar(require("./repository/WidgetDataRepository"), exports);
27
+ __exportStar(require("./api/BrowserWindowApi"), exports);
28
+ __exportStar(require("./api/NotificationApi"), exports);
29
+ __exportStar(require("./api/Channel"), exports);
30
+ __exportStar(require("./api/WidgetApi"), exports);
31
+ __exportStar(require("./api/ApiConstants"), exports);
32
+ __exportStar(require("./api/BroadcastApi"), exports);
33
+ __exportStar(require("./api/AppApi"), exports);
34
+ __exportStar(require("./utils/ElectronUtils"), exports);
35
+ __exportStar(require("./router/query"), exports);