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