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