@widget-js/core 0.1.14 → 0.1.16
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.
- package/dist/cjs/api/AppApi.js +8 -4
- package/dist/cjs/api/BroadcastApi.js +2 -1
- package/dist/cjs/api/BrowserWindowApi.js +37 -12
- package/dist/cjs/api/Channel.js +2 -0
- package/dist/cjs/api/DialogApi.js +2 -1
- package/dist/cjs/api/ElectronApi.js +4 -2
- package/dist/cjs/api/NotificationApi.js +55 -15
- package/dist/cjs/api/WidgetApi.js +29 -7
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/model/AppNotification.js +32 -0
- package/dist/cjs/model/WidgetPackage.js +3 -5
- package/dist/cjs/model/WidgetParams.js +6 -2
- package/dist/cjs/model/event/AppKeyboardEvent.js +2 -0
- package/dist/cjs/model/event/AppMouseEvent.js +2 -0
- package/dist/cjs/utils/UrlUtils.js +15 -0
- package/dist/esm/api/AppApi.js +8 -4
- package/dist/esm/api/BroadcastApi.js +2 -1
- package/dist/esm/api/BrowserWindowApi.js +37 -12
- package/dist/esm/api/Channel.js +2 -0
- package/dist/esm/api/DialogApi.js +2 -1
- package/dist/esm/api/ElectronApi.js +4 -2
- package/dist/esm/api/NotificationApi.js +55 -15
- package/dist/esm/api/WidgetApi.js +29 -7
- package/dist/esm/index.js +3 -1
- package/dist/esm/model/AppNotification.js +28 -0
- package/dist/esm/model/WidgetPackage.js +3 -5
- package/dist/esm/model/WidgetParams.js +6 -2
- package/dist/esm/model/event/AppKeyboardEvent.js +1 -0
- package/dist/esm/model/event/AppMouseEvent.js +1 -0
- package/dist/esm/utils/UrlUtils.js +15 -0
- package/dist/types/api/BrowserWindowApi.d.ts +7 -0
- package/dist/types/api/Channel.d.ts +2 -0
- package/dist/types/api/NotificationApi.d.ts +15 -3
- package/dist/types/api/WidgetApi.d.ts +2 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/model/AppNotification.d.ts +49 -0
- package/dist/types/model/WidgetPackage.d.ts +1 -1
- package/dist/types/model/event/AppKeyboardEvent.d.ts +16 -0
- package/dist/types/model/event/AppMouseEvent.d.ts +14 -0
- package/dist/types/utils/UrlUtils.d.ts +1 -0
- package/dist/umd/index.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/model/Notification.js +0 -15
- package/dist/esm/model/Notification.js +0 -11
- package/dist/types/model/Notification.d.ts +0 -16
package/dist/cjs/api/AppApi.js
CHANGED
|
@@ -5,10 +5,12 @@ const ElectronUtils_1 = require("../utils/ElectronUtils");
|
|
|
5
5
|
const Channel_1 = require("./Channel");
|
|
6
6
|
class AppApi {
|
|
7
7
|
static async setConfig(key, value) {
|
|
8
|
-
|
|
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));
|
|
9
10
|
}
|
|
10
11
|
static async getConfig(key, defaultValue) {
|
|
11
|
-
|
|
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));
|
|
12
14
|
if (value === null || value === undefined) {
|
|
13
15
|
return defaultValue;
|
|
14
16
|
}
|
|
@@ -18,10 +20,12 @@ class AppApi {
|
|
|
18
20
|
return value;
|
|
19
21
|
}
|
|
20
22
|
static openAddWidgetWindow() {
|
|
21
|
-
|
|
23
|
+
var _a;
|
|
24
|
+
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.APP, this.OPEN_ADD_WIDGET_WINDOW);
|
|
22
25
|
}
|
|
23
26
|
static openSettingWindow() {
|
|
24
|
-
|
|
27
|
+
var _a;
|
|
28
|
+
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.APP, this.OPEN_SETTING_WINDOW);
|
|
25
29
|
}
|
|
26
30
|
}
|
|
27
31
|
exports.AppApi = AppApi;
|
|
@@ -6,7 +6,8 @@ const Channel_1 = require("./Channel");
|
|
|
6
6
|
const ElectronApi_1 = require("./ElectronApi");
|
|
7
7
|
class BroadcastApi {
|
|
8
8
|
static async sendBroadcastEvent(event) {
|
|
9
|
-
|
|
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)));
|
|
10
11
|
}
|
|
11
12
|
static async registerBroadcast(callback) {
|
|
12
13
|
await ElectronApi_1.ElectronApi.addIpcListener(Channel_1.Channel.BROADCAST, (json) => {
|
|
@@ -5,19 +5,36 @@ const Channel_1 = require("./Channel");
|
|
|
5
5
|
const ElectronUtils_1 = require("../utils/ElectronUtils");
|
|
6
6
|
class BrowserWindowApi {
|
|
7
7
|
static async setIgnoreMouseEvent(ignore) {
|
|
8
|
-
|
|
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));
|
|
9
10
|
}
|
|
11
|
+
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));
|
|
14
|
+
}
|
|
15
|
+
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));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated
|
|
21
|
+
* @param show
|
|
22
|
+
*/
|
|
10
23
|
static async setWindowVisibility(show) {
|
|
11
|
-
|
|
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));
|
|
12
26
|
}
|
|
13
27
|
static async setAlwaysOnTop(alwaysOnTop) {
|
|
14
|
-
|
|
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));
|
|
15
30
|
}
|
|
16
31
|
static async isAlwaysOnTop() {
|
|
17
|
-
|
|
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));
|
|
18
34
|
}
|
|
19
35
|
static async openUrl(url) {
|
|
20
|
-
|
|
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));
|
|
21
38
|
}
|
|
22
39
|
/**
|
|
23
40
|
* 设置窗口位置
|
|
@@ -26,29 +43,36 @@ class BrowserWindowApi {
|
|
|
26
43
|
* @param animation 动画只在mac系统有效
|
|
27
44
|
*/
|
|
28
45
|
static async setPosition(x, y, animation) {
|
|
29
|
-
|
|
46
|
+
var _a;
|
|
47
|
+
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));
|
|
30
48
|
}
|
|
31
49
|
static async getPosition() {
|
|
32
|
-
|
|
50
|
+
var _a;
|
|
51
|
+
return await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.GET_POSITION));
|
|
33
52
|
}
|
|
34
53
|
static async blur() {
|
|
35
|
-
|
|
54
|
+
var _a;
|
|
55
|
+
return await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.BLUR));
|
|
36
56
|
}
|
|
37
57
|
static async focus() {
|
|
38
|
-
|
|
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.FOCUS));
|
|
39
60
|
}
|
|
40
61
|
/**
|
|
41
62
|
* 设置窗口是否可以拉伸
|
|
42
63
|
* @param resizable
|
|
43
64
|
*/
|
|
44
65
|
static async setResizable(resizable) {
|
|
45
|
-
|
|
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.SET_RESIZABLE, resizable));
|
|
46
68
|
}
|
|
47
69
|
static async getBounds() {
|
|
48
|
-
|
|
70
|
+
var _a;
|
|
71
|
+
return await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.GET_BOUNDS));
|
|
49
72
|
}
|
|
50
73
|
static async setBounds(bounds, animate) {
|
|
51
|
-
|
|
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_BOUNDS, bounds, animate));
|
|
52
76
|
}
|
|
53
77
|
}
|
|
54
78
|
exports.BrowserWindowApi = BrowserWindowApi;
|
|
@@ -64,3 +88,4 @@ BrowserWindowApi.FOCUS = "focus";
|
|
|
64
88
|
BrowserWindowApi.SET_RESIZABLE = "set-resizable";
|
|
65
89
|
BrowserWindowApi.GET_BOUNDS = "get-bounds";
|
|
66
90
|
BrowserWindowApi.SET_BOUNDS = "set-bounds";
|
|
91
|
+
BrowserWindowApi.SHOW = "show";
|
package/dist/cjs/api/Channel.js
CHANGED
|
@@ -8,5 +8,7 @@ var Channel;
|
|
|
8
8
|
Channel["BROADCAST"] = "channel::cn.widgetjs.core.broadcast";
|
|
9
9
|
Channel["WIDGET"] = "channel::cn.widgetjs.core.widget";
|
|
10
10
|
Channel["APP"] = "channel::cn.widgetjs.core.app";
|
|
11
|
+
Channel["MOUSE_EVENT"] = "channel::cn.widgetjs.core.mouse_event";
|
|
12
|
+
Channel["KEYBOARD_EVENT"] = "channel::cn.widgetjs.core.keyboard_event";
|
|
11
13
|
Channel["DIALOG"] = "channel::cn.widgetjs.core.dialog";
|
|
12
14
|
})(Channel = exports.Channel || (exports.Channel = {}));
|
|
@@ -9,7 +9,8 @@ class DialogApi {
|
|
|
9
9
|
* @param extensions 允许的文件后缀格式,如:["txt","docx","gif"]
|
|
10
10
|
*/
|
|
11
11
|
static async pickFile(extensions) {
|
|
12
|
-
|
|
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));
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
exports.DialogApi = DialogApi;
|
|
@@ -4,10 +4,12 @@ exports.ElectronApi = void 0;
|
|
|
4
4
|
const ElectronUtils_1 = require("../utils/ElectronUtils");
|
|
5
5
|
class ElectronApi {
|
|
6
6
|
static async addIpcListener(key, f) {
|
|
7
|
-
|
|
7
|
+
var _a;
|
|
8
|
+
await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.addIpcListener(key, f));
|
|
8
9
|
}
|
|
9
10
|
static async removeIpcListener(key) {
|
|
10
|
-
|
|
11
|
+
var _a;
|
|
12
|
+
await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.removeIpcListener(key));
|
|
11
13
|
}
|
|
12
14
|
}
|
|
13
15
|
exports.ElectronApi = ElectronApi;
|
|
@@ -1,20 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NotificationApi = void 0;
|
|
4
|
-
const
|
|
4
|
+
const AppNotification_1 = require("../model/AppNotification");
|
|
5
5
|
const Channel_1 = require("./Channel");
|
|
6
6
|
const ElectronUtils_1 = require("../utils/ElectronUtils");
|
|
7
7
|
class NotificationApi {
|
|
8
|
-
static async
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
// static async url(url: string, duration: number = -1) {
|
|
9
|
+
// ElectronUtils.getAPI()?.invoke(Channel.NOTIFICATION, new AppNotification({
|
|
10
|
+
// url, message: "",
|
|
11
|
+
// duration,
|
|
12
|
+
// type: "url",
|
|
13
|
+
// }));
|
|
14
|
+
// }
|
|
15
|
+
/**
|
|
16
|
+
* 来电
|
|
17
|
+
* @param avatar 头像地址
|
|
18
|
+
* @param audio 音频地址
|
|
19
|
+
* @param title 标题文件
|
|
20
|
+
* @param message 初始消息
|
|
21
|
+
* @param lyric 歌词字符串
|
|
22
|
+
*/
|
|
23
|
+
static async call(avatar, audio, title, message, lyric) {
|
|
24
|
+
var _a;
|
|
25
|
+
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, new AppNotification_1.AppNotification({
|
|
26
|
+
avatar,
|
|
27
|
+
audio,
|
|
28
|
+
message,
|
|
29
|
+
title,
|
|
30
|
+
duration: -1,
|
|
31
|
+
lyric,
|
|
11
32
|
type: "call",
|
|
12
|
-
message: "下班提醒",
|
|
13
|
-
duration: duration
|
|
14
33
|
}));
|
|
15
34
|
}
|
|
16
35
|
static async advanceCountdown(message, targetTime, title) {
|
|
17
|
-
|
|
36
|
+
var _a;
|
|
37
|
+
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, new AppNotification_1.AppNotification({
|
|
18
38
|
title,
|
|
19
39
|
message,
|
|
20
40
|
targetTime,
|
|
@@ -22,17 +42,22 @@ class NotificationApi {
|
|
|
22
42
|
}));
|
|
23
43
|
}
|
|
24
44
|
static async countdown(message, targetTime) {
|
|
25
|
-
|
|
45
|
+
var _a;
|
|
46
|
+
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, new AppNotification_1.AppNotification({
|
|
26
47
|
message,
|
|
27
48
|
targetTime,
|
|
49
|
+
backgroundColor: 'rgba(0,0,0,0.5)',
|
|
50
|
+
duration: -1,
|
|
28
51
|
type: "countdown"
|
|
29
52
|
}));
|
|
30
53
|
}
|
|
31
54
|
static async success(message, duration = 5000) {
|
|
55
|
+
var _a;
|
|
32
56
|
if (ElectronUtils_1.ElectronUtils.hasElectronApi()) {
|
|
33
|
-
ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.NOTIFICATION, new
|
|
57
|
+
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, new AppNotification_1.AppNotification({
|
|
34
58
|
message,
|
|
35
59
|
type: "success",
|
|
60
|
+
icon: "check_circle_line",
|
|
36
61
|
duration
|
|
37
62
|
}));
|
|
38
63
|
}
|
|
@@ -41,10 +66,12 @@ class NotificationApi {
|
|
|
41
66
|
}
|
|
42
67
|
}
|
|
43
68
|
static async error(message, duration = 5000) {
|
|
69
|
+
var _a;
|
|
44
70
|
if (ElectronUtils_1.ElectronUtils.hasElectronApi()) {
|
|
45
|
-
ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.NOTIFICATION, new
|
|
71
|
+
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, new AppNotification_1.AppNotification({
|
|
46
72
|
message,
|
|
47
73
|
type: "error",
|
|
74
|
+
icon: "close_circle_line",
|
|
48
75
|
duration
|
|
49
76
|
}));
|
|
50
77
|
}
|
|
@@ -53,10 +80,12 @@ class NotificationApi {
|
|
|
53
80
|
}
|
|
54
81
|
}
|
|
55
82
|
static async warning(message, duration = 5000) {
|
|
83
|
+
var _a;
|
|
56
84
|
if (ElectronUtils_1.ElectronUtils.hasElectronApi()) {
|
|
57
|
-
ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.NOTIFICATION, new
|
|
85
|
+
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, new AppNotification_1.AppNotification({
|
|
58
86
|
message,
|
|
59
87
|
type: "warning",
|
|
88
|
+
icon: "warning_line",
|
|
60
89
|
duration
|
|
61
90
|
}));
|
|
62
91
|
}
|
|
@@ -64,16 +93,27 @@ class NotificationApi {
|
|
|
64
93
|
this.callback("warning", message, duration);
|
|
65
94
|
}
|
|
66
95
|
}
|
|
67
|
-
static async
|
|
96
|
+
static async info(message, duration = 5000) {
|
|
97
|
+
var _a;
|
|
68
98
|
if (ElectronUtils_1.ElectronUtils.hasElectronApi()) {
|
|
69
|
-
ElectronUtils_1.ElectronUtils.getAPI().invoke(Channel_1.Channel.NOTIFICATION, new
|
|
99
|
+
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, new AppNotification_1.AppNotification({
|
|
70
100
|
message,
|
|
71
|
-
type: "
|
|
101
|
+
type: "info",
|
|
102
|
+
icon: "information_line",
|
|
72
103
|
duration
|
|
73
104
|
}));
|
|
74
105
|
}
|
|
75
106
|
else {
|
|
76
|
-
this.callback("
|
|
107
|
+
this.callback("info", message, duration);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 隐藏通知
|
|
112
|
+
*/
|
|
113
|
+
static async hide() {
|
|
114
|
+
var _a;
|
|
115
|
+
if (ElectronUtils_1.ElectronUtils.hasElectronApi()) {
|
|
116
|
+
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, null);
|
|
77
117
|
}
|
|
78
118
|
}
|
|
79
119
|
static setDebugNotification(callback) {
|
|
@@ -14,13 +14,16 @@ const BroadcastApi_1 = require("./BroadcastApi");
|
|
|
14
14
|
const localforage_1 = __importDefault(require("localforage"));
|
|
15
15
|
class WidgetApi {
|
|
16
16
|
static async registerWidgets(widgets) {
|
|
17
|
-
|
|
17
|
+
var _a;
|
|
18
|
+
await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.WIDGET, this.REGISTER_WIDGETS, JSON.stringify(widgets)));
|
|
18
19
|
}
|
|
19
20
|
static async registerWidgetPackage(widgetPackage) {
|
|
20
|
-
|
|
21
|
+
var _a;
|
|
22
|
+
await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.WIDGET, this.REGISTER_WIDGET_PACKAGE, JSON.stringify(widgetPackage)));
|
|
21
23
|
}
|
|
22
24
|
static async getWidgets() {
|
|
23
|
-
|
|
25
|
+
var _a;
|
|
26
|
+
const data = await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.WIDGET, this.GET_WIDGETS));
|
|
24
27
|
const widgets = [];
|
|
25
28
|
if (data) {
|
|
26
29
|
const arr = JSON.parse(data);
|
|
@@ -31,28 +34,32 @@ class WidgetApi {
|
|
|
31
34
|
return widgets;
|
|
32
35
|
}
|
|
33
36
|
static async getWidgetPackages() {
|
|
34
|
-
|
|
37
|
+
var _a;
|
|
38
|
+
return await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.WIDGET, this.GET_WIDGET_PACKAGES));
|
|
35
39
|
}
|
|
36
40
|
/**
|
|
37
41
|
*
|
|
38
42
|
* @param name package name
|
|
39
43
|
*/
|
|
40
44
|
static async getWidget(name) {
|
|
41
|
-
|
|
45
|
+
var _a;
|
|
46
|
+
return Widget_1.Widget.parseObject(await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.WIDGET, this.GET_WIDGET, name)));
|
|
42
47
|
}
|
|
43
48
|
/**
|
|
44
49
|
*
|
|
45
50
|
* @param name package name
|
|
46
51
|
*/
|
|
47
52
|
static async getWidgetPackage(name) {
|
|
48
|
-
|
|
53
|
+
var _a;
|
|
54
|
+
return WidgetPackage_1.WidgetPackage.parseObject(await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.WIDGET, this.GET_WIDGET_PACKAGE, name)));
|
|
49
55
|
}
|
|
50
56
|
/**
|
|
51
57
|
* 移除组件
|
|
52
58
|
* @param id
|
|
53
59
|
*/
|
|
54
60
|
static async removeHostedWidget(id) {
|
|
55
|
-
|
|
61
|
+
var _a;
|
|
62
|
+
return (_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.WIDGET, this.REMOVE_HOSTED_WIDGET, id);
|
|
56
63
|
}
|
|
57
64
|
/**
|
|
58
65
|
* 获取组件配置地址
|
|
@@ -67,6 +74,21 @@ class WidgetApi {
|
|
|
67
74
|
return null;
|
|
68
75
|
return UrlUtils_1.UrlUtils.getWidgetUrl(widget.configUrl, widgetPackage, widgetParams);
|
|
69
76
|
}
|
|
77
|
+
static async getWidgetUrl(widgetName, widgetParams) {
|
|
78
|
+
const widget = await this.getWidget(widgetName);
|
|
79
|
+
if (!widget || widget.configUrl == null)
|
|
80
|
+
return null;
|
|
81
|
+
const widgetPackage = await this.getWidgetPackage(widget.packageName);
|
|
82
|
+
if (!widgetPackage)
|
|
83
|
+
return null;
|
|
84
|
+
return UrlUtils_1.UrlUtils.getWidgetUrl(widget.url, widgetPackage, widgetParams);
|
|
85
|
+
}
|
|
86
|
+
static async getWidgetPackageUrl(packageName, hash) {
|
|
87
|
+
const widgetPackage = await this.getWidgetPackage(packageName);
|
|
88
|
+
if (!widgetPackage)
|
|
89
|
+
return null;
|
|
90
|
+
return widgetPackage.getFullUrl(hash);
|
|
91
|
+
}
|
|
70
92
|
/**
|
|
71
93
|
* 通过组件名保存组件信息,通常用于存储可以在同类组件中共用的数据
|
|
72
94
|
* @param data
|
package/dist/cjs/index.js
CHANGED
|
@@ -19,9 +19,11 @@ __exportStar(require("./model/event/BroadcastEvent"), exports);
|
|
|
19
19
|
__exportStar(require("./model/event/WebSocketEvent"), exports);
|
|
20
20
|
__exportStar(require("./model/WidgetData"), exports);
|
|
21
21
|
__exportStar(require("./model/WidgetParams"), exports);
|
|
22
|
-
__exportStar(require("./model/
|
|
22
|
+
__exportStar(require("./model/AppNotification"), exports);
|
|
23
23
|
__exportStar(require("./model/HostedMode"), exports);
|
|
24
24
|
__exportStar(require("./model/interface/Rectangle"), exports);
|
|
25
|
+
__exportStar(require("./model/event/AppKeyboardEvent"), exports);
|
|
26
|
+
__exportStar(require("./model/event/AppMouseEvent"), exports);
|
|
25
27
|
__exportStar(require("./model/WidgetPackage"), exports);
|
|
26
28
|
__exportStar(require("./api/ElectronApi"), exports);
|
|
27
29
|
__exportStar(require("./repository/WidgetDataRepository"), exports);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppNotification = exports.NotificationSize = void 0;
|
|
4
|
+
var NotificationSize;
|
|
5
|
+
(function (NotificationSize) {
|
|
6
|
+
NotificationSize["SMALL"] = "small";
|
|
7
|
+
NotificationSize["NORMAL"] = "normal";
|
|
8
|
+
NotificationSize["LARGE"] = "large";
|
|
9
|
+
})(NotificationSize = exports.NotificationSize || (exports.NotificationSize = {}));
|
|
10
|
+
class AppNotification {
|
|
11
|
+
constructor(option) {
|
|
12
|
+
var _a, _b, _c, _d, _e;
|
|
13
|
+
this.type = "info";
|
|
14
|
+
this.type = (_a = option.type) !== null && _a !== void 0 ? _a : "info";
|
|
15
|
+
this.title = option.title;
|
|
16
|
+
this.message = option.message;
|
|
17
|
+
this.targetTime = option.targetTime;
|
|
18
|
+
this.duration = (_b = option.duration) !== null && _b !== void 0 ? _b : 5000;
|
|
19
|
+
this.icon = option.icon;
|
|
20
|
+
this.color = (_c = option.color) !== null && _c !== void 0 ? _c : "#5D8AC8";
|
|
21
|
+
this.confirmButtonText = option.confirmButtonText;
|
|
22
|
+
this.cancelButtonText = option.cancelButtonText;
|
|
23
|
+
this.cancelBroadcast = option.cancelBroadcast;
|
|
24
|
+
this.confirmBroadcast = option.confirmBroadcast;
|
|
25
|
+
this.size = (_d = option.size) !== null && _d !== void 0 ? _d : NotificationSize.NORMAL;
|
|
26
|
+
this.audio = option.audio;
|
|
27
|
+
this.avatar = option.avatar;
|
|
28
|
+
this.lyric = option.lyric;
|
|
29
|
+
this.backgroundColor = (_e = option.backgroundColor) !== null && _e !== void 0 ? _e : '#000000';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.AppNotification = AppNotification;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WidgetPackage = void 0;
|
|
4
|
+
const UrlUtils_1 = require("../utils/UrlUtils");
|
|
4
5
|
class WidgetPackage {
|
|
5
6
|
constructor() {
|
|
6
7
|
/**
|
|
@@ -22,11 +23,8 @@ class WidgetPackage {
|
|
|
22
23
|
* 如果url是http链接,直接返回链接
|
|
23
24
|
* 如果是本地组件:file://链接,则返回 url+entry,e.g. file://C:\users\neo\desktop\index.html#
|
|
24
25
|
*/
|
|
25
|
-
getFullUrl() {
|
|
26
|
-
|
|
27
|
-
return this.url;
|
|
28
|
-
}
|
|
29
|
-
return this.url + (this.entry.startsWith("/") ? this.entry : `/${this.entry}`);
|
|
26
|
+
getFullUrl(hash) {
|
|
27
|
+
return UrlUtils_1.UrlUtils.getWidgetPackageUrl(this.url, this.entry, hash == null ? this.hash : hash);
|
|
30
28
|
}
|
|
31
29
|
}
|
|
32
30
|
exports.WidgetPackage = WidgetPackage;
|
|
@@ -35,8 +35,12 @@ class WidgetParams {
|
|
|
35
35
|
*/
|
|
36
36
|
static fromCurrentLocation() {
|
|
37
37
|
const href = window.location.href;
|
|
38
|
-
let
|
|
39
|
-
|
|
38
|
+
let strings = href.split("?");
|
|
39
|
+
if (strings.length > 1) {
|
|
40
|
+
let queryString = strings[1];
|
|
41
|
+
return this.fromObject((0, query_1.parseQuery)(queryString));
|
|
42
|
+
}
|
|
43
|
+
return new WidgetParams();
|
|
40
44
|
}
|
|
41
45
|
static setValue(widgetEnv, key, value) {
|
|
42
46
|
const keyWithoutPrefix = key.replace(this.PARAM_PREFIX, "");
|
|
@@ -17,5 +17,20 @@ class UrlUtils {
|
|
|
17
17
|
return url + "?" + widgetParams.toUrlParams().toString();
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
+
static getWidgetPackageUrl(url, entry, hash) {
|
|
21
|
+
const arr = [url];
|
|
22
|
+
if (url.startsWith("http")) {
|
|
23
|
+
if (hash) {
|
|
24
|
+
arr.push(url.endsWith("/") ? "#" : "/#");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
arr.push(entry.startsWith("/") ? entry : `/${entry}`);
|
|
29
|
+
if (hash) {
|
|
30
|
+
arr.push(url.endsWith("#") ? "" : "#");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return arr.join("");
|
|
34
|
+
}
|
|
20
35
|
}
|
|
21
36
|
exports.UrlUtils = UrlUtils;
|
package/dist/esm/api/AppApi.js
CHANGED
|
@@ -2,10 +2,12 @@ import { ElectronUtils } from "../utils/ElectronUtils";
|
|
|
2
2
|
import { Channel } from "./Channel";
|
|
3
3
|
export class AppApi {
|
|
4
4
|
static async setConfig(key, value) {
|
|
5
|
-
|
|
5
|
+
var _a;
|
|
6
|
+
await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.APP, this.SET_CONFIG, key, value));
|
|
6
7
|
}
|
|
7
8
|
static async getConfig(key, defaultValue) {
|
|
8
|
-
|
|
9
|
+
var _a;
|
|
10
|
+
const value = await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.APP, this.GET_CONFIG, key));
|
|
9
11
|
if (value === null || value === undefined) {
|
|
10
12
|
return defaultValue;
|
|
11
13
|
}
|
|
@@ -15,10 +17,12 @@ export class AppApi {
|
|
|
15
17
|
return value;
|
|
16
18
|
}
|
|
17
19
|
static openAddWidgetWindow() {
|
|
18
|
-
|
|
20
|
+
var _a;
|
|
21
|
+
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.APP, this.OPEN_ADD_WIDGET_WINDOW);
|
|
19
22
|
}
|
|
20
23
|
static openSettingWindow() {
|
|
21
|
-
|
|
24
|
+
var _a;
|
|
25
|
+
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.APP, this.OPEN_SETTING_WINDOW);
|
|
22
26
|
}
|
|
23
27
|
}
|
|
24
28
|
AppApi.SET_CONFIG = "SET_CONFIG";
|
|
@@ -3,7 +3,8 @@ import { Channel } from "./Channel";
|
|
|
3
3
|
import { ElectronApi } from "./ElectronApi";
|
|
4
4
|
export class BroadcastApi {
|
|
5
5
|
static async sendBroadcastEvent(event) {
|
|
6
|
-
|
|
6
|
+
var _a;
|
|
7
|
+
await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROADCAST, JSON.stringify(event)));
|
|
7
8
|
}
|
|
8
9
|
static async registerBroadcast(callback) {
|
|
9
10
|
await ElectronApi.addIpcListener(Channel.BROADCAST, (json) => {
|
|
@@ -2,19 +2,36 @@ import { Channel } from "./Channel";
|
|
|
2
2
|
import { ElectronUtils } from "../utils/ElectronUtils";
|
|
3
3
|
export class BrowserWindowApi {
|
|
4
4
|
static async setIgnoreMouseEvent(ignore) {
|
|
5
|
-
|
|
5
|
+
var _a;
|
|
6
|
+
await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.IGNORE_MOUSE_EVENT, ignore));
|
|
6
7
|
}
|
|
8
|
+
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));
|
|
11
|
+
}
|
|
12
|
+
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));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated
|
|
18
|
+
* @param show
|
|
19
|
+
*/
|
|
7
20
|
static async setWindowVisibility(show) {
|
|
8
|
-
|
|
21
|
+
var _a;
|
|
22
|
+
await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.WINDOW_VISIBILITY, show));
|
|
9
23
|
}
|
|
10
24
|
static async setAlwaysOnTop(alwaysOnTop) {
|
|
11
|
-
|
|
25
|
+
var _a;
|
|
26
|
+
await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.ALWAYS_ON_TOP, alwaysOnTop));
|
|
12
27
|
}
|
|
13
28
|
static async isAlwaysOnTop() {
|
|
14
|
-
|
|
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));
|
|
15
31
|
}
|
|
16
32
|
static async openUrl(url) {
|
|
17
|
-
|
|
33
|
+
var _a;
|
|
34
|
+
await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.OPEN_URL, url));
|
|
18
35
|
}
|
|
19
36
|
/**
|
|
20
37
|
* 设置窗口位置
|
|
@@ -23,29 +40,36 @@ export class BrowserWindowApi {
|
|
|
23
40
|
* @param animation 动画只在mac系统有效
|
|
24
41
|
*/
|
|
25
42
|
static async setPosition(x, y, animation) {
|
|
26
|
-
|
|
43
|
+
var _a;
|
|
44
|
+
await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.SET_POSITION, x, y, animation));
|
|
27
45
|
}
|
|
28
46
|
static async getPosition() {
|
|
29
|
-
|
|
47
|
+
var _a;
|
|
48
|
+
return await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.GET_POSITION));
|
|
30
49
|
}
|
|
31
50
|
static async blur() {
|
|
32
|
-
|
|
51
|
+
var _a;
|
|
52
|
+
return await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.BLUR));
|
|
33
53
|
}
|
|
34
54
|
static async focus() {
|
|
35
|
-
|
|
55
|
+
var _a;
|
|
56
|
+
return await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.FOCUS));
|
|
36
57
|
}
|
|
37
58
|
/**
|
|
38
59
|
* 设置窗口是否可以拉伸
|
|
39
60
|
* @param resizable
|
|
40
61
|
*/
|
|
41
62
|
static async setResizable(resizable) {
|
|
42
|
-
|
|
63
|
+
var _a;
|
|
64
|
+
return await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.SET_RESIZABLE, resizable));
|
|
43
65
|
}
|
|
44
66
|
static async getBounds() {
|
|
45
|
-
|
|
67
|
+
var _a;
|
|
68
|
+
return await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.GET_BOUNDS));
|
|
46
69
|
}
|
|
47
70
|
static async setBounds(bounds, animate) {
|
|
48
|
-
|
|
71
|
+
var _a;
|
|
72
|
+
return await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.SET_BOUNDS, bounds, animate));
|
|
49
73
|
}
|
|
50
74
|
}
|
|
51
75
|
BrowserWindowApi.IGNORE_MOUSE_EVENT = "ignore-mouse-event";
|
|
@@ -60,3 +84,4 @@ BrowserWindowApi.FOCUS = "focus";
|
|
|
60
84
|
BrowserWindowApi.SET_RESIZABLE = "set-resizable";
|
|
61
85
|
BrowserWindowApi.GET_BOUNDS = "get-bounds";
|
|
62
86
|
BrowserWindowApi.SET_BOUNDS = "set-bounds";
|
|
87
|
+
BrowserWindowApi.SHOW = "show";
|
package/dist/esm/api/Channel.js
CHANGED
|
@@ -5,5 +5,7 @@ export var Channel;
|
|
|
5
5
|
Channel["BROADCAST"] = "channel::cn.widgetjs.core.broadcast";
|
|
6
6
|
Channel["WIDGET"] = "channel::cn.widgetjs.core.widget";
|
|
7
7
|
Channel["APP"] = "channel::cn.widgetjs.core.app";
|
|
8
|
+
Channel["MOUSE_EVENT"] = "channel::cn.widgetjs.core.mouse_event";
|
|
9
|
+
Channel["KEYBOARD_EVENT"] = "channel::cn.widgetjs.core.keyboard_event";
|
|
8
10
|
Channel["DIALOG"] = "channel::cn.widgetjs.core.dialog";
|
|
9
11
|
})(Channel || (Channel = {}));
|