@widget-js/core 0.1.15 → 0.1.17
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/AppPermission.js +8 -0
- package/dist/cjs/api/BrowserWindowApi.js +27 -0
- package/dist/cjs/api/Channel.js +2 -0
- package/dist/cjs/api/NotificationApi.js +65 -16
- package/dist/cjs/api/WidgetApi.js +15 -0
- 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/AppPermission.js +5 -0
- package/dist/esm/api/BrowserWindowApi.js +27 -0
- package/dist/esm/api/Channel.js +2 -0
- package/dist/esm/api/NotificationApi.js +65 -16
- package/dist/esm/api/WidgetApi.js +15 -0
- 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/AppPermission.d.ts +4 -0
- package/dist/types/api/BrowserWindowApi.d.ts +15 -0
- package/dist/types/api/Channel.d.ts +2 -0
- package/dist/types/api/NotificationApi.d.ts +18 -4
- 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 -16
- package/dist/esm/model/Notification.js +0 -12
- package/dist/types/model/Notification.d.ts +0 -18
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppPermission = void 0;
|
|
4
|
+
var AppPermission;
|
|
5
|
+
(function (AppPermission) {
|
|
6
|
+
AppPermission["ACCESS_MOUSE_EVENT"] = "ACCESS_MOUSE_EVENT";
|
|
7
|
+
AppPermission["ACCESS_KEYBOARD_EVENT"] = "ACCESS_KEYBOARD_EVENT";
|
|
8
|
+
})(AppPermission = exports.AppPermission || (exports.AppPermission = {}));
|
|
@@ -8,6 +8,18 @@ class BrowserWindowApi {
|
|
|
8
8
|
var _a;
|
|
9
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));
|
|
10
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
|
+
*/
|
|
11
23
|
static async setWindowVisibility(show) {
|
|
12
24
|
var _a;
|
|
13
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,6 +36,10 @@ class BrowserWindowApi {
|
|
|
24
36
|
var _a;
|
|
25
37
|
await ((_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.BROWSER_WINDOW, this.OPEN_URL, url));
|
|
26
38
|
}
|
|
39
|
+
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));
|
|
42
|
+
}
|
|
27
43
|
/**
|
|
28
44
|
* 设置窗口位置
|
|
29
45
|
* @param x
|
|
@@ -62,6 +78,14 @@ class BrowserWindowApi {
|
|
|
62
78
|
var _a;
|
|
63
79
|
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));
|
|
64
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* 通过url检测窗口是否存在
|
|
83
|
+
* @param url
|
|
84
|
+
*/
|
|
85
|
+
static async existsByUrl(url) {
|
|
86
|
+
var _a;
|
|
87
|
+
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));
|
|
88
|
+
}
|
|
65
89
|
}
|
|
66
90
|
exports.BrowserWindowApi = BrowserWindowApi;
|
|
67
91
|
BrowserWindowApi.IGNORE_MOUSE_EVENT = "ignore-mouse-event";
|
|
@@ -69,6 +93,7 @@ BrowserWindowApi.WINDOW_VISIBILITY = "window-visibility";
|
|
|
69
93
|
BrowserWindowApi.ALWAYS_ON_TOP = "always-on-top";
|
|
70
94
|
BrowserWindowApi.IS_ALWAYS_ON_TOP = "is-always-on-top";
|
|
71
95
|
BrowserWindowApi.OPEN_URL = "open-url";
|
|
96
|
+
BrowserWindowApi.MOVE_TOP = "move-top";
|
|
72
97
|
BrowserWindowApi.SET_POSITION = "set-position";
|
|
73
98
|
BrowserWindowApi.GET_POSITION = "get-position";
|
|
74
99
|
BrowserWindowApi.BLUR = "blur";
|
|
@@ -76,3 +101,5 @@ BrowserWindowApi.FOCUS = "focus";
|
|
|
76
101
|
BrowserWindowApi.SET_RESIZABLE = "set-resizable";
|
|
77
102
|
BrowserWindowApi.GET_BOUNDS = "get-bounds";
|
|
78
103
|
BrowserWindowApi.SET_BOUNDS = "set-bounds";
|
|
104
|
+
BrowserWindowApi.EXISTS_BY_URL = "exists-by-url";
|
|
105
|
+
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 = {}));
|
|
@@ -1,22 +1,56 @@
|
|
|
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
|
|
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) {
|
|
9
24
|
var _a;
|
|
10
|
-
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, new
|
|
11
|
-
|
|
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,
|
|
12
32
|
type: "call",
|
|
13
|
-
message: "下班提醒",
|
|
14
|
-
duration: duration
|
|
15
33
|
}));
|
|
16
34
|
}
|
|
17
|
-
static async
|
|
35
|
+
static async send(notification) {
|
|
18
36
|
var _a;
|
|
19
|
-
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION,
|
|
37
|
+
return (_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, notification);
|
|
38
|
+
}
|
|
39
|
+
static async reminder(title, message, icon, cancelButtonText, confirmButtonText, cancelBroadcast, confirmBroadcast) {
|
|
40
|
+
return await this.send(new AppNotification_1.AppNotification({
|
|
41
|
+
icon,
|
|
42
|
+
message,
|
|
43
|
+
title,
|
|
44
|
+
duration: 5000,
|
|
45
|
+
cancelButtonText,
|
|
46
|
+
confirmButtonText,
|
|
47
|
+
cancelBroadcast,
|
|
48
|
+
confirmBroadcast,
|
|
49
|
+
type: "reminder",
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
static async advanceCountdown(message, targetTime, title) {
|
|
53
|
+
return await this.send(new AppNotification_1.AppNotification({
|
|
20
54
|
title,
|
|
21
55
|
message,
|
|
22
56
|
targetTime,
|
|
@@ -25,18 +59,21 @@ class NotificationApi {
|
|
|
25
59
|
}
|
|
26
60
|
static async countdown(message, targetTime) {
|
|
27
61
|
var _a;
|
|
28
|
-
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, new
|
|
62
|
+
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, new AppNotification_1.AppNotification({
|
|
29
63
|
message,
|
|
30
64
|
targetTime,
|
|
65
|
+
backgroundColor: 'rgba(0,0,0,0.5)',
|
|
66
|
+
duration: -1,
|
|
31
67
|
type: "countdown"
|
|
32
68
|
}));
|
|
33
69
|
}
|
|
34
70
|
static async success(message, duration = 5000) {
|
|
35
71
|
var _a;
|
|
36
72
|
if (ElectronUtils_1.ElectronUtils.hasElectronApi()) {
|
|
37
|
-
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, new
|
|
73
|
+
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, new AppNotification_1.AppNotification({
|
|
38
74
|
message,
|
|
39
75
|
type: "success",
|
|
76
|
+
icon: "check_circle_line",
|
|
40
77
|
duration
|
|
41
78
|
}));
|
|
42
79
|
}
|
|
@@ -47,9 +84,10 @@ class NotificationApi {
|
|
|
47
84
|
static async error(message, duration = 5000) {
|
|
48
85
|
var _a;
|
|
49
86
|
if (ElectronUtils_1.ElectronUtils.hasElectronApi()) {
|
|
50
|
-
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, new
|
|
87
|
+
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, new AppNotification_1.AppNotification({
|
|
51
88
|
message,
|
|
52
89
|
type: "error",
|
|
90
|
+
icon: "close_circle_line",
|
|
53
91
|
duration
|
|
54
92
|
}));
|
|
55
93
|
}
|
|
@@ -60,9 +98,10 @@ class NotificationApi {
|
|
|
60
98
|
static async warning(message, duration = 5000) {
|
|
61
99
|
var _a;
|
|
62
100
|
if (ElectronUtils_1.ElectronUtils.hasElectronApi()) {
|
|
63
|
-
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, new
|
|
101
|
+
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, new AppNotification_1.AppNotification({
|
|
64
102
|
message,
|
|
65
103
|
type: "warning",
|
|
104
|
+
icon: "warning_line",
|
|
66
105
|
duration
|
|
67
106
|
}));
|
|
68
107
|
}
|
|
@@ -70,17 +109,27 @@ class NotificationApi {
|
|
|
70
109
|
this.callback("warning", message, duration);
|
|
71
110
|
}
|
|
72
111
|
}
|
|
73
|
-
static async
|
|
112
|
+
static async info(message, duration = 5000) {
|
|
74
113
|
var _a;
|
|
75
114
|
if (ElectronUtils_1.ElectronUtils.hasElectronApi()) {
|
|
76
|
-
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, new
|
|
115
|
+
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, new AppNotification_1.AppNotification({
|
|
77
116
|
message,
|
|
78
|
-
type: "
|
|
117
|
+
type: "info",
|
|
118
|
+
icon: "information_line",
|
|
79
119
|
duration
|
|
80
120
|
}));
|
|
81
121
|
}
|
|
82
122
|
else {
|
|
83
|
-
this.callback("
|
|
123
|
+
this.callback("info", message, duration);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* 隐藏通知
|
|
128
|
+
*/
|
|
129
|
+
static async hide() {
|
|
130
|
+
var _a;
|
|
131
|
+
if (ElectronUtils_1.ElectronUtils.hasElectronApi()) {
|
|
132
|
+
(_a = ElectronUtils_1.ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel_1.Channel.NOTIFICATION, null);
|
|
84
133
|
}
|
|
85
134
|
}
|
|
86
135
|
static setDebugNotification(callback) {
|
|
@@ -74,6 +74,21 @@ class WidgetApi {
|
|
|
74
74
|
return null;
|
|
75
75
|
return UrlUtils_1.UrlUtils.getWidgetUrl(widget.configUrl, widgetPackage, widgetParams);
|
|
76
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
|
+
}
|
|
77
92
|
/**
|
|
78
93
|
* 通过组件名保存组件信息,通常用于存储可以在同类组件中共用的数据
|
|
79
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;
|
|
@@ -5,6 +5,18 @@ export class BrowserWindowApi {
|
|
|
5
5
|
var _a;
|
|
6
6
|
await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.IGNORE_MOUSE_EVENT, ignore));
|
|
7
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
|
+
*/
|
|
8
20
|
static async setWindowVisibility(show) {
|
|
9
21
|
var _a;
|
|
10
22
|
await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.WINDOW_VISIBILITY, show));
|
|
@@ -21,6 +33,10 @@ export class BrowserWindowApi {
|
|
|
21
33
|
var _a;
|
|
22
34
|
await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.OPEN_URL, url));
|
|
23
35
|
}
|
|
36
|
+
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));
|
|
39
|
+
}
|
|
24
40
|
/**
|
|
25
41
|
* 设置窗口位置
|
|
26
42
|
* @param x
|
|
@@ -59,12 +75,21 @@ export class BrowserWindowApi {
|
|
|
59
75
|
var _a;
|
|
60
76
|
return await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.SET_BOUNDS, bounds, animate));
|
|
61
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* 通过url检测窗口是否存在
|
|
80
|
+
* @param url
|
|
81
|
+
*/
|
|
82
|
+
static async existsByUrl(url) {
|
|
83
|
+
var _a;
|
|
84
|
+
return await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.BROWSER_WINDOW, this.EXISTS_BY_URL, url));
|
|
85
|
+
}
|
|
62
86
|
}
|
|
63
87
|
BrowserWindowApi.IGNORE_MOUSE_EVENT = "ignore-mouse-event";
|
|
64
88
|
BrowserWindowApi.WINDOW_VISIBILITY = "window-visibility";
|
|
65
89
|
BrowserWindowApi.ALWAYS_ON_TOP = "always-on-top";
|
|
66
90
|
BrowserWindowApi.IS_ALWAYS_ON_TOP = "is-always-on-top";
|
|
67
91
|
BrowserWindowApi.OPEN_URL = "open-url";
|
|
92
|
+
BrowserWindowApi.MOVE_TOP = "move-top";
|
|
68
93
|
BrowserWindowApi.SET_POSITION = "set-position";
|
|
69
94
|
BrowserWindowApi.GET_POSITION = "get-position";
|
|
70
95
|
BrowserWindowApi.BLUR = "blur";
|
|
@@ -72,3 +97,5 @@ BrowserWindowApi.FOCUS = "focus";
|
|
|
72
97
|
BrowserWindowApi.SET_RESIZABLE = "set-resizable";
|
|
73
98
|
BrowserWindowApi.GET_BOUNDS = "get-bounds";
|
|
74
99
|
BrowserWindowApi.SET_BOUNDS = "set-bounds";
|
|
100
|
+
BrowserWindowApi.EXISTS_BY_URL = "exists-by-url";
|
|
101
|
+
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 = {}));
|
|
@@ -1,19 +1,53 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AppNotification } from "../model/AppNotification";
|
|
2
2
|
import { Channel } from "./Channel";
|
|
3
3
|
import { ElectronUtils } from "../utils/ElectronUtils";
|
|
4
4
|
export class NotificationApi {
|
|
5
|
-
static async
|
|
5
|
+
// static async url(url: string, duration: number = -1) {
|
|
6
|
+
// ElectronUtils.getAPI()?.invoke(Channel.NOTIFICATION, new AppNotification({
|
|
7
|
+
// url, message: "",
|
|
8
|
+
// duration,
|
|
9
|
+
// type: "url",
|
|
10
|
+
// }));
|
|
11
|
+
// }
|
|
12
|
+
/**
|
|
13
|
+
* 来电
|
|
14
|
+
* @param avatar 头像地址
|
|
15
|
+
* @param audio 音频地址
|
|
16
|
+
* @param title 标题文件
|
|
17
|
+
* @param message 初始消息
|
|
18
|
+
* @param lyric 歌词字符串
|
|
19
|
+
*/
|
|
20
|
+
static async call(avatar, audio, title, message, lyric) {
|
|
6
21
|
var _a;
|
|
7
|
-
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, new
|
|
8
|
-
|
|
22
|
+
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, new AppNotification({
|
|
23
|
+
avatar,
|
|
24
|
+
audio,
|
|
25
|
+
message,
|
|
26
|
+
title,
|
|
27
|
+
duration: -1,
|
|
28
|
+
lyric,
|
|
9
29
|
type: "call",
|
|
10
|
-
message: "下班提醒",
|
|
11
|
-
duration: duration
|
|
12
30
|
}));
|
|
13
31
|
}
|
|
14
|
-
static async
|
|
32
|
+
static async send(notification) {
|
|
15
33
|
var _a;
|
|
16
|
-
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION,
|
|
34
|
+
return (_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, notification);
|
|
35
|
+
}
|
|
36
|
+
static async reminder(title, message, icon, cancelButtonText, confirmButtonText, cancelBroadcast, confirmBroadcast) {
|
|
37
|
+
return await this.send(new AppNotification({
|
|
38
|
+
icon,
|
|
39
|
+
message,
|
|
40
|
+
title,
|
|
41
|
+
duration: 5000,
|
|
42
|
+
cancelButtonText,
|
|
43
|
+
confirmButtonText,
|
|
44
|
+
cancelBroadcast,
|
|
45
|
+
confirmBroadcast,
|
|
46
|
+
type: "reminder",
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
static async advanceCountdown(message, targetTime, title) {
|
|
50
|
+
return await this.send(new AppNotification({
|
|
17
51
|
title,
|
|
18
52
|
message,
|
|
19
53
|
targetTime,
|
|
@@ -22,18 +56,21 @@ export class NotificationApi {
|
|
|
22
56
|
}
|
|
23
57
|
static async countdown(message, targetTime) {
|
|
24
58
|
var _a;
|
|
25
|
-
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, new
|
|
59
|
+
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, new AppNotification({
|
|
26
60
|
message,
|
|
27
61
|
targetTime,
|
|
62
|
+
backgroundColor: 'rgba(0,0,0,0.5)',
|
|
63
|
+
duration: -1,
|
|
28
64
|
type: "countdown"
|
|
29
65
|
}));
|
|
30
66
|
}
|
|
31
67
|
static async success(message, duration = 5000) {
|
|
32
68
|
var _a;
|
|
33
69
|
if (ElectronUtils.hasElectronApi()) {
|
|
34
|
-
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, new
|
|
70
|
+
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, new AppNotification({
|
|
35
71
|
message,
|
|
36
72
|
type: "success",
|
|
73
|
+
icon: "check_circle_line",
|
|
37
74
|
duration
|
|
38
75
|
}));
|
|
39
76
|
}
|
|
@@ -44,9 +81,10 @@ export class NotificationApi {
|
|
|
44
81
|
static async error(message, duration = 5000) {
|
|
45
82
|
var _a;
|
|
46
83
|
if (ElectronUtils.hasElectronApi()) {
|
|
47
|
-
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, new
|
|
84
|
+
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, new AppNotification({
|
|
48
85
|
message,
|
|
49
86
|
type: "error",
|
|
87
|
+
icon: "close_circle_line",
|
|
50
88
|
duration
|
|
51
89
|
}));
|
|
52
90
|
}
|
|
@@ -57,9 +95,10 @@ export class NotificationApi {
|
|
|
57
95
|
static async warning(message, duration = 5000) {
|
|
58
96
|
var _a;
|
|
59
97
|
if (ElectronUtils.hasElectronApi()) {
|
|
60
|
-
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, new
|
|
98
|
+
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, new AppNotification({
|
|
61
99
|
message,
|
|
62
100
|
type: "warning",
|
|
101
|
+
icon: "warning_line",
|
|
63
102
|
duration
|
|
64
103
|
}));
|
|
65
104
|
}
|
|
@@ -67,17 +106,27 @@ export class NotificationApi {
|
|
|
67
106
|
this.callback("warning", message, duration);
|
|
68
107
|
}
|
|
69
108
|
}
|
|
70
|
-
static async
|
|
109
|
+
static async info(message, duration = 5000) {
|
|
71
110
|
var _a;
|
|
72
111
|
if (ElectronUtils.hasElectronApi()) {
|
|
73
|
-
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, new
|
|
112
|
+
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, new AppNotification({
|
|
74
113
|
message,
|
|
75
|
-
type: "
|
|
114
|
+
type: "info",
|
|
115
|
+
icon: "information_line",
|
|
76
116
|
duration
|
|
77
117
|
}));
|
|
78
118
|
}
|
|
79
119
|
else {
|
|
80
|
-
this.callback("
|
|
120
|
+
this.callback("info", message, duration);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* 隐藏通知
|
|
125
|
+
*/
|
|
126
|
+
static async hide() {
|
|
127
|
+
var _a;
|
|
128
|
+
if (ElectronUtils.hasElectronApi()) {
|
|
129
|
+
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, null);
|
|
81
130
|
}
|
|
82
131
|
}
|
|
83
132
|
static setDebugNotification(callback) {
|
|
@@ -68,6 +68,21 @@ export class WidgetApi {
|
|
|
68
68
|
return null;
|
|
69
69
|
return UrlUtils.getWidgetUrl(widget.configUrl, widgetPackage, widgetParams);
|
|
70
70
|
}
|
|
71
|
+
static async getWidgetUrl(widgetName, widgetParams) {
|
|
72
|
+
const widget = await this.getWidget(widgetName);
|
|
73
|
+
if (!widget || widget.configUrl == null)
|
|
74
|
+
return null;
|
|
75
|
+
const widgetPackage = await this.getWidgetPackage(widget.packageName);
|
|
76
|
+
if (!widgetPackage)
|
|
77
|
+
return null;
|
|
78
|
+
return UrlUtils.getWidgetUrl(widget.url, widgetPackage, widgetParams);
|
|
79
|
+
}
|
|
80
|
+
static async getWidgetPackageUrl(packageName, hash) {
|
|
81
|
+
const widgetPackage = await this.getWidgetPackage(packageName);
|
|
82
|
+
if (!widgetPackage)
|
|
83
|
+
return null;
|
|
84
|
+
return widgetPackage.getFullUrl(hash);
|
|
85
|
+
}
|
|
71
86
|
/**
|
|
72
87
|
* 通过组件名保存组件信息,通常用于存储可以在同类组件中共用的数据
|
|
73
88
|
* @param data
|
package/dist/esm/index.js
CHANGED
|
@@ -3,9 +3,11 @@ export * from "./model/event/BroadcastEvent";
|
|
|
3
3
|
export * from "./model/event/WebSocketEvent";
|
|
4
4
|
export * from "./model/WidgetData";
|
|
5
5
|
export * from "./model/WidgetParams";
|
|
6
|
-
export * from "./model/
|
|
6
|
+
export * from "./model/AppNotification";
|
|
7
7
|
export * from "./model/HostedMode";
|
|
8
8
|
export * from "./model/interface/Rectangle";
|
|
9
|
+
export * from "./model/event/AppKeyboardEvent";
|
|
10
|
+
export * from "./model/event/AppMouseEvent";
|
|
9
11
|
export * from "./model/WidgetPackage";
|
|
10
12
|
export * from "./api/ElectronApi";
|
|
11
13
|
export * from "./repository/WidgetDataRepository";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export var NotificationSize;
|
|
2
|
+
(function (NotificationSize) {
|
|
3
|
+
NotificationSize["SMALL"] = "small";
|
|
4
|
+
NotificationSize["NORMAL"] = "normal";
|
|
5
|
+
NotificationSize["LARGE"] = "large";
|
|
6
|
+
})(NotificationSize || (NotificationSize = {}));
|
|
7
|
+
export class AppNotification {
|
|
8
|
+
constructor(option) {
|
|
9
|
+
var _a, _b, _c, _d, _e;
|
|
10
|
+
this.type = "info";
|
|
11
|
+
this.type = (_a = option.type) !== null && _a !== void 0 ? _a : "info";
|
|
12
|
+
this.title = option.title;
|
|
13
|
+
this.message = option.message;
|
|
14
|
+
this.targetTime = option.targetTime;
|
|
15
|
+
this.duration = (_b = option.duration) !== null && _b !== void 0 ? _b : 5000;
|
|
16
|
+
this.icon = option.icon;
|
|
17
|
+
this.color = (_c = option.color) !== null && _c !== void 0 ? _c : "#5D8AC8";
|
|
18
|
+
this.confirmButtonText = option.confirmButtonText;
|
|
19
|
+
this.cancelButtonText = option.cancelButtonText;
|
|
20
|
+
this.cancelBroadcast = option.cancelBroadcast;
|
|
21
|
+
this.confirmBroadcast = option.confirmBroadcast;
|
|
22
|
+
this.size = (_d = option.size) !== null && _d !== void 0 ? _d : NotificationSize.NORMAL;
|
|
23
|
+
this.audio = option.audio;
|
|
24
|
+
this.avatar = option.avatar;
|
|
25
|
+
this.lyric = option.lyric;
|
|
26
|
+
this.backgroundColor = (_e = option.backgroundColor) !== null && _e !== void 0 ? _e : '#000000';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UrlUtils } from "../utils/UrlUtils";
|
|
1
2
|
export class WidgetPackage {
|
|
2
3
|
constructor() {
|
|
3
4
|
/**
|
|
@@ -19,10 +20,7 @@ export class WidgetPackage {
|
|
|
19
20
|
* 如果url是http链接,直接返回链接
|
|
20
21
|
* 如果是本地组件:file://链接,则返回 url+entry,e.g. file://C:\users\neo\desktop\index.html#
|
|
21
22
|
*/
|
|
22
|
-
getFullUrl() {
|
|
23
|
-
|
|
24
|
-
return this.url;
|
|
25
|
-
}
|
|
26
|
-
return this.url + (this.entry.startsWith("/") ? this.entry : `/${this.entry}`);
|
|
23
|
+
getFullUrl(hash) {
|
|
24
|
+
return UrlUtils.getWidgetPackageUrl(this.url, this.entry, hash == null ? this.hash : hash);
|
|
27
25
|
}
|
|
28
26
|
}
|