@widget-js/core 0.1.6 → 0.1.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/LICENSE +21 -21
- package/dist/cjs/api/ApiConstants.js +8 -8
- package/dist/cjs/api/AppApi.js +31 -31
- package/dist/cjs/api/BroadcastApi.js +20 -20
- package/dist/cjs/api/BrowserWindowApi.js +58 -24
- package/dist/cjs/api/Channel.js +12 -11
- package/dist/cjs/api/DialogApi.js +16 -0
- package/dist/cjs/api/ElectronApi.js +13 -13
- package/dist/cjs/api/NotificationApi.js +83 -83
- package/dist/cjs/api/WidgetApi.js +58 -49
- package/dist/cjs/index.js +36 -34
- package/dist/cjs/model/HostedMode.js +14 -0
- package/dist/cjs/model/Notification.js +15 -15
- package/dist/cjs/model/SocialInfo.js +10 -10
- package/dist/cjs/model/Widget.js +79 -79
- package/dist/cjs/model/WidgetData.js +16 -16
- package/dist/cjs/model/WidgetPackage.js +21 -6
- package/dist/cjs/model/WidgetParams.js +139 -144
- package/dist/cjs/model/event/BroadcastEvent.js +14 -14
- package/dist/cjs/model/event/WebSocketEvent.js +14 -14
- package/dist/cjs/model/interface/IHostedWidget.js +2 -0
- package/dist/cjs/repository/WidgetDataRepository.js +71 -71
- package/dist/cjs/router/encoding.js +144 -144
- package/dist/cjs/router/query.js +84 -84
- package/dist/cjs/utils/ElectronUtils.js +24 -24
- package/dist/esm/api/ApiConstants.js +4 -4
- package/dist/esm/api/AppApi.js +27 -27
- package/dist/esm/api/BroadcastApi.js +16 -16
- package/dist/esm/api/BrowserWindowApi.js +54 -20
- package/dist/esm/api/Channel.js +9 -8
- package/dist/esm/api/DialogApi.js +12 -0
- package/dist/esm/api/ElectronApi.js +9 -9
- package/dist/esm/api/NotificationApi.js +79 -79
- package/dist/esm/api/WidgetApi.js +54 -45
- package/dist/esm/index.js +20 -18
- package/dist/esm/model/HostedMode.js +11 -0
- package/dist/esm/model/Notification.js +11 -11
- package/dist/esm/model/SocialInfo.js +6 -6
- package/dist/esm/model/Widget.js +75 -75
- package/dist/esm/model/WidgetData.js +12 -12
- package/dist/esm/model/WidgetPackage.js +17 -2
- package/dist/esm/model/WidgetParams.js +135 -140
- package/dist/esm/model/event/BroadcastEvent.js +10 -10
- package/dist/esm/model/event/WebSocketEvent.js +10 -10
- package/dist/esm/model/interface/IHostedWidget.js +1 -0
- package/dist/esm/repository/WidgetDataRepository.js +64 -64
- package/dist/esm/router/encoding.js +135 -135
- package/dist/esm/router/query.js +79 -79
- package/dist/esm/utils/ElectronUtils.js +20 -20
- package/dist/types/api/ApiConstants.d.ts +4 -4
- package/dist/types/api/AppApi.d.ts +10 -10
- package/dist/types/api/BroadcastApi.d.ts +6 -6
- package/dist/types/api/BrowserWindowApi.d.ts +37 -10
- package/dist/types/api/Channel.d.ts +8 -7
- package/dist/types/api/DialogApi.d.ts +8 -0
- package/dist/types/api/ElectronApi.d.ts +4 -4
- package/dist/types/api/NotificationApi.d.ts +14 -14
- package/dist/types/api/WidgetApi.d.ts +30 -24
- package/dist/types/index.d.ts +20 -18
- package/dist/types/model/HostedMode.d.ts +10 -0
- package/dist/types/model/Notification.d.ts +16 -16
- package/dist/types/model/SocialInfo.d.ts +6 -6
- package/dist/types/model/Widget.d.ts +96 -85
- package/dist/types/model/WidgetData.d.ts +35 -35
- package/dist/types/model/WidgetPackage.d.ts +43 -41
- package/dist/types/model/WidgetParams.d.ts +60 -63
- package/dist/types/model/event/BroadcastEvent.d.ts +12 -12
- package/dist/types/model/event/WebSocketEvent.d.ts +8 -8
- package/dist/types/model/interface/IHostedWidget.d.ts +13 -0
- package/dist/types/repository/WidgetDataRepository.d.ts +26 -26
- package/dist/types/router/encoding.d.ts +62 -62
- package/dist/types/router/query.d.ts +53 -53
- package/dist/types/utils/ElectronUtils.d.ts +8 -8
- package/dist/umd/index.js +1 -1
- package/package.json +15 -16
package/dist/cjs/router/query.js
CHANGED
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stringifyQuery = exports.parseQuery = void 0;
|
|
4
|
-
const encoding_1 = require("./encoding");
|
|
5
|
-
const isArray = Array.isArray;
|
|
6
|
-
/**
|
|
7
|
-
* Transforms a queryString into a {@link LocationQuery} object. Accept both, a
|
|
8
|
-
* version with the leading `?` and without Should work as URLSearchParams
|
|
9
|
-
* @internal
|
|
10
|
-
*
|
|
11
|
-
* @param search - search string to parse
|
|
12
|
-
* @returns a query object
|
|
13
|
-
*/
|
|
14
|
-
function parseQuery(search) {
|
|
15
|
-
const query = {};
|
|
16
|
-
// avoid creating an object with an empty key and empty value
|
|
17
|
-
// because of split('&')
|
|
18
|
-
if (search === '' || search === '?')
|
|
19
|
-
return query;
|
|
20
|
-
const hasLeadingIM = search[0] === '?';
|
|
21
|
-
const searchParams = (hasLeadingIM ? search.slice(1) : search).split('&');
|
|
22
|
-
for (let i = 0; i < searchParams.length; ++i) {
|
|
23
|
-
// pre decode the + into space
|
|
24
|
-
const searchParam = searchParams[i].replace(encoding_1.PLUS_RE, ' ');
|
|
25
|
-
// allow the = character
|
|
26
|
-
const eqPos = searchParam.indexOf('=');
|
|
27
|
-
const key = (0, encoding_1.decode)(eqPos < 0 ? searchParam : searchParam.slice(0, eqPos));
|
|
28
|
-
const value = eqPos < 0 ? null : (0, encoding_1.decode)(searchParam.slice(eqPos + 1));
|
|
29
|
-
if (key in query) {
|
|
30
|
-
// an extra variable for ts types
|
|
31
|
-
let currentValue = query[key];
|
|
32
|
-
if (!isArray(currentValue)) {
|
|
33
|
-
currentValue = query[key] = [currentValue];
|
|
34
|
-
}
|
|
35
|
-
// we force the modification
|
|
36
|
-
;
|
|
37
|
-
currentValue.push(value);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
query[key] = value;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return query;
|
|
44
|
-
}
|
|
45
|
-
exports.parseQuery = parseQuery;
|
|
46
|
-
/**
|
|
47
|
-
* Stringifies a {@link LocationQueryRaw} object. Like `URLSearchParams`, it
|
|
48
|
-
* doesn't prepend a `?`
|
|
49
|
-
*
|
|
50
|
-
* @internal
|
|
51
|
-
*
|
|
52
|
-
* @param query - query object to stringify
|
|
53
|
-
* @returns string version of the query without the leading `?`
|
|
54
|
-
*/
|
|
55
|
-
function stringifyQuery(query) {
|
|
56
|
-
let search = '';
|
|
57
|
-
for (let key in query) {
|
|
58
|
-
const value = query[key];
|
|
59
|
-
key = (0, encoding_1.encodeQueryKey)(key);
|
|
60
|
-
if (value == null) {
|
|
61
|
-
// only null adds the value
|
|
62
|
-
if (value !== undefined) {
|
|
63
|
-
search += (search.length ? '&' : '') + key;
|
|
64
|
-
}
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
// keep null values
|
|
68
|
-
const values = isArray(value)
|
|
69
|
-
? value.map(v => v && (0, encoding_1.encodeQueryValue)(v))
|
|
70
|
-
: [value && (0, encoding_1.encodeQueryValue)(value)];
|
|
71
|
-
values.forEach(value => {
|
|
72
|
-
// skip undefined values in arrays as if they were not present
|
|
73
|
-
// smaller code than using filter
|
|
74
|
-
if (value !== undefined) {
|
|
75
|
-
// only append & with non-empty search
|
|
76
|
-
search += (search.length ? '&' : '') + key;
|
|
77
|
-
if (value != null)
|
|
78
|
-
search += '=' + value;
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
return search;
|
|
83
|
-
}
|
|
84
|
-
exports.stringifyQuery = stringifyQuery;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringifyQuery = exports.parseQuery = void 0;
|
|
4
|
+
const encoding_1 = require("./encoding");
|
|
5
|
+
const isArray = Array.isArray;
|
|
6
|
+
/**
|
|
7
|
+
* Transforms a queryString into a {@link LocationQuery} object. Accept both, a
|
|
8
|
+
* version with the leading `?` and without Should work as URLSearchParams
|
|
9
|
+
* @internal
|
|
10
|
+
*
|
|
11
|
+
* @param search - search string to parse
|
|
12
|
+
* @returns a query object
|
|
13
|
+
*/
|
|
14
|
+
function parseQuery(search) {
|
|
15
|
+
const query = {};
|
|
16
|
+
// avoid creating an object with an empty key and empty value
|
|
17
|
+
// because of split('&')
|
|
18
|
+
if (search === '' || search === '?')
|
|
19
|
+
return query;
|
|
20
|
+
const hasLeadingIM = search[0] === '?';
|
|
21
|
+
const searchParams = (hasLeadingIM ? search.slice(1) : search).split('&');
|
|
22
|
+
for (let i = 0; i < searchParams.length; ++i) {
|
|
23
|
+
// pre decode the + into space
|
|
24
|
+
const searchParam = searchParams[i].replace(encoding_1.PLUS_RE, ' ');
|
|
25
|
+
// allow the = character
|
|
26
|
+
const eqPos = searchParam.indexOf('=');
|
|
27
|
+
const key = (0, encoding_1.decode)(eqPos < 0 ? searchParam : searchParam.slice(0, eqPos));
|
|
28
|
+
const value = eqPos < 0 ? null : (0, encoding_1.decode)(searchParam.slice(eqPos + 1));
|
|
29
|
+
if (key in query) {
|
|
30
|
+
// an extra variable for ts types
|
|
31
|
+
let currentValue = query[key];
|
|
32
|
+
if (!isArray(currentValue)) {
|
|
33
|
+
currentValue = query[key] = [currentValue];
|
|
34
|
+
}
|
|
35
|
+
// we force the modification
|
|
36
|
+
;
|
|
37
|
+
currentValue.push(value);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
query[key] = value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return query;
|
|
44
|
+
}
|
|
45
|
+
exports.parseQuery = parseQuery;
|
|
46
|
+
/**
|
|
47
|
+
* Stringifies a {@link LocationQueryRaw} object. Like `URLSearchParams`, it
|
|
48
|
+
* doesn't prepend a `?`
|
|
49
|
+
*
|
|
50
|
+
* @internal
|
|
51
|
+
*
|
|
52
|
+
* @param query - query object to stringify
|
|
53
|
+
* @returns string version of the query without the leading `?`
|
|
54
|
+
*/
|
|
55
|
+
function stringifyQuery(query) {
|
|
56
|
+
let search = '';
|
|
57
|
+
for (let key in query) {
|
|
58
|
+
const value = query[key];
|
|
59
|
+
key = (0, encoding_1.encodeQueryKey)(key);
|
|
60
|
+
if (value == null) {
|
|
61
|
+
// only null adds the value
|
|
62
|
+
if (value !== undefined) {
|
|
63
|
+
search += (search.length ? '&' : '') + key;
|
|
64
|
+
}
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
// keep null values
|
|
68
|
+
const values = isArray(value)
|
|
69
|
+
? value.map(v => v && (0, encoding_1.encodeQueryValue)(v))
|
|
70
|
+
: [value && (0, encoding_1.encodeQueryValue)(value)];
|
|
71
|
+
values.forEach(value => {
|
|
72
|
+
// skip undefined values in arrays as if they were not present
|
|
73
|
+
// smaller code than using filter
|
|
74
|
+
if (value !== undefined) {
|
|
75
|
+
// only append & with non-empty search
|
|
76
|
+
search += (search.length ? '&' : '') + key;
|
|
77
|
+
if (value != null)
|
|
78
|
+
search += '=' + value;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return search;
|
|
83
|
+
}
|
|
84
|
+
exports.stringifyQuery = stringifyQuery;
|
|
@@ -1,24 +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 this.getAPI() != null;
|
|
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;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ElectronUtils = void 0;
|
|
4
|
+
class ElectronUtils {
|
|
5
|
+
static hasElectronApi() {
|
|
6
|
+
return this.getAPI() != null;
|
|
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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export class ApiConstants {
|
|
2
|
-
}
|
|
3
|
-
ApiConstants.CONFIG_LAUNCH_AT_STARTUP = "CONFIG_LAUNCH_AT_STARTUP";
|
|
4
|
-
ApiConstants.CONFIG_WIDGET_TITLE_COLOR = "CONFIG_WIDGET_TITLE_COLOR";
|
|
1
|
+
export class ApiConstants {
|
|
2
|
+
}
|
|
3
|
+
ApiConstants.CONFIG_LAUNCH_AT_STARTUP = "CONFIG_LAUNCH_AT_STARTUP";
|
|
4
|
+
ApiConstants.CONFIG_WIDGET_TITLE_COLOR = "CONFIG_WIDGET_TITLE_COLOR";
|
package/dist/esm/api/AppApi.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { ElectronUtils } from "../utils/ElectronUtils";
|
|
2
|
-
import { Channel } from "./Channel";
|
|
3
|
-
export class AppApi {
|
|
4
|
-
static async setConfig(key, value) {
|
|
5
|
-
await ElectronUtils.getAPI().invoke(Channel.APP, this.SET_CONFIG, key, value);
|
|
6
|
-
}
|
|
7
|
-
static async getConfig(key, defaultValue) {
|
|
8
|
-
const value = await ElectronUtils.getAPI().invoke(Channel.APP, this.GET_CONFIG, key);
|
|
9
|
-
if (value === null || value === undefined) {
|
|
10
|
-
return defaultValue;
|
|
11
|
-
}
|
|
12
|
-
if (typeof defaultValue == "boolean") {
|
|
13
|
-
return value === "true";
|
|
14
|
-
}
|
|
15
|
-
return value;
|
|
16
|
-
}
|
|
17
|
-
static openAddWidgetWindow() {
|
|
18
|
-
ElectronUtils.getAPI().invoke(Channel.APP, this.OPEN_ADD_WIDGET_WINDOW);
|
|
19
|
-
}
|
|
20
|
-
static openSettingWindow() {
|
|
21
|
-
ElectronUtils.getAPI().invoke(Channel.APP, this.OPEN_SETTING_WINDOW);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
AppApi.SET_CONFIG = "SET_CONFIG";
|
|
25
|
-
AppApi.GET_CONFIG = "GET_CONFIG";
|
|
26
|
-
AppApi.OPEN_ADD_WIDGET_WINDOW = "open-add-widget-window";
|
|
27
|
-
AppApi.OPEN_SETTING_WINDOW = "open-setting-window";
|
|
1
|
+
import { ElectronUtils } from "../utils/ElectronUtils";
|
|
2
|
+
import { Channel } from "./Channel";
|
|
3
|
+
export class AppApi {
|
|
4
|
+
static async setConfig(key, value) {
|
|
5
|
+
await ElectronUtils.getAPI().invoke(Channel.APP, this.SET_CONFIG, key, value);
|
|
6
|
+
}
|
|
7
|
+
static async getConfig(key, defaultValue) {
|
|
8
|
+
const value = await ElectronUtils.getAPI().invoke(Channel.APP, this.GET_CONFIG, key);
|
|
9
|
+
if (value === null || value === undefined) {
|
|
10
|
+
return defaultValue;
|
|
11
|
+
}
|
|
12
|
+
if (typeof defaultValue == "boolean") {
|
|
13
|
+
return value === "true";
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
static openAddWidgetWindow() {
|
|
18
|
+
ElectronUtils.getAPI().invoke(Channel.APP, this.OPEN_ADD_WIDGET_WINDOW);
|
|
19
|
+
}
|
|
20
|
+
static openSettingWindow() {
|
|
21
|
+
ElectronUtils.getAPI().invoke(Channel.APP, this.OPEN_SETTING_WINDOW);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
AppApi.SET_CONFIG = "SET_CONFIG";
|
|
25
|
+
AppApi.GET_CONFIG = "GET_CONFIG";
|
|
26
|
+
AppApi.OPEN_ADD_WIDGET_WINDOW = "open-add-widget-window";
|
|
27
|
+
AppApi.OPEN_SETTING_WINDOW = "open-setting-window";
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { ElectronUtils } from "../utils/ElectronUtils";
|
|
2
|
-
import { Channel } from "./Channel";
|
|
3
|
-
import { ElectronApi } from "./ElectronApi";
|
|
4
|
-
export class BroadcastApi {
|
|
5
|
-
static async sendBroadcastEvent(event) {
|
|
6
|
-
await ElectronUtils.getAPI().invoke(Channel.BROADCAST, JSON.stringify(event));
|
|
7
|
-
}
|
|
8
|
-
static async registerBroadcast(callback) {
|
|
9
|
-
await ElectronApi.addIpcListener(Channel.BROADCAST, (json) => {
|
|
10
|
-
callback(JSON.parse(json));
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
static async unregisterBroadcast() {
|
|
14
|
-
await ElectronApi.removeIpcListener(Channel.BROADCAST);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
1
|
+
import { ElectronUtils } from "../utils/ElectronUtils";
|
|
2
|
+
import { Channel } from "./Channel";
|
|
3
|
+
import { ElectronApi } from "./ElectronApi";
|
|
4
|
+
export class BroadcastApi {
|
|
5
|
+
static async sendBroadcastEvent(event) {
|
|
6
|
+
await ElectronUtils.getAPI().invoke(Channel.BROADCAST, JSON.stringify(event));
|
|
7
|
+
}
|
|
8
|
+
static async registerBroadcast(callback) {
|
|
9
|
+
await ElectronApi.addIpcListener(Channel.BROADCAST, (json) => {
|
|
10
|
+
callback(JSON.parse(json));
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
static async unregisterBroadcast() {
|
|
14
|
+
await ElectronApi.removeIpcListener(Channel.BROADCAST);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,20 +1,54 @@
|
|
|
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
|
-
static async
|
|
14
|
-
await ElectronUtils.getAPI().invoke(Channel.BROWSER_WINDOW, this.
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
+
static async isAlwaysOnTop() {
|
|
14
|
+
return await ElectronUtils.getAPI().invoke(Channel.BROWSER_WINDOW, this.IS_ALWAYS_ON_TOP);
|
|
15
|
+
}
|
|
16
|
+
static async openUrl(url) {
|
|
17
|
+
await ElectronUtils.getAPI().invoke(Channel.BROWSER_WINDOW, this.OPEN_URL, url);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 设置窗口位置
|
|
21
|
+
* @param x
|
|
22
|
+
* @param y
|
|
23
|
+
* @param animation 动画只在mac系统有效
|
|
24
|
+
*/
|
|
25
|
+
static async setPosition(x, y, animation) {
|
|
26
|
+
await ElectronUtils.getAPI().invoke(Channel.BROWSER_WINDOW, this.SET_POSITION, x, y, animation);
|
|
27
|
+
}
|
|
28
|
+
static async getPosition() {
|
|
29
|
+
return await ElectronUtils.getAPI().invoke(Channel.BROWSER_WINDOW, this.GET_POSITION);
|
|
30
|
+
}
|
|
31
|
+
static async blur() {
|
|
32
|
+
return await ElectronUtils.getAPI().invoke(Channel.BROWSER_WINDOW, this.BLUR);
|
|
33
|
+
}
|
|
34
|
+
static async focus() {
|
|
35
|
+
return await ElectronUtils.getAPI().invoke(Channel.BROWSER_WINDOW, this.FOCUS);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 设置窗口是否可以拉伸
|
|
39
|
+
* @param resizable
|
|
40
|
+
*/
|
|
41
|
+
static async setResizable(resizable) {
|
|
42
|
+
return await ElectronUtils.getAPI().invoke(Channel.BROWSER_WINDOW, this.SET_RESIZABLE, resizable);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
BrowserWindowApi.IGNORE_MOUSE_EVENT = "ignore-mouse-event";
|
|
46
|
+
BrowserWindowApi.WINDOW_VISIBILITY = "window-visibility";
|
|
47
|
+
BrowserWindowApi.ALWAYS_ON_TOP = "always-on-top";
|
|
48
|
+
BrowserWindowApi.IS_ALWAYS_ON_TOP = "is-always-on-top";
|
|
49
|
+
BrowserWindowApi.OPEN_URL = "open-url";
|
|
50
|
+
BrowserWindowApi.SET_POSITION = "set-position";
|
|
51
|
+
BrowserWindowApi.GET_POSITION = "get-position";
|
|
52
|
+
BrowserWindowApi.BLUR = "blur";
|
|
53
|
+
BrowserWindowApi.FOCUS = "focus";
|
|
54
|
+
BrowserWindowApi.SET_RESIZABLE = "set-resizable";
|
package/dist/esm/api/Channel.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export var Channel;
|
|
2
|
-
(function (Channel) {
|
|
3
|
-
Channel["NOTIFICATION"] = "channel::cn.widgetjs.core.notification";
|
|
4
|
-
Channel["BROWSER_WINDOW"] = "channel::cn.widgetjs.core.browser_window";
|
|
5
|
-
Channel["BROADCAST"] = "channel::cn.widgetjs.core.broadcast";
|
|
6
|
-
Channel["WIDGET"] = "channel::cn.widgetjs.core.widget";
|
|
7
|
-
Channel["APP"] = "channel::cn.widgetjs.core.app";
|
|
8
|
-
|
|
1
|
+
export var Channel;
|
|
2
|
+
(function (Channel) {
|
|
3
|
+
Channel["NOTIFICATION"] = "channel::cn.widgetjs.core.notification";
|
|
4
|
+
Channel["BROWSER_WINDOW"] = "channel::cn.widgetjs.core.browser_window";
|
|
5
|
+
Channel["BROADCAST"] = "channel::cn.widgetjs.core.broadcast";
|
|
6
|
+
Channel["WIDGET"] = "channel::cn.widgetjs.core.widget";
|
|
7
|
+
Channel["APP"] = "channel::cn.widgetjs.core.app";
|
|
8
|
+
Channel["DIALOG"] = "channel::cn.widgetjs.core.dialog";
|
|
9
|
+
})(Channel || (Channel = {}));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ElectronUtils } from "../utils/ElectronUtils";
|
|
2
|
+
import { Channel } from "./Channel";
|
|
3
|
+
export class DialogApi {
|
|
4
|
+
/**
|
|
5
|
+
* 选取单个文件
|
|
6
|
+
* @param extensions 允许的文件后缀格式,如:["txt","docx","gif"]
|
|
7
|
+
*/
|
|
8
|
+
static async pickFile(extensions) {
|
|
9
|
+
return await ElectronUtils.getAPI().invoke(Channel.DIALOG, this.PICK_FILE, extensions);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
DialogApi.PICK_FILE = "pick-file";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ElectronUtils } from "../utils/ElectronUtils";
|
|
2
|
-
export class ElectronApi {
|
|
3
|
-
static async addIpcListener(key, f) {
|
|
4
|
-
await ElectronUtils.getAPI().addIpcListener(key, f);
|
|
5
|
-
}
|
|
6
|
-
static async removeIpcListener(key) {
|
|
7
|
-
await ElectronUtils.getAPI().removeIpcListener(key);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
1
|
+
import { ElectronUtils } from "../utils/ElectronUtils";
|
|
2
|
+
export class ElectronApi {
|
|
3
|
+
static async addIpcListener(key, f) {
|
|
4
|
+
await ElectronUtils.getAPI().addIpcListener(key, f);
|
|
5
|
+
}
|
|
6
|
+
static async removeIpcListener(key) {
|
|
7
|
+
await ElectronUtils.getAPI().removeIpcListener(key);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
import { Notification } from "../model/Notification";
|
|
2
|
-
import { Channel } from "./Channel";
|
|
3
|
-
import { ElectronUtils } from "../utils/ElectronUtils";
|
|
4
|
-
export class NotificationApi {
|
|
5
|
-
static async call(duration = 5000) {
|
|
6
|
-
ElectronUtils.getAPI().invoke(Channel.NOTIFICATION, new Notification({
|
|
7
|
-
title: "章鱼哥",
|
|
8
|
-
type: "call",
|
|
9
|
-
message: "下班提醒",
|
|
10
|
-
duration: duration
|
|
11
|
-
}));
|
|
12
|
-
}
|
|
13
|
-
static async advanceCountdown(message, targetTime, title) {
|
|
14
|
-
ElectronUtils.getAPI().invoke(Channel.NOTIFICATION, new Notification({
|
|
15
|
-
title,
|
|
16
|
-
message,
|
|
17
|
-
targetTime,
|
|
18
|
-
type: "advance-countdown"
|
|
19
|
-
}));
|
|
20
|
-
}
|
|
21
|
-
static async countdown(message, targetTime) {
|
|
22
|
-
ElectronUtils.getAPI().invoke(Channel.NOTIFICATION, new Notification({
|
|
23
|
-
message,
|
|
24
|
-
targetTime,
|
|
25
|
-
type: "countdown"
|
|
26
|
-
}));
|
|
27
|
-
}
|
|
28
|
-
static async success(message, duration = 5000) {
|
|
29
|
-
if (ElectronUtils.hasElectronApi()) {
|
|
30
|
-
ElectronUtils.getAPI().invoke(Channel.NOTIFICATION, new Notification({
|
|
31
|
-
message,
|
|
32
|
-
type: "success",
|
|
33
|
-
duration
|
|
34
|
-
}));
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
this.callback("success", message, duration);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
static async error(message, duration = 5000) {
|
|
41
|
-
if (ElectronUtils.hasElectronApi()) {
|
|
42
|
-
ElectronUtils.getAPI().invoke(Channel.NOTIFICATION, new Notification({
|
|
43
|
-
message,
|
|
44
|
-
type: "error",
|
|
45
|
-
duration
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
this.callback("error", message, duration);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
static async warning(message, duration = 5000) {
|
|
53
|
-
if (ElectronUtils.hasElectronApi()) {
|
|
54
|
-
ElectronUtils.getAPI().invoke(Channel.NOTIFICATION, new Notification({
|
|
55
|
-
message,
|
|
56
|
-
type: "warning",
|
|
57
|
-
duration
|
|
58
|
-
}));
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
this.callback("warning", message, duration);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
static async message(message, duration = 5000) {
|
|
65
|
-
if (ElectronUtils.hasElectronApi()) {
|
|
66
|
-
ElectronUtils.getAPI().invoke(Channel.NOTIFICATION, new Notification({
|
|
67
|
-
message,
|
|
68
|
-
type: "message",
|
|
69
|
-
duration
|
|
70
|
-
}));
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
this.callback("message", message, duration);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
static setDebugNotification(callback) {
|
|
77
|
-
this.callback = callback;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
1
|
+
import { Notification } from "../model/Notification";
|
|
2
|
+
import { Channel } from "./Channel";
|
|
3
|
+
import { ElectronUtils } from "../utils/ElectronUtils";
|
|
4
|
+
export class NotificationApi {
|
|
5
|
+
static async call(duration = 5000) {
|
|
6
|
+
ElectronUtils.getAPI().invoke(Channel.NOTIFICATION, new Notification({
|
|
7
|
+
title: "章鱼哥",
|
|
8
|
+
type: "call",
|
|
9
|
+
message: "下班提醒",
|
|
10
|
+
duration: duration
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
13
|
+
static async advanceCountdown(message, targetTime, title) {
|
|
14
|
+
ElectronUtils.getAPI().invoke(Channel.NOTIFICATION, new Notification({
|
|
15
|
+
title,
|
|
16
|
+
message,
|
|
17
|
+
targetTime,
|
|
18
|
+
type: "advance-countdown"
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
static async countdown(message, targetTime) {
|
|
22
|
+
ElectronUtils.getAPI().invoke(Channel.NOTIFICATION, new Notification({
|
|
23
|
+
message,
|
|
24
|
+
targetTime,
|
|
25
|
+
type: "countdown"
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
static async success(message, duration = 5000) {
|
|
29
|
+
if (ElectronUtils.hasElectronApi()) {
|
|
30
|
+
ElectronUtils.getAPI().invoke(Channel.NOTIFICATION, new Notification({
|
|
31
|
+
message,
|
|
32
|
+
type: "success",
|
|
33
|
+
duration
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
this.callback("success", message, duration);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
static async error(message, duration = 5000) {
|
|
41
|
+
if (ElectronUtils.hasElectronApi()) {
|
|
42
|
+
ElectronUtils.getAPI().invoke(Channel.NOTIFICATION, new Notification({
|
|
43
|
+
message,
|
|
44
|
+
type: "error",
|
|
45
|
+
duration
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.callback("error", message, duration);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
static async warning(message, duration = 5000) {
|
|
53
|
+
if (ElectronUtils.hasElectronApi()) {
|
|
54
|
+
ElectronUtils.getAPI().invoke(Channel.NOTIFICATION, new Notification({
|
|
55
|
+
message,
|
|
56
|
+
type: "warning",
|
|
57
|
+
duration
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this.callback("warning", message, duration);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
static async message(message, duration = 5000) {
|
|
65
|
+
if (ElectronUtils.hasElectronApi()) {
|
|
66
|
+
ElectronUtils.getAPI().invoke(Channel.NOTIFICATION, new Notification({
|
|
67
|
+
message,
|
|
68
|
+
type: "message",
|
|
69
|
+
duration
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this.callback("message", message, duration);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
static setDebugNotification(callback) {
|
|
77
|
+
this.callback = callback;
|
|
78
|
+
}
|
|
79
|
+
}
|