@widget-js/core 0.1.31 → 0.5.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/AppApi.js +24 -21
- package/dist/cjs/api/BaseApi.js +13 -0
- package/dist/cjs/api/BroadcastApi.js +14 -13
- package/dist/cjs/api/BrowserWindowApi.js +55 -72
- package/dist/cjs/api/Channel.js +1 -1
- package/dist/cjs/api/ClipboardApi.js +16 -11
- package/dist/cjs/api/DeviceApi.js +12 -9
- package/dist/cjs/api/DialogApi.js +8 -6
- package/dist/cjs/api/HostedWidgetApi.js +27 -36
- package/dist/cjs/api/LogApi.js +14 -10
- package/dist/cjs/api/NotificationApi.js +52 -74
- package/dist/cjs/api/ShortcutApi.js +23 -0
- package/dist/cjs/api/WidgetApi.js +29 -69
- package/dist/cjs/{repository/WidgetDataRepository.js → api/WidgetDataApi.js} +19 -10
- package/dist/cjs/index.js +3 -2
- 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/utils/ElectronUtils.js +5 -1
- package/dist/cjs/utils/LanguageUtils.js +36 -0
- package/dist/esm/api/AppApi.js +23 -20
- package/dist/esm/api/BaseApi.js +9 -0
- package/dist/esm/api/BroadcastApi.js +13 -12
- package/dist/esm/api/BrowserWindowApi.js +53 -71
- package/dist/esm/api/Channel.js +1 -1
- package/dist/esm/api/ClipboardApi.js +15 -10
- package/dist/esm/api/DeviceApi.js +11 -8
- package/dist/esm/api/DialogApi.js +9 -6
- package/dist/esm/api/HostedWidgetApi.js +26 -35
- package/dist/esm/api/LogApi.js +15 -10
- package/dist/esm/api/NotificationApi.js +51 -73
- package/dist/esm/api/ShortcutApi.js +19 -0
- package/dist/esm/api/WidgetApi.js +28 -65
- package/dist/esm/{repository/WidgetDataRepository.js → api/WidgetDataApi.js} +17 -8
- package/dist/esm/index.js +3 -2
- 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/utils/ElectronUtils.js +5 -1
- package/dist/esm/utils/LanguageUtils.js +32 -0
- package/dist/types/api/AppApi.d.ts +23 -13
- 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 -52
- package/dist/types/api/Channel.d.ts +1 -1
- package/dist/types/api/ClipboardApi.d.ts +9 -5
- package/dist/types/api/DeviceApi.d.ts +13 -9
- package/dist/types/api/DialogApi.d.ts +5 -7
- package/dist/types/api/HostedWidgetApi.d.ts +28 -18
- package/dist/types/api/LogApi.d.ts +8 -5
- package/dist/types/api/NotificationApi.d.ts +26 -16
- package/dist/types/api/ShortcutApi.d.ts +10 -0
- package/dist/types/api/WidgetApi.d.ts +31 -33
- package/dist/types/{repository/WidgetDataRepository.d.ts → api/WidgetDataApi.d.ts} +7 -2
- package/dist/types/index.d.ts +3 -2
- 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 +4 -2
- 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,15 @@
|
|
|
1
1
|
import { AppNotification } from "../model/AppNotification";
|
|
2
2
|
import { Channel } from "./Channel";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { BaseApi } from "./BaseApi";
|
|
4
|
+
var NotificationApiEvent;
|
|
5
|
+
(function (NotificationApiEvent) {
|
|
6
|
+
NotificationApiEvent["CONFIRM"] = "event::cn.widgetjs.core.notification.confirm";
|
|
7
|
+
NotificationApiEvent["CANCEL"] = "event::cn.widgetjs.core.notification.cancel";
|
|
8
|
+
NotificationApiEvent["HIDE"] = "event::cn.widgetjs.core.notification.hide";
|
|
9
|
+
})(NotificationApiEvent || (NotificationApiEvent = {}));
|
|
10
|
+
class NotificationApiImpl extends BaseApi {
|
|
5
11
|
// static async url(url: string, duration: number = -1) {
|
|
6
|
-
//
|
|
12
|
+
// this.invoke(Channel.NOTIFICATION, new AppNotification({
|
|
7
13
|
// url, message: "",
|
|
8
14
|
// duration,
|
|
9
15
|
// type: "url",
|
|
@@ -17,9 +23,8 @@ export class NotificationApi {
|
|
|
17
23
|
* @param message 初始消息
|
|
18
24
|
* @param lyric 歌词字符串
|
|
19
25
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, new AppNotification({
|
|
26
|
+
async call(avatar, audio, title, message, lyric) {
|
|
27
|
+
await this.invoke(new AppNotification({
|
|
23
28
|
avatar,
|
|
24
29
|
audio,
|
|
25
30
|
message,
|
|
@@ -29,11 +34,10 @@ export class NotificationApi {
|
|
|
29
34
|
type: "call",
|
|
30
35
|
}));
|
|
31
36
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return (_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, notification);
|
|
37
|
+
async send(notification) {
|
|
38
|
+
return this.invokeMethod('send', notification);
|
|
35
39
|
}
|
|
36
|
-
|
|
40
|
+
async reminder(title, message, icon, cancelButtonText, confirmButtonText, cancelBroadcast, confirmBroadcast, duration = 5000) {
|
|
37
41
|
return await this.send(new AppNotification({
|
|
38
42
|
icon,
|
|
39
43
|
message,
|
|
@@ -46,7 +50,7 @@ export class NotificationApi {
|
|
|
46
50
|
type: "reminder",
|
|
47
51
|
}));
|
|
48
52
|
}
|
|
49
|
-
|
|
53
|
+
async advanceCountdown(message, targetTime, title) {
|
|
50
54
|
return await this.send(new AppNotification({
|
|
51
55
|
title,
|
|
52
56
|
message,
|
|
@@ -54,9 +58,8 @@ export class NotificationApi {
|
|
|
54
58
|
type: "advance-countdown"
|
|
55
59
|
}));
|
|
56
60
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, new AppNotification({
|
|
61
|
+
async countdown(message, targetTime) {
|
|
62
|
+
await this.send(new AppNotification({
|
|
60
63
|
message,
|
|
61
64
|
targetTime,
|
|
62
65
|
backgroundColor: 'rgba(0,0,0,0.5)',
|
|
@@ -64,72 +67,47 @@ export class NotificationApi {
|
|
|
64
67
|
type: "countdown"
|
|
65
68
|
}));
|
|
66
69
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
duration
|
|
75
|
-
}));
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
this.callback("success", message, duration);
|
|
79
|
-
}
|
|
70
|
+
async success(message, duration = 5000) {
|
|
71
|
+
await this.send(new AppNotification({
|
|
72
|
+
message,
|
|
73
|
+
type: "success",
|
|
74
|
+
icon: "check_circle_line",
|
|
75
|
+
duration
|
|
76
|
+
}));
|
|
80
77
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
duration
|
|
89
|
-
}));
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
this.callback("error", message, duration);
|
|
93
|
-
}
|
|
78
|
+
async error(message, duration = 5000) {
|
|
79
|
+
await this.send(new AppNotification({
|
|
80
|
+
message,
|
|
81
|
+
type: "error",
|
|
82
|
+
icon: "close_circle_line",
|
|
83
|
+
duration
|
|
84
|
+
}));
|
|
94
85
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
duration
|
|
103
|
-
}));
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
this.callback("warning", message, duration);
|
|
107
|
-
}
|
|
86
|
+
async warning(message, duration = 5000) {
|
|
87
|
+
await this.send(new AppNotification({
|
|
88
|
+
message,
|
|
89
|
+
type: "warning",
|
|
90
|
+
icon: "warning_line",
|
|
91
|
+
duration
|
|
92
|
+
}));
|
|
108
93
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
duration
|
|
117
|
-
}));
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
this.callback("info", message, duration);
|
|
121
|
-
}
|
|
94
|
+
async info(message, duration = 5000) {
|
|
95
|
+
await this.send(new AppNotification({
|
|
96
|
+
message,
|
|
97
|
+
type: "info",
|
|
98
|
+
icon: "information_line",
|
|
99
|
+
duration
|
|
100
|
+
}));
|
|
122
101
|
}
|
|
123
102
|
/**
|
|
124
103
|
* 隐藏通知
|
|
125
104
|
*/
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (ElectronUtils.hasElectronApi()) {
|
|
129
|
-
(_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.NOTIFICATION, null);
|
|
130
|
-
}
|
|
105
|
+
async hide() {
|
|
106
|
+
await this.invokeMethod('hide');
|
|
131
107
|
}
|
|
132
|
-
|
|
133
|
-
|
|
108
|
+
getChannel() {
|
|
109
|
+
return Channel.NOTIFICATION;
|
|
134
110
|
}
|
|
135
111
|
}
|
|
112
|
+
const NotificationApi = new NotificationApiImpl();
|
|
113
|
+
export { NotificationApi, NotificationApiEvent };
|
|
@@ -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,25 @@
|
|
|
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
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
import { BaseApi } from "./BaseApi";
|
|
6
|
+
var WidgetApiEvent;
|
|
7
|
+
(function (WidgetApiEvent) {
|
|
8
|
+
WidgetApiEvent["DATA_CHANGED"] = "event::cn.widgetjs.core.widget.data-changed";
|
|
9
|
+
WidgetApiEvent["EDIT_DESKTOP_WIDGETS"] = "event::cn.widgetjs.core.widget.desktop.edit";
|
|
10
|
+
})(WidgetApiEvent || (WidgetApiEvent = {}));
|
|
11
|
+
class WidgetApiImpl extends BaseApi {
|
|
12
|
+
getChannel() {
|
|
13
|
+
return Channel.WIDGET;
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.WIDGET, this.REGISTER_WIDGET_PACKAGE, JSON.stringify(widgetPackage)));
|
|
15
|
+
async registerWidgets(widgets) {
|
|
16
|
+
return this.invokeMethod("registerWidgets", JSON.stringify(widgets));
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
async registerWidgetPackage(widgetPackage) {
|
|
19
|
+
return this.invokeMethod("registerWidgetPackage", JSON.stringify(widgetPackage));
|
|
20
|
+
}
|
|
21
|
+
async getWidgets() {
|
|
22
|
+
const data = await this.invokeMethod('getWidgets');
|
|
21
23
|
const widgets = [];
|
|
22
24
|
if (data) {
|
|
23
25
|
for (const item of data) {
|
|
@@ -26,31 +28,28 @@ export class WidgetApi {
|
|
|
26
28
|
}
|
|
27
29
|
return widgets;
|
|
28
30
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.WIDGET, this.GET_WIDGET_PACKAGES));
|
|
31
|
+
async getWidgetPackages() {
|
|
32
|
+
return await this.invokeMethod('getWidgetPackages');
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
35
|
*
|
|
35
36
|
* @param name package name
|
|
36
37
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return Widget.parseObject(await ((_a = ElectronUtils.getAPI()) === null || _a === void 0 ? void 0 : _a.invoke(Channel.WIDGET, this.GET_WIDGET, name)));
|
|
38
|
+
async getWidget(name) {
|
|
39
|
+
return Widget.parseObject(await this.invokeMethod('getWidget', name));
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
*
|
|
43
43
|
* @param name package name
|
|
44
44
|
*/
|
|
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)));
|
|
45
|
+
async getWidgetPackage(name) {
|
|
46
|
+
return WidgetPackage.parseObject(await this.invokeMethod('getWidgetPackage', name));
|
|
48
47
|
}
|
|
49
48
|
/**
|
|
50
49
|
* 获取组件配置地址
|
|
51
50
|
* @param widgetName
|
|
52
51
|
*/
|
|
53
|
-
|
|
52
|
+
async getWidgetConfigUrl(widgetName, widgetParams) {
|
|
54
53
|
const widget = await this.getWidget(widgetName);
|
|
55
54
|
if (!widget)
|
|
56
55
|
return null;
|
|
@@ -62,7 +61,7 @@ export class WidgetApi {
|
|
|
62
61
|
return null;
|
|
63
62
|
return UrlUtils.getWidgetUrl(configRoute.url, widgetPackage, widgetParams);
|
|
64
63
|
}
|
|
65
|
-
|
|
64
|
+
async getWidgetUrl(widgetName, widgetParams) {
|
|
66
65
|
const widget = await this.getWidget(widgetName);
|
|
67
66
|
if (!widget)
|
|
68
67
|
return null;
|
|
@@ -72,54 +71,18 @@ export class WidgetApi {
|
|
|
72
71
|
return null;
|
|
73
72
|
return UrlUtils.getWidgetUrl(indexRoute.url, widgetPackage, widgetParams);
|
|
74
73
|
}
|
|
75
|
-
|
|
74
|
+
async getWidgetPackageIndexUrl(packageName, hash) {
|
|
76
75
|
const widgetPackage = await this.getWidgetPackage(packageName);
|
|
77
76
|
if (!widgetPackage)
|
|
78
77
|
return null;
|
|
79
78
|
return widgetPackage.getIndexUrl(hash);
|
|
80
79
|
}
|
|
81
|
-
|
|
80
|
+
async getWidgetPackageUrl(packageName) {
|
|
82
81
|
const widgetPackage = await this.getWidgetPackage(packageName);
|
|
83
82
|
if (!widgetPackage)
|
|
84
83
|
return null;
|
|
85
84
|
return widgetPackage.url;
|
|
86
85
|
}
|
|
87
|
-
/**
|
|
88
|
-
* 通过组件名保存组件信息,通常用于存储可以在同类组件中共用的数据
|
|
89
|
-
* @param data
|
|
90
|
-
* @param options
|
|
91
|
-
*/
|
|
92
|
-
static async saveDataByName(data, options = { sendBroadcast: true }) {
|
|
93
|
-
const store = this.getStore(data.name);
|
|
94
|
-
const json = JSON.stringify(data);
|
|
95
|
-
const result = await store.setItem(data.name, json);
|
|
96
|
-
if (options.sendBroadcast) {
|
|
97
|
-
const broadcastEvent = new BroadcastEvent(BroadcastEvent.TYPE_WIDGET_UPDATED, "", {
|
|
98
|
-
name: data.name,
|
|
99
|
-
id: options.id,
|
|
100
|
-
json
|
|
101
|
-
});
|
|
102
|
-
await BroadcastApi.sendBroadcastEvent(broadcastEvent);
|
|
103
|
-
}
|
|
104
|
-
return result;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* 获取组件 LocalForage 存储实例
|
|
108
|
-
* @param name
|
|
109
|
-
*/
|
|
110
|
-
static getStore(name) {
|
|
111
|
-
if (this.stores.has(name)) {
|
|
112
|
-
return this.stores.get(name);
|
|
113
|
-
}
|
|
114
|
-
const store = localforage.createInstance({ name: name });
|
|
115
|
-
this.stores.set(name, store);
|
|
116
|
-
return store;
|
|
117
|
-
}
|
|
118
86
|
}
|
|
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();
|
|
87
|
+
const WidgetApi = new WidgetApiImpl();
|
|
88
|
+
export { WidgetApi, WidgetApiEvent };
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import localforage from "localforage";
|
|
2
2
|
import { BroadcastEvent } from "../model/event/BroadcastEvent";
|
|
3
3
|
import { BroadcastApi } from "../api/BroadcastApi";
|
|
4
|
-
|
|
4
|
+
import { WidgetApiEvent } from "../api/WidgetApi";
|
|
5
|
+
export class WidgetDataApi {
|
|
5
6
|
/**
|
|
6
7
|
* 保存组件数据
|
|
7
8
|
* @param data
|
|
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
|
/**
|
|
@@ -28,13 +32,18 @@ export class WidgetDataRepository {
|
|
|
28
32
|
/**
|
|
29
33
|
* 通过组件名保存组件信息,通常用于存储可以在同类组件中共用的数据
|
|
30
34
|
* @param data
|
|
35
|
+
* @param options
|
|
31
36
|
*/
|
|
32
|
-
static async saveByName(data) {
|
|
37
|
+
static async saveByName(data, options = { sendBroadcast: true }) {
|
|
33
38
|
const store = this.getStore(data.name);
|
|
34
39
|
const json = JSON.stringify(data);
|
|
35
40
|
const result = await store.setItem(data.name, json);
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
if (options === null || options === void 0 ? void 0 : options.sendBroadcast) {
|
|
42
|
+
const broadcastEvent = new BroadcastEvent({
|
|
43
|
+
event: WidgetApiEvent.DATA_CHANGED, payload: { name: data.name, json }
|
|
44
|
+
});
|
|
45
|
+
await BroadcastApi.send(broadcastEvent);
|
|
46
|
+
}
|
|
38
47
|
return result;
|
|
39
48
|
}
|
|
40
49
|
static async findByName(name, type) {
|
|
@@ -61,4 +70,4 @@ export class WidgetDataRepository {
|
|
|
61
70
|
return `${name}@${id}`;
|
|
62
71
|
}
|
|
63
72
|
}
|
|
64
|
-
|
|
73
|
+
WidgetDataApi.stores = new Map();
|
package/dist/esm/index.js
CHANGED
|
@@ -11,9 +11,9 @@ export * from "./model/event/NativeKeyboardEvent";
|
|
|
11
11
|
export * from "./model/event/AppMouseEvent";
|
|
12
12
|
export * from "./model/WidgetPackage";
|
|
13
13
|
export * from "./api/ElectronApi";
|
|
14
|
-
export * from "./
|
|
14
|
+
export * from "./api/WidgetDataApi";
|
|
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 {};
|
|
@@ -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,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 根据语言环境获取文本
|
|
3
|
+
* @param langMap 对象
|
|
4
|
+
* @param {LanguageCode} langCode 语言环境 例如:zh-CN,en-US
|
|
5
|
+
* @param fallbackToBrowser
|
|
6
|
+
*/
|
|
7
|
+
export function getTextByLanguageCode(langMap, langCode, fallbackToBrowser = true) {
|
|
8
|
+
let result;
|
|
9
|
+
if (langCode) {
|
|
10
|
+
if (langCode in langMap) {
|
|
11
|
+
return langMap[langCode];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
// fallback to browser default language
|
|
15
|
+
if (result == undefined && fallbackToBrowser) {
|
|
16
|
+
if (typeof navigator != 'undefined' && navigator.languages) {
|
|
17
|
+
const langCode = navigator.language;
|
|
18
|
+
result = getTextByLanguageCode(langMap, langCode, false);
|
|
19
|
+
if (result != undefined) {
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// fallback to first language
|
|
25
|
+
if (result == undefined) {
|
|
26
|
+
let langCode = Object.keys(langMap);
|
|
27
|
+
if (langCode.length > 0) {
|
|
28
|
+
return langMap[langCode[0]];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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>;
|
|
11
19
|
/**
|
|
12
20
|
* 获取应用版本号,格式为 x.y.z
|
|
13
21
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
22
|
+
getVersion(): Promise<string>;
|
|
23
|
+
getPreloadPath(): Promise<string>;
|
|
24
|
+
openSettingWindow(): Promise<any>;
|
|
17
25
|
}
|
|
26
|
+
declare const AppApi: AppApiImpl;
|
|
27
|
+
export { AppApi, AppApiEvent, AppApiMethods };
|