@widget-js/core 0.0.10 → 0.0.12
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/BrowserWindowApi.js +20 -0
- package/dist/cjs/api/Channel.js +9 -0
- package/dist/cjs/api/ElectronApi.js +34 -76
- package/dist/cjs/api/NotificationApi.js +83 -0
- package/dist/cjs/api/WidgetApi.js +25 -0
- package/dist/cjs/index.js +7 -1
- package/dist/cjs/model/Notification.js +15 -0
- package/dist/cjs/model/Widget.js +28 -42
- package/dist/cjs/model/WidgetPackage.js +6 -0
- package/dist/cjs/model/WidgetParams.js +17 -17
- package/dist/cjs/repository/WidgetDataRepository.js +31 -48
- package/dist/cjs/utils/ElectronUtils.js +24 -0
- package/dist/esm/api/BrowserWindowApi.js +16 -0
- package/dist/esm/api/Channel.js +6 -0
- package/dist/esm/api/ElectronApi.js +34 -76
- package/dist/esm/api/NotificationApi.js +79 -0
- package/dist/esm/api/WidgetApi.js +21 -0
- package/dist/esm/index.js +7 -1
- package/dist/esm/model/Notification.js +11 -0
- package/dist/esm/model/Widget.js +28 -42
- package/dist/esm/model/WidgetPackage.js +2 -0
- package/dist/esm/model/WidgetParams.js +17 -17
- package/dist/esm/repository/WidgetDataRepository.js +31 -48
- package/dist/esm/utils/ElectronUtils.js +20 -0
- package/dist/types/api/BrowserWindowApi.d.ts +8 -0
- package/dist/types/api/Channel.d.ts +5 -0
- package/dist/types/api/ElectronApi.d.ts +1 -3
- package/dist/types/api/NotificationApi.d.ts +14 -0
- package/dist/types/api/WidgetApi.d.ts +7 -0
- package/dist/types/index.d.ts +7 -1
- package/dist/types/model/Notification.d.ts +16 -0
- package/dist/types/model/Widget.d.ts +32 -41
- package/dist/types/model/WidgetPackage.d.ts +31 -0
- package/dist/types/model/WidgetParams.d.ts +7 -7
- package/dist/types/utils/ElectronUtils.d.ts +8 -0
- package/dist/umd/index.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/api/Keys.js +0 -11
- package/dist/esm/api/Keys.js +0 -7
- package/dist/types/api/Keys.d.ts +0 -7
|
@@ -1,89 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { Keys } from "./Keys";
|
|
1
|
+
import { ElectronUtils } from "../utils/ElectronUtils";
|
|
2
|
+
import { Channel } from "./Channel";
|
|
11
3
|
export class ElectronApi {
|
|
12
4
|
static openAddWidgetWindow() {
|
|
13
|
-
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
window.electronAPI.invokeIpc("openAddWidgetWindow");
|
|
16
|
-
}
|
|
5
|
+
ElectronUtils.getAPI().invokeIpc("openAddWidgetWindow");
|
|
17
6
|
}
|
|
18
|
-
static
|
|
19
|
-
|
|
20
|
-
if (this.hasElectronApi()) {
|
|
21
|
-
const data = JSON.parse(JSON.stringify(widgets.map(item => JSON.stringify(item))));
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
yield window.electronAPI.invokeIpc("registerWidgets", data);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
7
|
+
static async setConfig(key, value) {
|
|
8
|
+
await ElectronUtils.getAPI().invokeIpc("setConfig", { key, value });
|
|
26
9
|
}
|
|
27
|
-
static
|
|
28
|
-
|
|
29
|
-
if (this.hasElectronApi()) {
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
yield window.electronAPI.invokeIpc("setConfig", { key, value });
|
|
32
|
-
}
|
|
33
|
-
});
|
|
10
|
+
static async sendBroadcastEvent(event) {
|
|
11
|
+
await ElectronUtils.getAPI().invokeIpc(Channel.BROADCAST, JSON.stringify(event));
|
|
34
12
|
}
|
|
35
|
-
static
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// @ts-ignore
|
|
39
|
-
yield window.electronAPI.invokeIpc(Keys.BROADCAST_EVENT, JSON.stringify(event));
|
|
40
|
-
}
|
|
13
|
+
static async registerBroadcast(callback) {
|
|
14
|
+
await this.addIpcListener(Channel.BROADCAST, (json) => {
|
|
15
|
+
callback(JSON.parse(json));
|
|
41
16
|
});
|
|
42
17
|
}
|
|
43
|
-
static
|
|
44
|
-
|
|
45
|
-
yield this.addIpcListener(Keys.BROADCAST_EVENT, (json) => {
|
|
46
|
-
callback(JSON.parse(json));
|
|
47
|
-
});
|
|
48
|
-
});
|
|
18
|
+
static async unregisterBroadcast() {
|
|
19
|
+
await this.removeIpcListener(Channel.BROADCAST);
|
|
49
20
|
}
|
|
50
|
-
static
|
|
51
|
-
|
|
52
|
-
yield this.removeIpcListener(Keys.BROADCAST_EVENT);
|
|
53
|
-
});
|
|
21
|
+
static async addIpcListener(key, f) {
|
|
22
|
+
await ElectronUtils.getAPI().addIpcListener(key, f);
|
|
54
23
|
}
|
|
55
|
-
static
|
|
56
|
-
|
|
57
|
-
if (this.hasElectronApi()) {
|
|
58
|
-
// @ts-ignore
|
|
59
|
-
yield window.electronAPI.addIpcListener(key, f);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
24
|
+
static async removeIpcListener(key) {
|
|
25
|
+
await ElectronUtils.getAPI().removeIpcListener(key);
|
|
62
26
|
}
|
|
63
|
-
static
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
if (this.hasElectronApi()) {
|
|
74
|
-
// @ts-ignore
|
|
75
|
-
const value = yield window.electronAPI.invokeIpc("getConfig", key);
|
|
76
|
-
if (value === null || value === undefined) {
|
|
77
|
-
return defaultValue;
|
|
78
|
-
}
|
|
79
|
-
if (typeof defaultValue == "boolean") {
|
|
80
|
-
return value === "true";
|
|
81
|
-
}
|
|
82
|
-
return value;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
27
|
+
static async getConfig(key, defaultValue) {
|
|
28
|
+
const value = await ElectronUtils.getAPI().invokeIpc("getConfig", key);
|
|
29
|
+
if (value === null || value === undefined) {
|
|
30
|
+
return defaultValue;
|
|
31
|
+
}
|
|
32
|
+
if (typeof defaultValue == "boolean") {
|
|
33
|
+
return value === "true";
|
|
34
|
+
}
|
|
35
|
+
return value;
|
|
85
36
|
}
|
|
86
|
-
static
|
|
87
|
-
|
|
37
|
+
static async upgradeNewVersion(key, defaultValue) {
|
|
38
|
+
const value = await ElectronUtils.getAPI().invokeIpc("getConfig", key);
|
|
39
|
+
if (value === null || value === undefined) {
|
|
40
|
+
return defaultValue;
|
|
41
|
+
}
|
|
42
|
+
if (typeof defaultValue == "boolean") {
|
|
43
|
+
return value === "true";
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
88
46
|
}
|
|
89
47
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Notification } from "../model/Notification";
|
|
2
|
+
import { Channel } from "./Channel";
|
|
3
|
+
import { ElectronUtils } from "../utils/ElectronUtils";
|
|
4
|
+
export class NotificationApi {
|
|
5
|
+
static async call(duration = 5000) {
|
|
6
|
+
ElectronUtils.getAPI().invokeIpc(Channel.NOTIFICATION, new Notification({
|
|
7
|
+
title: "章鱼哥",
|
|
8
|
+
type: "call",
|
|
9
|
+
message: "下班提醒",
|
|
10
|
+
duration: duration
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
13
|
+
static async advanceCountdown(message, targetTime, title) {
|
|
14
|
+
ElectronUtils.getAPI().invokeIpc(Channel.NOTIFICATION, new Notification({
|
|
15
|
+
title,
|
|
16
|
+
message,
|
|
17
|
+
targetTime,
|
|
18
|
+
type: "advance-countdown"
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
static async countdown(message, targetTime) {
|
|
22
|
+
ElectronUtils.getAPI().invokeIpc(Channel.NOTIFICATION, new Notification({
|
|
23
|
+
message,
|
|
24
|
+
targetTime,
|
|
25
|
+
type: "countdown"
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
static async success(message, duration = 5000) {
|
|
29
|
+
if (ElectronUtils.hasElectronApi()) {
|
|
30
|
+
ElectronUtils.getAPI().invokeIpc(Channel.NOTIFICATION, new Notification({
|
|
31
|
+
message,
|
|
32
|
+
type: "success",
|
|
33
|
+
duration
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
this.callback("success", message, duration);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
static async error(message, duration = 5000) {
|
|
41
|
+
if (ElectronUtils.hasElectronApi()) {
|
|
42
|
+
ElectronUtils.getAPI().invokeIpc(Channel.NOTIFICATION, new Notification({
|
|
43
|
+
message,
|
|
44
|
+
type: "error",
|
|
45
|
+
duration
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.callback("error", message, duration);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
static async warning(message, duration = 5000) {
|
|
53
|
+
if (ElectronUtils.hasElectronApi()) {
|
|
54
|
+
ElectronUtils.getAPI().invokeIpc(Channel.NOTIFICATION, new Notification({
|
|
55
|
+
message,
|
|
56
|
+
type: "warning",
|
|
57
|
+
duration
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this.callback("warning", message, duration);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
static async message(message, duration = 5000) {
|
|
65
|
+
if (ElectronUtils.hasElectronApi()) {
|
|
66
|
+
ElectronUtils.getAPI().invokeIpc(Channel.NOTIFICATION, new Notification({
|
|
67
|
+
message,
|
|
68
|
+
type: "message",
|
|
69
|
+
duration
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this.callback("message", message, duration);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
static setDebugNotification(callback) {
|
|
77
|
+
this.callback = callback;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Widget } from "../model/Widget";
|
|
2
|
+
import { ElectronUtils } from "../utils/ElectronUtils";
|
|
3
|
+
export class WidgetApi {
|
|
4
|
+
static async registerWidgets(widgets) {
|
|
5
|
+
await ElectronUtils.getAPI().invokeIpc("registerWidgets", JSON.stringify(widgets));
|
|
6
|
+
}
|
|
7
|
+
static async registerWidgetPackage(widgetPackage) {
|
|
8
|
+
await ElectronUtils.getAPI().invokeIpc("registerWidgetPackage", JSON.stringify(widgetPackage));
|
|
9
|
+
}
|
|
10
|
+
static async getWidgets() {
|
|
11
|
+
const data = await ElectronUtils.getAPI().invokeIpc("getWidgets");
|
|
12
|
+
const widgets = [];
|
|
13
|
+
if (data) {
|
|
14
|
+
const arr = JSON.parse(data);
|
|
15
|
+
for (const i in arr) {
|
|
16
|
+
widgets.push(Widget.parseObject(arr[i]));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return widgets;
|
|
20
|
+
}
|
|
21
|
+
}
|
package/dist/esm/index.js
CHANGED
|
@@ -2,6 +2,12 @@ export * from "./model/Widget";
|
|
|
2
2
|
export * from "./model/BroadcastEvent";
|
|
3
3
|
export * from "./model/WidgetData";
|
|
4
4
|
export * from "./model/WidgetParams";
|
|
5
|
+
export * from "./model/Notification";
|
|
6
|
+
export * from "./model/WidgetPackage";
|
|
5
7
|
export * from "./api/ElectronApi";
|
|
6
|
-
export * from "./api/Keys";
|
|
7
8
|
export * from "./repository/WidgetDataRepository";
|
|
9
|
+
export * from "./api/BrowserWindowApi";
|
|
10
|
+
export * from "./api/NotificationApi";
|
|
11
|
+
export * from "./api/Channel";
|
|
12
|
+
export * from "./api/WidgetApi";
|
|
13
|
+
export * from "./utils/ElectronUtils";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export class Notification {
|
|
2
|
+
constructor(option) {
|
|
3
|
+
var _a, _b;
|
|
4
|
+
this.type = "message";
|
|
5
|
+
this.type = (_a = option.type) !== null && _a !== void 0 ? _a : "message";
|
|
6
|
+
this.title = option.title;
|
|
7
|
+
this.message = option.message;
|
|
8
|
+
this.targetTime = option.targetTime;
|
|
9
|
+
this.duration = (_b = option.duration) !== null && _b !== void 0 ? _b : 5000;
|
|
10
|
+
}
|
|
11
|
+
}
|
package/dist/esm/model/Widget.js
CHANGED
|
@@ -10,65 +10,51 @@ export class Widget {
|
|
|
10
10
|
this.description = options.description;
|
|
11
11
|
this.keywords = options.keywords;
|
|
12
12
|
this.lang = options.lang;
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
13
|
+
this.width = options.width;
|
|
14
|
+
this.height = options.height;
|
|
15
|
+
this.maxWidth = (_a = options.maxWidth) !== null && _a !== void 0 ? _a : options.width;
|
|
16
|
+
this.maxHeight = (_b = options.maxHeight) !== null && _b !== void 0 ? _b : options.height;
|
|
17
|
+
this.minWidth = (_c = options.minWidth) !== null && _c !== void 0 ? _c : options.width;
|
|
18
|
+
this.minHeight = (_d = options.minHeight) !== null && _d !== void 0 ? _d : options.height;
|
|
19
19
|
this.url = options.url;
|
|
20
20
|
this.configUrl = options.configUrl;
|
|
21
|
-
this.extraUrl = (_e = options.extraUrl) !== null && _e !== void 0 ? _e :
|
|
21
|
+
this.extraUrl = (_e = options.extraUrl) !== null && _e !== void 0 ? _e : {};
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* 获取组件标题
|
|
25
25
|
* @param lang 语言环境,不传则获取默认语言
|
|
26
26
|
*/
|
|
27
27
|
getTitle(lang) {
|
|
28
|
-
|
|
28
|
+
var _a;
|
|
29
|
+
return lang ? (_a = this.title[lang]) !== null && _a !== void 0 ? _a : this.title[this.lang] : this.title[this.lang];
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
31
32
|
* 获取组件标描述
|
|
32
33
|
* @param lang 语言环境,不传则获取默认标题
|
|
33
34
|
*/
|
|
34
35
|
getDescription(lang) {
|
|
35
|
-
return lang ? this.description
|
|
36
|
+
return lang ? this.description[lang] : this.description[this.lang];
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
name: this.name,
|
|
40
|
-
title: Object.fromEntries(this.title),
|
|
41
|
-
description: Object.fromEntries(this.description),
|
|
42
|
-
keywords: this.keywords,
|
|
43
|
-
lang: this.lang,
|
|
44
|
-
w: this.w,
|
|
45
|
-
h: this.h,
|
|
46
|
-
maxW: this.maxW,
|
|
47
|
-
maxH: this.maxH,
|
|
48
|
-
minW: this.minW,
|
|
49
|
-
minH: this.minH,
|
|
50
|
-
url: this.url,
|
|
51
|
-
configUrl: this.configUrl,
|
|
52
|
-
extraUrl: Object.fromEntries(this.extraUrl),
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
static parse(json) {
|
|
38
|
+
static parseJSON(json) {
|
|
56
39
|
const object = JSON.parse(json);
|
|
40
|
+
return this.parseObject(object);
|
|
41
|
+
}
|
|
42
|
+
static parseObject(obj) {
|
|
57
43
|
return new Widget({
|
|
58
|
-
configUrl:
|
|
59
|
-
description:
|
|
60
|
-
extraUrl:
|
|
61
|
-
|
|
62
|
-
keywords:
|
|
63
|
-
lang:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
44
|
+
configUrl: obj["configUrl"],
|
|
45
|
+
description: obj["description"],
|
|
46
|
+
extraUrl: obj["extraUrl"],
|
|
47
|
+
width: obj["width"],
|
|
48
|
+
keywords: obj["keywords"],
|
|
49
|
+
lang: obj["lang"],
|
|
50
|
+
maxHeight: obj["maxHeight"],
|
|
51
|
+
maxWidth: obj["maxWidth"],
|
|
52
|
+
height: obj["height"],
|
|
53
|
+
minHeight: obj["minHeight"],
|
|
54
|
+
minWidth: obj["minWidth"],
|
|
55
|
+
name: obj["name"],
|
|
56
|
+
title: obj["title"],
|
|
57
|
+
url: obj["url"]
|
|
72
58
|
});
|
|
73
59
|
}
|
|
74
60
|
}
|
|
@@ -27,7 +27,7 @@ export class WidgetParams {
|
|
|
27
27
|
* 从当前地址解析组件参数:
|
|
28
28
|
* http://localhost:8080/#/widget/config/labor_progress?w_w=2&w_h=2&w_width=156&w_height=156
|
|
29
29
|
* =>
|
|
30
|
-
* {
|
|
30
|
+
* {width:2,height:2,id:21,width_px:156,height_px:156}
|
|
31
31
|
*/
|
|
32
32
|
static fromCurrentLocation() {
|
|
33
33
|
const href = window.location.href;
|
|
@@ -45,11 +45,11 @@ export class WidgetParams {
|
|
|
45
45
|
else if (keyWithoutPrefix == WidgetParams.PARAM_Y) {
|
|
46
46
|
widgetEnv.y = parseInt(value);
|
|
47
47
|
}
|
|
48
|
-
else if (keyWithoutPrefix == WidgetParams.
|
|
49
|
-
widgetEnv.
|
|
48
|
+
else if (keyWithoutPrefix == WidgetParams.PARAM_HEIGHT) {
|
|
49
|
+
widgetEnv.height = parseInt(value);
|
|
50
50
|
}
|
|
51
|
-
else if (keyWithoutPrefix == WidgetParams.
|
|
52
|
-
widgetEnv.
|
|
51
|
+
else if (keyWithoutPrefix == WidgetParams.PARAM_WIDTH) {
|
|
52
|
+
widgetEnv.width = parseInt(value);
|
|
53
53
|
}
|
|
54
54
|
else if (keyWithoutPrefix == WidgetParams.PARAM_LANG) {
|
|
55
55
|
widgetEnv.lang = value;
|
|
@@ -63,11 +63,11 @@ export class WidgetParams {
|
|
|
63
63
|
else if (keyWithoutPrefix == WidgetParams.PARAM_RADIUS) {
|
|
64
64
|
widgetEnv.radius = parseInt(value);
|
|
65
65
|
}
|
|
66
|
-
else if (keyWithoutPrefix == WidgetParams.
|
|
67
|
-
widgetEnv.
|
|
66
|
+
else if (keyWithoutPrefix == WidgetParams.PARAM_WIDTH_PX) {
|
|
67
|
+
widgetEnv.widthPx = parseInt(value);
|
|
68
68
|
}
|
|
69
|
-
else if (keyWithoutPrefix == WidgetParams.
|
|
70
|
-
widgetEnv.
|
|
69
|
+
else if (keyWithoutPrefix == WidgetParams.PARAM_HEIGHT_PX) {
|
|
70
|
+
widgetEnv.heightPx = parseInt(value);
|
|
71
71
|
}
|
|
72
72
|
else if (keyWithoutPrefix == WidgetParams.PARAM_NAME) {
|
|
73
73
|
widgetEnv.name = value;
|
|
@@ -81,8 +81,8 @@ export class WidgetParams {
|
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
83
|
* 从对象键值对中初始化组件参数
|
|
84
|
-
* {
|
|
85
|
-
* {
|
|
84
|
+
* {w_width:2,w_height:2,w_id:21,w_width_px:156,w_height_px:156}=>
|
|
85
|
+
* {width:2,height:2,id:21,width_px:156,height_px:156}
|
|
86
86
|
* @param object
|
|
87
87
|
*/
|
|
88
88
|
static fromObject(object) {
|
|
@@ -98,10 +98,10 @@ export class WidgetParams {
|
|
|
98
98
|
}
|
|
99
99
|
WidgetParams.PARAM_PREFIX = "w_";
|
|
100
100
|
WidgetParams.PARAM_ID = "id";
|
|
101
|
-
WidgetParams.PARAM_W = "w";
|
|
102
|
-
WidgetParams.PARAM_H = "h";
|
|
103
101
|
WidgetParams.PARAM_WIDTH = "width";
|
|
104
102
|
WidgetParams.PARAM_HEIGHT = "height";
|
|
103
|
+
WidgetParams.PARAM_WIDTH_PX = "width_px";
|
|
104
|
+
WidgetParams.PARAM_HEIGHT_PX = "height_px";
|
|
105
105
|
WidgetParams.PARAM_X = "x";
|
|
106
106
|
WidgetParams.PARAM_Y = "y";
|
|
107
107
|
WidgetParams.PARAM_LANG = "lang";
|
|
@@ -113,15 +113,15 @@ WidgetParams.PARAM_TITLE = "title";
|
|
|
113
113
|
WidgetParams.PARAM_PREVIEW = "preview";
|
|
114
114
|
WidgetParams.PARAMS = [
|
|
115
115
|
WidgetParams.PARAM_ID,
|
|
116
|
-
WidgetParams.
|
|
117
|
-
WidgetParams.
|
|
116
|
+
WidgetParams.PARAM_WIDTH,
|
|
117
|
+
WidgetParams.PARAM_HEIGHT,
|
|
118
118
|
WidgetParams.PARAM_X,
|
|
119
119
|
WidgetParams.PARAM_Y,
|
|
120
120
|
WidgetParams.PARAM_LANG,
|
|
121
121
|
WidgetParams.PARAM_THEME,
|
|
122
122
|
WidgetParams.PARAM_MODE,
|
|
123
|
-
WidgetParams.
|
|
124
|
-
WidgetParams.
|
|
123
|
+
WidgetParams.PARAM_WIDTH_PX,
|
|
124
|
+
WidgetParams.PARAM_HEIGHT_PX,
|
|
125
125
|
WidgetParams.PARAM_NAME,
|
|
126
126
|
WidgetParams.PARAM_TITLE,
|
|
127
127
|
WidgetParams.PARAM_PREVIEW,
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import localforage from "localforage";
|
|
11
2
|
import { BroadcastEvent } from "../model/BroadcastEvent";
|
|
12
3
|
import { ElectronApi } from "../api/ElectronApi";
|
|
@@ -15,14 +6,12 @@ export class WidgetDataRepository {
|
|
|
15
6
|
* 保存组件数据
|
|
16
7
|
* @param data
|
|
17
8
|
*/
|
|
18
|
-
static save(data) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return result;
|
|
25
|
-
});
|
|
9
|
+
static async save(data) {
|
|
10
|
+
let store = this.getStore(data.name);
|
|
11
|
+
const result = await store.setItem(this.getKey(data.name, data.id), JSON.stringify(data));
|
|
12
|
+
const broadcastEvent = new BroadcastEvent(BroadcastEvent.TYPE_WIDGET_UPDATED, "", data);
|
|
13
|
+
await ElectronApi.sendBroadcastEvent(broadcastEvent);
|
|
14
|
+
return result;
|
|
26
15
|
}
|
|
27
16
|
/**
|
|
28
17
|
* 获取组件 LocalForage 存储实例
|
|
@@ -40,39 +29,33 @@ export class WidgetDataRepository {
|
|
|
40
29
|
* 通过组件名保存组件信息,通常用于存储可以在同类组件中共用的数据
|
|
41
30
|
* @param data
|
|
42
31
|
*/
|
|
43
|
-
static saveByName(data) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return result;
|
|
51
|
-
});
|
|
32
|
+
static async saveByName(data) {
|
|
33
|
+
const store = this.getStore(data.name);
|
|
34
|
+
const json = JSON.stringify(data);
|
|
35
|
+
const result = await store.setItem(data.name, json);
|
|
36
|
+
const broadcastEvent = new BroadcastEvent(BroadcastEvent.TYPE_WIDGET_UPDATED, "", { name: data.name, json });
|
|
37
|
+
await ElectronApi.sendBroadcastEvent(broadcastEvent);
|
|
38
|
+
return result;
|
|
52
39
|
}
|
|
53
|
-
static findByName(name, type) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return undefined;
|
|
63
|
-
});
|
|
40
|
+
static async findByName(name, type) {
|
|
41
|
+
let store = this.getStore(name);
|
|
42
|
+
let result = await store.getItem(name);
|
|
43
|
+
if (result) {
|
|
44
|
+
const widgetData = new type(name);
|
|
45
|
+
widgetData.parseJSON(JSON.parse(result));
|
|
46
|
+
return widgetData;
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
64
49
|
}
|
|
65
|
-
static find(name, id, type) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return undefined;
|
|
75
|
-
});
|
|
50
|
+
static async find(name, id, type) {
|
|
51
|
+
let store = this.getStore(name);
|
|
52
|
+
let result = await store.getItem(this.getKey(name, id));
|
|
53
|
+
if (result) {
|
|
54
|
+
const widgetData = new type(name, id);
|
|
55
|
+
widgetData.parseJSON(JSON.parse(result));
|
|
56
|
+
return widgetData;
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
76
59
|
}
|
|
77
60
|
static getKey(name, id) {
|
|
78
61
|
return `${name}@${id}`;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export class ElectronUtils {
|
|
2
|
+
static hasElectronApi() {
|
|
3
|
+
return Reflect.has(window, "electronAPI");
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* 获取ElectronAPI
|
|
7
|
+
* windows api
|
|
8
|
+
*/
|
|
9
|
+
static getAPI() {
|
|
10
|
+
if (Reflect.has(window, "electronAPI")) {
|
|
11
|
+
//@ts-ignore
|
|
12
|
+
return window.electronAPI;
|
|
13
|
+
}
|
|
14
|
+
else if (Reflect.has(window.parent, "electronAPI")) {
|
|
15
|
+
//@ts-ignore
|
|
16
|
+
return window.parent.electronAPI;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class BrowserWindowApi {
|
|
2
|
+
static readonly IGNORE_MOUSE_EVENT = "ignore-mouse-event";
|
|
3
|
+
static readonly WINDOW_VISIBILITY = "window-visibility";
|
|
4
|
+
static readonly ALWAYS_ON_TOP = "always-on-top";
|
|
5
|
+
static setIgnoreMouseEvent(ignore: boolean): Promise<void>;
|
|
6
|
+
static setWindowVisibility(show: boolean): Promise<void>;
|
|
7
|
+
static setAlwaysOnTop(alwaysOnTop: boolean): Promise<void>;
|
|
8
|
+
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { Widget } from "../model/Widget";
|
|
2
1
|
import { BroadcastEvent } from "../model/BroadcastEvent";
|
|
3
2
|
export declare class ElectronApi {
|
|
4
3
|
static openAddWidgetWindow(): void;
|
|
5
|
-
static registerWidgets(widgets: Widget[]): Promise<void>;
|
|
6
4
|
static setConfig(key: string, value: string | number | boolean): Promise<void>;
|
|
7
5
|
static sendBroadcastEvent(event: BroadcastEvent): Promise<void>;
|
|
8
6
|
static registerBroadcast(callback: (event: BroadcastEvent) => void): Promise<void>;
|
|
@@ -10,5 +8,5 @@ export declare class ElectronApi {
|
|
|
10
8
|
static addIpcListener(key: String, f: Function): Promise<void>;
|
|
11
9
|
static removeIpcListener(key: String): Promise<void>;
|
|
12
10
|
static getConfig(key: string, defaultValue: string | number | boolean): Promise<any>;
|
|
13
|
-
static
|
|
11
|
+
static upgradeNewVersion(key: string, defaultValue: string | number | boolean): Promise<any>;
|
|
14
12
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { NotificationType } from "../model/Notification";
|
|
2
|
+
type NotificationCallback = (type: NotificationType, message: string, duration: number) => void;
|
|
3
|
+
export declare class NotificationApi {
|
|
4
|
+
static call(duration?: number): Promise<void>;
|
|
5
|
+
static advanceCountdown(message: string, targetTime: string, title?: string): Promise<void>;
|
|
6
|
+
static countdown(message: string, targetTime: string): Promise<void>;
|
|
7
|
+
static success(message: string, duration?: number): Promise<void>;
|
|
8
|
+
static error(message: string, duration?: number): Promise<void>;
|
|
9
|
+
static warning(message: string, duration?: number): Promise<void>;
|
|
10
|
+
static message(message: string, duration?: number): Promise<void>;
|
|
11
|
+
private static callback;
|
|
12
|
+
static setDebugNotification(callback: NotificationCallback): void;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Widget } from "../model/Widget";
|
|
2
|
+
import { WidgetPackage } from "../model/WidgetPackage";
|
|
3
|
+
export declare class WidgetApi {
|
|
4
|
+
static registerWidgets(widgets: Widget[]): Promise<void>;
|
|
5
|
+
static registerWidgetPackage(widgetPackage: WidgetPackage): Promise<void>;
|
|
6
|
+
static getWidgets(): Promise<Widget[]>;
|
|
7
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,6 +2,12 @@ export * from "./model/Widget";
|
|
|
2
2
|
export * from "./model/BroadcastEvent";
|
|
3
3
|
export * from "./model/WidgetData";
|
|
4
4
|
export * from "./model/WidgetParams";
|
|
5
|
+
export * from "./model/Notification";
|
|
6
|
+
export * from "./model/WidgetPackage";
|
|
5
7
|
export * from "./api/ElectronApi";
|
|
6
|
-
export * from "./api/Keys";
|
|
7
8
|
export * from "./repository/WidgetDataRepository";
|
|
9
|
+
export * from "./api/BrowserWindowApi";
|
|
10
|
+
export * from "./api/NotificationApi";
|
|
11
|
+
export * from "./api/Channel";
|
|
12
|
+
export * from "./api/WidgetApi";
|
|
13
|
+
export * from "./utils/ElectronUtils";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type NotificationType = "call" | "message" | "countdown" | "advance-countdown" | "error" | "success" | "warning" | "info";
|
|
2
|
+
export type NotificationOption = {
|
|
3
|
+
type?: NotificationType;
|
|
4
|
+
title?: string;
|
|
5
|
+
message: string;
|
|
6
|
+
targetTime?: string;
|
|
7
|
+
duration?: number;
|
|
8
|
+
};
|
|
9
|
+
export declare class Notification {
|
|
10
|
+
type: NotificationType;
|
|
11
|
+
message: string;
|
|
12
|
+
title?: string;
|
|
13
|
+
targetTime?: string;
|
|
14
|
+
duration: number;
|
|
15
|
+
constructor(option: NotificationOption);
|
|
16
|
+
}
|