@widget-js/core 0.1.29 → 0.5.5
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 +25 -23
- package/dist/cjs/api/BaseApi.js +13 -0
- package/dist/cjs/api/BroadcastApi.js +14 -13
- package/dist/cjs/api/BrowserWindowApi.js +58 -63
- package/dist/cjs/api/Channel.js +3 -4
- package/dist/cjs/api/ClipboardApi.js +16 -11
- package/dist/cjs/api/DeviceApi.js +16 -7
- package/dist/cjs/api/DialogApi.js +8 -6
- package/dist/cjs/api/HostedWidgetApi.js +24 -36
- package/dist/cjs/api/LogApi.js +14 -10
- package/dist/cjs/api/NotificationApi.js +44 -70
- package/dist/cjs/api/ShortcutApi.js +23 -0
- package/dist/cjs/api/WidgetApi.js +46 -39
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/lang/LanguageCode.js +34 -0
- package/dist/cjs/model/Widget.js +4 -4
- package/dist/cjs/model/WidgetPackage.js +49 -2
- package/dist/cjs/model/event/BroadcastEvent.js +4 -8
- package/dist/cjs/model/msic/graphics.js +2 -0
- package/dist/cjs/repository/WidgetDataRepository.js +11 -5
- package/dist/cjs/utils/ElectronUtils.js +5 -1
- package/dist/cjs/utils/LanguageUtils.js +38 -0
- package/dist/esm/api/AppApi.js +24 -22
- package/dist/esm/api/BaseApi.js +9 -0
- package/dist/esm/api/BroadcastApi.js +13 -12
- package/dist/esm/api/BrowserWindowApi.js +56 -62
- package/dist/esm/api/Channel.js +3 -4
- package/dist/esm/api/ClipboardApi.js +15 -10
- package/dist/esm/api/DeviceApi.js +15 -6
- package/dist/esm/api/DialogApi.js +9 -6
- package/dist/esm/api/HostedWidgetApi.js +23 -35
- package/dist/esm/api/LogApi.js +15 -10
- package/dist/esm/api/NotificationApi.js +45 -70
- package/dist/esm/api/ShortcutApi.js +19 -0
- package/dist/esm/api/WidgetApi.js +45 -38
- package/dist/esm/index.js +2 -1
- package/dist/esm/lang/LanguageCode.js +33 -0
- package/dist/esm/model/Widget.js +4 -4
- package/dist/esm/model/WidgetPackage.js +49 -2
- package/dist/esm/model/event/BroadcastEvent.js +4 -8
- package/dist/esm/model/msic/graphics.js +1 -0
- package/dist/esm/repository/WidgetDataRepository.js +11 -5
- package/dist/esm/utils/ElectronUtils.js +5 -1
- package/dist/esm/utils/LanguageUtils.js +34 -0
- package/dist/types/api/AppApi.d.ts +23 -11
- package/dist/types/api/BaseApi.d.ts +5 -0
- package/dist/types/api/BroadcastApi.d.ts +19 -4
- package/dist/types/api/BrowserWindowApi.d.ts +56 -46
- package/dist/types/api/Channel.d.ts +4 -5
- package/dist/types/api/ClipboardApi.d.ts +9 -5
- package/dist/types/api/DeviceApi.d.ts +16 -7
- package/dist/types/api/DialogApi.d.ts +5 -7
- package/dist/types/api/HostedWidgetApi.d.ts +24 -18
- package/dist/types/api/LogApi.d.ts +8 -5
- package/dist/types/api/NotificationApi.d.ts +21 -16
- package/dist/types/api/ShortcutApi.d.ts +10 -0
- package/dist/types/api/WidgetApi.d.ts +39 -20
- package/dist/types/index.d.ts +2 -1
- package/dist/types/lang/LanguageCode.d.ts +40 -0
- package/dist/types/model/Widget.d.ts +7 -9
- package/dist/types/model/WidgetPackage.d.ts +55 -12
- package/dist/types/model/event/BroadcastEvent.d.ts +14 -10
- package/dist/types/model/msic/graphics.d.ts +8 -0
- package/dist/types/utils/ElectronUtils.d.ts +2 -1
- package/dist/types/utils/LanguageUtils.d.ts +8 -0
- package/dist/umd/index.js +1 -1
- package/package.json +15 -15
- package/dist/cjs/api/GlobalShortcutApi.js +0 -29
- package/dist/esm/api/GlobalShortcutApi.js +0 -25
- package/dist/types/api/GlobalShortcutApi.d.ts +0 -14
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AppNotification } from "../model/AppNotification";
|
|
2
2
|
import { Channel } from "./Channel";
|
|
3
3
|
import { ElectronUtils } from "../utils/ElectronUtils";
|
|
4
|
-
|
|
4
|
+
import { BaseApi } from "./BaseApi";
|
|
5
|
+
class NotificationApiImpl extends BaseApi {
|
|
5
6
|
// static async url(url: string, duration: number = -1) {
|
|
6
|
-
//
|
|
7
|
+
// this.invoke(Channel.NOTIFICATION, new AppNotification({
|
|
7
8
|
// url, message: "",
|
|
8
9
|
// duration,
|
|
9
10
|
// type: "url",
|
|
@@ -17,9 +18,8 @@ export class NotificationApi {
|
|
|
17
18
|
* @param message 初始消息
|
|
18
19
|
* @param lyric 歌词字符串
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, new AppNotification({
|
|
21
|
+
async call(avatar, audio, title, message, lyric) {
|
|
22
|
+
this.invoke(new AppNotification({
|
|
23
23
|
avatar,
|
|
24
24
|
audio,
|
|
25
25
|
message,
|
|
@@ -29,11 +29,10 @@ export class NotificationApi {
|
|
|
29
29
|
type: "call",
|
|
30
30
|
}));
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return (_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, notification);
|
|
32
|
+
async send(notification) {
|
|
33
|
+
return this.invokeMethod('send', notification);
|
|
35
34
|
}
|
|
36
|
-
|
|
35
|
+
async reminder(title, message, icon, cancelButtonText, confirmButtonText, cancelBroadcast, confirmBroadcast, duration = 5000) {
|
|
37
36
|
return await this.send(new AppNotification({
|
|
38
37
|
icon,
|
|
39
38
|
message,
|
|
@@ -46,7 +45,7 @@ export class NotificationApi {
|
|
|
46
45
|
type: "reminder",
|
|
47
46
|
}));
|
|
48
47
|
}
|
|
49
|
-
|
|
48
|
+
async advanceCountdown(message, targetTime, title) {
|
|
50
49
|
return await this.send(new AppNotification({
|
|
51
50
|
title,
|
|
52
51
|
message,
|
|
@@ -54,9 +53,8 @@ export class NotificationApi {
|
|
|
54
53
|
type: "advance-countdown"
|
|
55
54
|
}));
|
|
56
55
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, new AppNotification({
|
|
56
|
+
async countdown(message, targetTime) {
|
|
57
|
+
this.send(new AppNotification({
|
|
60
58
|
message,
|
|
61
59
|
targetTime,
|
|
62
60
|
backgroundColor: 'rgba(0,0,0,0.5)',
|
|
@@ -64,72 +62,49 @@ export class NotificationApi {
|
|
|
64
62
|
type: "countdown"
|
|
65
63
|
}));
|
|
66
64
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
duration
|
|
75
|
-
}));
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
this.callback("success", message, duration);
|
|
79
|
-
}
|
|
65
|
+
async success(message, duration = 5000) {
|
|
66
|
+
this.send(new AppNotification({
|
|
67
|
+
message,
|
|
68
|
+
type: "success",
|
|
69
|
+
icon: "check_circle_line",
|
|
70
|
+
duration
|
|
71
|
+
}));
|
|
80
72
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
duration
|
|
89
|
-
}));
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
this.callback("error", message, duration);
|
|
93
|
-
}
|
|
73
|
+
async error(message, duration = 5000) {
|
|
74
|
+
this.send(new AppNotification({
|
|
75
|
+
message,
|
|
76
|
+
type: "error",
|
|
77
|
+
icon: "close_circle_line",
|
|
78
|
+
duration
|
|
79
|
+
}));
|
|
94
80
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
duration
|
|
103
|
-
}));
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
this.callback("warning", message, duration);
|
|
107
|
-
}
|
|
81
|
+
async warning(message, duration = 5000) {
|
|
82
|
+
this.send(new AppNotification({
|
|
83
|
+
message,
|
|
84
|
+
type: "warning",
|
|
85
|
+
icon: "warning_line",
|
|
86
|
+
duration
|
|
87
|
+
}));
|
|
108
88
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
duration
|
|
117
|
-
}));
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
this.callback("info", message, duration);
|
|
121
|
-
}
|
|
89
|
+
async info(message, duration = 5000) {
|
|
90
|
+
this.send(new AppNotification({
|
|
91
|
+
message,
|
|
92
|
+
type: "info",
|
|
93
|
+
icon: "information_line",
|
|
94
|
+
duration
|
|
95
|
+
}));
|
|
122
96
|
}
|
|
123
97
|
/**
|
|
124
98
|
* 隐藏通知
|
|
125
99
|
*/
|
|
126
|
-
|
|
127
|
-
var _a;
|
|
100
|
+
async hide() {
|
|
128
101
|
if (ElectronUtils.hasElectronApi()) {
|
|
129
|
-
|
|
102
|
+
this.invokeMethod('hide');
|
|
130
103
|
}
|
|
131
104
|
}
|
|
132
|
-
|
|
133
|
-
|
|
105
|
+
getChannel() {
|
|
106
|
+
return Channel.NOTIFICATION;
|
|
134
107
|
}
|
|
135
108
|
}
|
|
109
|
+
const NotificationApi = new NotificationApiImpl();
|
|
110
|
+
export { NotificationApi };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseApi } from "./BaseApi";
|
|
2
|
+
import { Channel } from "./Channel";
|
|
3
|
+
var ShortcutApiEvent;
|
|
4
|
+
(function (ShortcutApiEvent) {
|
|
5
|
+
ShortcutApiEvent["TRIGGERED"] = "channel::cn.widgetjs.core.shortcut.triggered";
|
|
6
|
+
})(ShortcutApiEvent || (ShortcutApiEvent = {}));
|
|
7
|
+
class ShortcutApiImpl extends BaseApi {
|
|
8
|
+
getChannel() {
|
|
9
|
+
return Channel.SHORTCUT;
|
|
10
|
+
}
|
|
11
|
+
async register(shortcut) {
|
|
12
|
+
return await this.invokeMethod('register', shortcut);
|
|
13
|
+
}
|
|
14
|
+
async unregister(shortcut) {
|
|
15
|
+
return await this.invokeMethod('unregister', shortcut);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const ShortcutApi = new ShortcutApiImpl();
|
|
19
|
+
export { ShortcutApi, ShortcutApiEvent };
|
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
import { Widget } from "../model/Widget";
|
|
2
|
-
import { ElectronUtils } from "../utils/ElectronUtils";
|
|
3
2
|
import { WidgetPackage } from "../model/WidgetPackage";
|
|
4
3
|
import { Channel } from "./Channel";
|
|
5
4
|
import { UrlUtils } from "../utils/UrlUtils";
|
|
6
5
|
import { BroadcastEvent } from "../model/event/BroadcastEvent";
|
|
7
6
|
import { BroadcastApi } from "./BroadcastApi";
|
|
8
7
|
import localforage from "localforage";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
import { BaseApi } from "./BaseApi";
|
|
9
|
+
var WidgetApiEvent;
|
|
10
|
+
(function (WidgetApiEvent) {
|
|
11
|
+
WidgetApiEvent["DATA_CHANGED"] = "event::cn.widgetjs.core.widget.data0changed";
|
|
12
|
+
WidgetApiEvent["EDIT_DESKTOP_WIDGETS"] = "event::cn.widgetjs.core.widget.desktop.edit";
|
|
13
|
+
})(WidgetApiEvent || (WidgetApiEvent = {}));
|
|
14
|
+
class WidgetApiImpl extends BaseApi {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(...arguments);
|
|
17
|
+
this.stores = new Map();
|
|
13
18
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.WIDGET, this.REGISTER_WIDGET_PACKAGE, JSON.stringify(widgetPackage)));
|
|
19
|
+
getChannel() {
|
|
20
|
+
return Channel.WIDGET;
|
|
17
21
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
async registerWidgets(widgets) {
|
|
23
|
+
return this.invokeMethod("registerWidgets", JSON.stringify(widgets));
|
|
24
|
+
}
|
|
25
|
+
async registerWidgetPackage(widgetPackage) {
|
|
26
|
+
return this.invokeMethod("registerWidgetPackage", JSON.stringify(widgetPackage));
|
|
27
|
+
}
|
|
28
|
+
async getWidgets() {
|
|
29
|
+
const data = await this.invokeMethod('getWidgets');
|
|
21
30
|
const widgets = [];
|
|
22
31
|
if (data) {
|
|
23
32
|
for (const item of data) {
|
|
@@ -26,31 +35,28 @@ export class WidgetApi {
|
|
|
26
35
|
}
|
|
27
36
|
return widgets;
|
|
28
37
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.WIDGET, this.GET_WIDGET_PACKAGES));
|
|
38
|
+
async getWidgetPackages() {
|
|
39
|
+
return await this.invokeMethod('getWidgetPackages');
|
|
32
40
|
}
|
|
33
41
|
/**
|
|
34
42
|
*
|
|
35
43
|
* @param name package name
|
|
36
44
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return Widget.parseObject(await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.WIDGET, this.GET_WIDGET, name)));
|
|
45
|
+
async getWidget(name) {
|
|
46
|
+
return Widget.parseObject(await this.invokeMethod('getWidget', name));
|
|
40
47
|
}
|
|
41
48
|
/**
|
|
42
49
|
*
|
|
43
50
|
* @param name package name
|
|
44
51
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return WidgetPackage.parseObject(await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.WIDGET, this.GET_WIDGET_PACKAGE, name)));
|
|
52
|
+
async getWidgetPackage(name) {
|
|
53
|
+
return WidgetPackage.parseObject(await this.invokeMethod('getWidgetPackage', name));
|
|
48
54
|
}
|
|
49
55
|
/**
|
|
50
56
|
* 获取组件配置地址
|
|
51
57
|
* @param widgetName
|
|
52
58
|
*/
|
|
53
|
-
|
|
59
|
+
async getWidgetConfigUrl(widgetName, widgetParams) {
|
|
54
60
|
const widget = await this.getWidget(widgetName);
|
|
55
61
|
if (!widget)
|
|
56
62
|
return null;
|
|
@@ -62,7 +68,7 @@ export class WidgetApi {
|
|
|
62
68
|
return null;
|
|
63
69
|
return UrlUtils.getWidgetUrl(configRoute.url, widgetPackage, widgetParams);
|
|
64
70
|
}
|
|
65
|
-
|
|
71
|
+
async getWidgetUrl(widgetName, widgetParams) {
|
|
66
72
|
const widget = await this.getWidget(widgetName);
|
|
67
73
|
if (!widget)
|
|
68
74
|
return null;
|
|
@@ -72,13 +78,13 @@ export class WidgetApi {
|
|
|
72
78
|
return null;
|
|
73
79
|
return UrlUtils.getWidgetUrl(indexRoute.url, widgetPackage, widgetParams);
|
|
74
80
|
}
|
|
75
|
-
|
|
81
|
+
async getWidgetPackageIndexUrl(packageName, hash) {
|
|
76
82
|
const widgetPackage = await this.getWidgetPackage(packageName);
|
|
77
83
|
if (!widgetPackage)
|
|
78
84
|
return null;
|
|
79
85
|
return widgetPackage.getIndexUrl(hash);
|
|
80
86
|
}
|
|
81
|
-
|
|
87
|
+
async getWidgetPackageUrl(packageName) {
|
|
82
88
|
const widgetPackage = await this.getWidgetPackage(packageName);
|
|
83
89
|
if (!widgetPackage)
|
|
84
90
|
return null;
|
|
@@ -89,17 +95,20 @@ export class WidgetApi {
|
|
|
89
95
|
* @param data
|
|
90
96
|
* @param options
|
|
91
97
|
*/
|
|
92
|
-
|
|
98
|
+
async saveDataByName(data, options = { sendBroadcast: true }) {
|
|
93
99
|
const store = this.getStore(data.name);
|
|
94
100
|
const json = JSON.stringify(data);
|
|
95
101
|
const result = await store.setItem(data.name, json);
|
|
96
102
|
if (options.sendBroadcast) {
|
|
97
|
-
const broadcastEvent = new BroadcastEvent(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
103
|
+
const broadcastEvent = new BroadcastEvent({
|
|
104
|
+
event: WidgetApiEvent.DATA_CHANGED,
|
|
105
|
+
payload: {
|
|
106
|
+
name: data.name,
|
|
107
|
+
id: options.id,
|
|
108
|
+
json
|
|
109
|
+
}
|
|
101
110
|
});
|
|
102
|
-
await BroadcastApi.
|
|
111
|
+
await BroadcastApi.send(broadcastEvent);
|
|
103
112
|
}
|
|
104
113
|
return result;
|
|
105
114
|
}
|
|
@@ -107,7 +116,7 @@ export class WidgetApi {
|
|
|
107
116
|
* 获取组件 LocalForage 存储实例
|
|
108
117
|
* @param name
|
|
109
118
|
*/
|
|
110
|
-
|
|
119
|
+
getStore(name) {
|
|
111
120
|
if (this.stores.has(name)) {
|
|
112
121
|
return this.stores.get(name);
|
|
113
122
|
}
|
|
@@ -115,11 +124,9 @@ export class WidgetApi {
|
|
|
115
124
|
this.stores.set(name, store);
|
|
116
125
|
return store;
|
|
117
126
|
}
|
|
127
|
+
addWidget(widgetName, hostMode) {
|
|
128
|
+
return this.invokeMethod('addWidget', widgetName, hostMode);
|
|
129
|
+
}
|
|
118
130
|
}
|
|
119
|
-
WidgetApi
|
|
120
|
-
WidgetApi
|
|
121
|
-
WidgetApi.GET_WIDGETS = "get-widgets";
|
|
122
|
-
WidgetApi.GET_WIDGET = "get-widget";
|
|
123
|
-
WidgetApi.GET_WIDGET_PACKAGE = "get-widget-package";
|
|
124
|
-
WidgetApi.GET_WIDGET_PACKAGES = "get-widget-packages";
|
|
125
|
-
WidgetApi.stores = new Map();
|
|
131
|
+
const WidgetApi = new WidgetApiImpl();
|
|
132
|
+
export { WidgetApi, WidgetApiEvent };
|
package/dist/esm/index.js
CHANGED
|
@@ -13,7 +13,7 @@ export * from "./model/WidgetPackage";
|
|
|
13
13
|
export * from "./api/ElectronApi";
|
|
14
14
|
export * from "./repository/WidgetDataRepository";
|
|
15
15
|
export * from "./api/BrowserWindowApi";
|
|
16
|
-
export * from "./
|
|
16
|
+
export * from "./lang/LanguageCode";
|
|
17
17
|
export * from "./api/NotificationApi";
|
|
18
18
|
export * from "./api/HostedWidgetApi";
|
|
19
19
|
export * from "./api/DeviceApi";
|
|
@@ -21,6 +21,7 @@ export * from "./api/Channel";
|
|
|
21
21
|
export * from "./api/ClipboardApi";
|
|
22
22
|
export * from "./api/WidgetApi";
|
|
23
23
|
export * from "./api/ApiConstants";
|
|
24
|
+
export * from "./api/ShortcutApi";
|
|
24
25
|
export * from "./api/BroadcastApi";
|
|
25
26
|
export * from "./api/AppApi";
|
|
26
27
|
export * from "./api/DialogApi";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
class LanguageMapImpl {
|
|
2
|
+
constructor() {
|
|
3
|
+
this['ar-SA'] = { locale: 'ar-SA', language: 'العربية', code: 'ar' };
|
|
4
|
+
this['bn-BD'] = { locale: 'bn-BD', language: 'বাংলা', code: 'bn' };
|
|
5
|
+
this['en-US'] = { locale: 'en-US', language: 'English', code: 'en' };
|
|
6
|
+
this['de-DE'] = { locale: 'de-DE', language: 'Deutsch', code: 'de' };
|
|
7
|
+
this['el-GR'] = { locale: 'el-GR', language: 'Ελληνικά', code: 'el' };
|
|
8
|
+
this['es-ES'] = { locale: 'es-ES', language: 'Español', code: 'es-ES' };
|
|
9
|
+
this['fi-FI'] = { locale: 'fi-FI', language: 'Suomalainen', code: 'fi' };
|
|
10
|
+
this['fil-PH'] = { locale: 'fil-PH', language: 'Filipino', code: 'fil' };
|
|
11
|
+
this['fr-FR'] = { locale: 'fr-FR', language: 'Français', code: 'fr' };
|
|
12
|
+
this['hi-IN'] = { locale: 'hi-IN', language: 'हिंदी', code: 'hi' };
|
|
13
|
+
this['hu-HU'] = { locale: 'hu-HU', language: 'Magyar', code: 'hu' };
|
|
14
|
+
this['id-ID'] = { locale: 'id-ID', language: 'Bahasa Indonesia', code: 'id' };
|
|
15
|
+
this['it-IT'] = { locale: 'it-IT', language: 'Italiano', code: 'it' };
|
|
16
|
+
this['ja-JP'] = { locale: 'ja-JP', language: '日本語', code: 'ja' };
|
|
17
|
+
this['ko-KR'] = { locale: 'ko-KR', language: '한국어', code: 'ko' };
|
|
18
|
+
this['nl-NL'] = { locale: 'nl-NL', language: 'Nederlands', code: 'nl' };
|
|
19
|
+
this['pl-PL'] = { locale: 'pl-PL', language: 'Polski', code: 'pl' };
|
|
20
|
+
this['pt-BR'] = { locale: 'pt-BR', language: 'Português (Brazil)', code: 'pt-br' };
|
|
21
|
+
this['pt-PT'] = { locale: 'pt-PT', language: 'Português', code: 'pt-pt' };
|
|
22
|
+
this['ro-RO'] = { locale: 'ro-RO', language: 'Română', code: 'ro' };
|
|
23
|
+
this['ru-RU'] = { locale: 'ru-RU', language: 'Русский', code: 'ru' };
|
|
24
|
+
this['sv-SE'] = { locale: 'sv-SE', language: 'Svenska', code: 'sv' };
|
|
25
|
+
this['ta-IN'] = { locale: 'ta-IN', language: 'தமிழ்', code: 'ta' };
|
|
26
|
+
this['tr-TR'] = { locale: 'tr-TR', language: 'Türkçe', code: 'tr' };
|
|
27
|
+
this['uk-UA'] = { locale: 'uk-UA', language: 'Українська', code: 'uk' };
|
|
28
|
+
this['vi-VN'] = { locale: 'vi-VN', language: 'Tiếng Việt', code: 'vi' };
|
|
29
|
+
this['zh-CN'] = { locale: 'zh-CN', language: '简体中文', code: 'zh-cn' };
|
|
30
|
+
this['zh-TW'] = { locale: 'zh-TW', language: '繁體中文', code: 'zh-tw' };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export {};
|
package/dist/esm/model/Widget.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HostedMode } from "./HostedMode";
|
|
2
|
+
import { getTextByLanguageCode } from "../utils/LanguageUtils";
|
|
2
3
|
export class Widget {
|
|
3
4
|
constructor(options) {
|
|
4
5
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
@@ -43,15 +44,14 @@ export class Widget {
|
|
|
43
44
|
* @param lang 语言环境,不传则获取默认语言
|
|
44
45
|
*/
|
|
45
46
|
getTitle(lang) {
|
|
46
|
-
|
|
47
|
-
return lang ? (_a = this.title[lang]) !== null && _a !== void 0 ? _a : this.title[this.lang] : this.title[this.lang];
|
|
47
|
+
return getTextByLanguageCode(this.title, lang);
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
50
|
+
* 获取组件描述
|
|
51
51
|
* @param lang 语言环境,不传则获取默认标题
|
|
52
52
|
*/
|
|
53
53
|
getDescription(lang) {
|
|
54
|
-
return
|
|
54
|
+
return getTextByLanguageCode(this.description, lang);
|
|
55
55
|
}
|
|
56
56
|
static parseJSON(json) {
|
|
57
57
|
const object = JSON.parse(json);
|
|
@@ -1,20 +1,67 @@
|
|
|
1
1
|
import { UrlUtils } from "../utils/UrlUtils";
|
|
2
|
+
import { getTextByLanguageCode } from "../utils/LanguageUtils";
|
|
2
3
|
export class WidgetPackage {
|
|
3
|
-
constructor() {
|
|
4
|
+
constructor(options) {
|
|
4
5
|
/**
|
|
5
6
|
* Hash路由模式,默认为true
|
|
6
7
|
*/
|
|
7
8
|
this.hash = true;
|
|
9
|
+
this.widgets = [];
|
|
10
|
+
this.name = options.name;
|
|
11
|
+
this.version = options.version;
|
|
12
|
+
this.author = options.author;
|
|
13
|
+
this.homepage = options.homepage;
|
|
14
|
+
this.title = options.title;
|
|
15
|
+
this.description = options.description;
|
|
16
|
+
this.entry = options.entry;
|
|
17
|
+
this.remoteEntry = options.remoteEntry;
|
|
18
|
+
this.remotePackage = options.remotePackage;
|
|
19
|
+
this.hash = options.hash;
|
|
20
|
+
this.url = options.url;
|
|
21
|
+
this.devOptions = options.devOptions;
|
|
22
|
+
if (options.widgets) {
|
|
23
|
+
for (let widget of options.widgets) {
|
|
24
|
+
this.widgets.push(widget);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
8
27
|
}
|
|
9
28
|
static parseJSON(json) {
|
|
10
29
|
const object = JSON.parse(json);
|
|
11
30
|
return this.parseObject(object);
|
|
12
31
|
}
|
|
13
32
|
static parseObject(obj) {
|
|
14
|
-
let widgetPackage = new WidgetPackage(
|
|
33
|
+
let widgetPackage = new WidgetPackage({
|
|
34
|
+
author: "",
|
|
35
|
+
description: {
|
|
36
|
+
"zh-CN": "",
|
|
37
|
+
},
|
|
38
|
+
entry: "",
|
|
39
|
+
hash: false,
|
|
40
|
+
homepage: "",
|
|
41
|
+
name: "",
|
|
42
|
+
title: {
|
|
43
|
+
"zh-CN": "",
|
|
44
|
+
},
|
|
45
|
+
url: "",
|
|
46
|
+
version: ""
|
|
47
|
+
});
|
|
15
48
|
Object.assign(widgetPackage, obj);
|
|
16
49
|
return widgetPackage;
|
|
17
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* 获取组件包标题
|
|
53
|
+
* @param lang 语言环境,不传则获取默认语言
|
|
54
|
+
*/
|
|
55
|
+
getTitle(lang) {
|
|
56
|
+
return getTextByLanguageCode(this.title, lang);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 获取组件包描述
|
|
60
|
+
* @param lang 语言环境,不传则获取默认标题
|
|
61
|
+
*/
|
|
62
|
+
getDescription(lang) {
|
|
63
|
+
return getTextByLanguageCode(this.description, lang);
|
|
64
|
+
}
|
|
18
65
|
/**
|
|
19
66
|
* 获取组件完整路径
|
|
20
67
|
* 如果url是http链接,直接返回链接
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
export class BroadcastEvent {
|
|
2
|
-
constructor(
|
|
3
|
-
this.
|
|
4
|
-
this.
|
|
5
|
-
this.payload = payload;
|
|
2
|
+
constructor(options) {
|
|
3
|
+
this.event = options.event;
|
|
4
|
+
this.sender = options.sender;
|
|
5
|
+
this.payload = options.payload;
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
-
BroadcastEvent.TYPE_WIDGET_UPDATED = "broadcast::cn.widgetjs.core.widget_updated";
|
|
9
|
-
BroadcastEvent.TYPE_APP_CONFIG_UPDATED = "broadcast::cn.widgetjs.core.app_config_updated";
|
|
10
|
-
BroadcastEvent.TYPE_THEME_CHANGED = "broadcast::cn.widgetjs.core.theme_changed";
|
|
11
|
-
BroadcastEvent.TYPE_EDIT_DESKTOP_WIDGETS = "broadcast::cn.widgetjs.core.edit_desktop_widgets";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import localforage from "localforage";
|
|
2
2
|
import { BroadcastEvent } from "../model/event/BroadcastEvent";
|
|
3
3
|
import { BroadcastApi } from "../api/BroadcastApi";
|
|
4
|
+
import { WidgetApiEvent } from "../api/WidgetApi";
|
|
4
5
|
export class WidgetDataRepository {
|
|
5
6
|
/**
|
|
6
7
|
* 保存组件数据
|
|
@@ -8,9 +9,12 @@ export class WidgetDataRepository {
|
|
|
8
9
|
*/
|
|
9
10
|
static async save(data) {
|
|
10
11
|
let store = this.getStore(data.name);
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
12
|
+
let json = JSON.stringify(data);
|
|
13
|
+
const result = await store.setItem(this.getKey(data.name, data.id), json);
|
|
14
|
+
const broadcastEvent = new BroadcastEvent({
|
|
15
|
+
event: WidgetApiEvent.DATA_CHANGED, payload: { name: data.name, json }
|
|
16
|
+
});
|
|
17
|
+
await BroadcastApi.send(broadcastEvent);
|
|
14
18
|
return result;
|
|
15
19
|
}
|
|
16
20
|
/**
|
|
@@ -33,8 +37,10 @@ export class WidgetDataRepository {
|
|
|
33
37
|
const store = this.getStore(data.name);
|
|
34
38
|
const json = JSON.stringify(data);
|
|
35
39
|
const result = await store.setItem(data.name, json);
|
|
36
|
-
const broadcastEvent = new BroadcastEvent(
|
|
37
|
-
|
|
40
|
+
const broadcastEvent = new BroadcastEvent({
|
|
41
|
+
event: WidgetApiEvent.DATA_CHANGED, payload: { name: data.name, json }
|
|
42
|
+
});
|
|
43
|
+
await BroadcastApi.send(broadcastEvent);
|
|
38
44
|
return result;
|
|
39
45
|
}
|
|
40
46
|
static async findByName(name, type) {
|
|
@@ -17,8 +17,12 @@ export class ElectronUtils {
|
|
|
17
17
|
}
|
|
18
18
|
return null;
|
|
19
19
|
}
|
|
20
|
-
static async
|
|
20
|
+
static async invokeMethod(channel, method, ...args) {
|
|
21
21
|
var _a;
|
|
22
22
|
return (_a = this.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(channel, method, ...args);
|
|
23
23
|
}
|
|
24
|
+
static async invoke(channel, ...args) {
|
|
25
|
+
var _a;
|
|
26
|
+
return (_a = this.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(channel, ...args);
|
|
27
|
+
}
|
|
24
28
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 根据语言环境获取文本
|
|
3
|
+
* @param obj 对象
|
|
4
|
+
* @param key 属性名
|
|
5
|
+
* @param {LanguageCode} langCode 语言环境 例如:zh-CN,en-US
|
|
6
|
+
*/
|
|
7
|
+
export function getTextByLanguageCode(obj, langCode) {
|
|
8
|
+
let result;
|
|
9
|
+
if (langCode) {
|
|
10
|
+
if (langCode in obj) {
|
|
11
|
+
return obj[langCode];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
// fallback to browser default language
|
|
15
|
+
if (result == undefined) {
|
|
16
|
+
if (typeof navigator != 'undefined' && navigator.languages) {
|
|
17
|
+
for (let language of navigator.languages) {
|
|
18
|
+
const langCode = language;
|
|
19
|
+
result = getTextByLanguageCode(obj, langCode);
|
|
20
|
+
if (result != undefined) {
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// fallback to first language
|
|
27
|
+
if (result == undefined) {
|
|
28
|
+
let langCode = Object.keys(obj);
|
|
29
|
+
if (langCode.length > 0) {
|
|
30
|
+
return obj[langCode[0]];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { BaseApi } from "./BaseApi";
|
|
2
|
+
interface IAppApi {
|
|
3
|
+
setConfig(key: string, value: string | number | boolean): Promise<void>;
|
|
4
|
+
getConfig(key: string, defaultValue: string | number | boolean): Promise<string | number | boolean>;
|
|
5
|
+
getVersion(): Promise<string>;
|
|
6
|
+
getPreloadPath(): Promise<string>;
|
|
7
|
+
openAddWidgetWindow(): Promise<void>;
|
|
8
|
+
openSettingWindow(): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
type AppApiMethods = keyof IAppApi;
|
|
11
|
+
declare enum AppApiEvent {
|
|
12
|
+
CONFIG_CHANGED = "event::cn.widgetjs.core.app.config.changed"
|
|
13
|
+
}
|
|
14
|
+
declare class AppApiImpl extends BaseApi<AppApiMethods> implements IAppApi {
|
|
15
|
+
getChannel(): string;
|
|
16
|
+
setConfig(key: string, value: string | number | boolean): Promise<any>;
|
|
17
|
+
getConfig(key: string, defaultValue: string | number | boolean): Promise<string | number | boolean>;
|
|
18
|
+
openAddWidgetWindow(): Promise<any>;
|
|
10
19
|
/**
|
|
11
20
|
* 获取应用版本号,格式为 x.y.z
|
|
12
21
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
22
|
+
getVersion(): Promise<string>;
|
|
23
|
+
getPreloadPath(): Promise<string>;
|
|
24
|
+
openSettingWindow(): Promise<any>;
|
|
15
25
|
}
|
|
26
|
+
declare const AppApi: AppApiImpl;
|
|
27
|
+
export { AppApi, AppApiEvent, AppApiMethods };
|