mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-13 16:06:13 +01:00
🎨 Improve sendNotification (#17167)
This commit is contained in:
parent
257aa0ef44
commit
07e74561ff
2 changed files with 28 additions and 6 deletions
|
|
@ -54,8 +54,8 @@ app.setPath("userData", app.getPath("userData") + "-Electron"); // `~/.config`
|
|||
fs.rmSync(app.getPath("appData") + "/" + app.name, {recursive: true}); // 删除自动创建的应用目录 https://github.com/siyuan-note/siyuan/issues/13150
|
||||
|
||||
if (process.platform === "win32") {
|
||||
// Windows 需要设置 AppUserModelId 才能正确显示应用名称 https://github.com/siyuan-note/siyuan/issues/17022
|
||||
app.setAppUserModelId(app.name);
|
||||
// Windows 需要设置 AppUserModelId 才能正确显示应用名称和应用图标 https://github.com/siyuan-note/siyuan/issues/17022
|
||||
app.setAppUserModelId("org.b3log.siyuan");
|
||||
}
|
||||
|
||||
if (!app.requestSingleInstanceLock()) {
|
||||
|
|
@ -958,8 +958,7 @@ app.whenReady().then(() => {
|
|||
new Notification({
|
||||
title: data.title,
|
||||
body: data.body,
|
||||
icon: path.join(appDir, "stage", "icon.png"),
|
||||
timeoutType: "never",
|
||||
timeoutType: data.timeoutType,
|
||||
}).show();
|
||||
break;
|
||||
case "setSpellCheckerLanguages":
|
||||
|
|
|
|||
|
|
@ -20,9 +20,27 @@ export const updateHotkeyTip = compatibility.updateHotkeyTip;
|
|||
export const getLocalStorage = compatibility.getLocalStorage;
|
||||
export const setStorageVal = compatibility.setStorageVal;
|
||||
|
||||
export const sendNotification = (channel: string, title: string, body: string, delayInSeconds: number): Promise<number> => {
|
||||
export interface ISendNotificationOptions {
|
||||
channel?: string,
|
||||
title?: string,
|
||||
body?: string,
|
||||
delayInSeconds?: number,
|
||||
timeoutType?: "default" | "never"
|
||||
}
|
||||
|
||||
export const sendNotification = (options: ISendNotificationOptions): Promise<number> => {
|
||||
return new Promise((resolve) => {
|
||||
const title = options.title || "";
|
||||
const body = options.body || "";
|
||||
const delayInSeconds = options.delayInSeconds || 0;
|
||||
if (!title.trim() && !body.trim()) {
|
||||
// 不能同时为空
|
||||
resolve(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
/// #if BROWSER
|
||||
const channel = options.channel || "Plugin Notification";
|
||||
if (window.JSAndroid && window.JSAndroid.sendNotification) {
|
||||
const id = window.JSAndroid.sendNotification(channel, title, body, delayInSeconds);
|
||||
resolve(id);
|
||||
|
|
@ -49,11 +67,13 @@ export const sendNotification = (channel: string, title: string, body: string, d
|
|||
resolve(-1);
|
||||
}
|
||||
/// #else
|
||||
const timeoutType = options.timeoutType || "default";
|
||||
const timeoutId = window.setTimeout(() => {
|
||||
ipcRenderer.send(Constants.SIYUAN_CMD, {
|
||||
cmd: "notification",
|
||||
title,
|
||||
body
|
||||
body,
|
||||
timeoutType
|
||||
});
|
||||
}, delayInSeconds * 1000);
|
||||
resolve(timeoutId);
|
||||
|
|
@ -62,6 +82,9 @@ export const sendNotification = (channel: string, title: string, body: string, d
|
|||
};
|
||||
|
||||
export const cancelNotification = (id: number) => {
|
||||
if (id <= 0) {
|
||||
return;
|
||||
}
|
||||
/// #if BROWSER
|
||||
if (window.JSAndroid && window.JSAndroid.cancelNotification) {
|
||||
window.JSAndroid.cancelNotification(id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue