Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/17154

Vanessae514746cd6f6
diff --git a/app/electron/main.js b/app/electron/main.js
index 6090d5dbb8..628ce79fa6 100644
--- a/app/electron/main.js
+++ b/app/electron/main.js
@@ -18,6 +18,7 @@ const {
net,
app,
BrowserWindow,
+ Notification,
shell,
Menu,
MenuItem,
@@ -953,6 +954,12 @@ app.whenReady().then(() => {
case "showItemInFolder":
shell.showItemInFolder(data.filePath);
break;
+ case "notification":
+ new Notification({
+ title: data.title,
+ body: data.body,
+ }).show();
+ break;
case "setSpellCheckerLanguages":
BrowserWindow.getAllWindows().forEach(item => {
item.webContents.session.setSpellCheckerLanguages(data.languages);
@@ -1542,4 +1549,4 @@ function writeLog(out) {
} catch (e) {
console.error(e);
}
-}
\ No newline at end of file
+}
diff --git a/app/src/plugin/platformUtils.ts b/app/src/plugin/platformUtils.ts
index d18f408868..158a4b6422 100644
--- a/app/src/plugin/platformUtils.ts
+++ b/app/src/plugin/platformUtils.ts
@@ -1,5 +1,8 @@
import * as compatibility from "../protyle/util/compatibility";
-
+/// #if !BROWSER
+import {ipcRenderer} from "electron";
+import {Constants} from "../constants";
+/// #endif
export const openByMobile = compatibility.openByMobile;
export const readText = compatibility.readText;
export const writeText = compatibility.writeText;
@@ -17,7 +20,7 @@ export const updateHotkeyTip = compatibility.updateHotkeyTip;
export const getLocalStorage = compatibility.getLocalStorage;
export const setStorageVal = compatibility.setStorageVal;
-export const sendMobileAppNotification = (channel: string, title: string, body: string, delayInSeconds: number): Promise<number> => {
+export const sendNotification = (channel: string, title: string, body: string, delayInSeconds: number): Promise<number> => {
return new Promise((resolve) => {
/// #if BROWSER
if (window.JSAndroid && window.JSAndroid.sendNotification) {
@@ -32,7 +35,7 @@ export const sendMobileAppNotification = (channel: string, title: string, body:
if (!window.webkit.nativeCallbacks) {
window.webkit.nativeCallbacks = {};
}
- window.webkit.nativeCallbacks[callbackId] = (id:number) => {
+ window.webkit.nativeCallbacks[callbackId] = (id: number) => {
delete window.webkit.nativeCallbacks[callbackId];
resolve(id);
};
@@ -46,12 +49,19 @@ export const sendMobileAppNotification = (channel: string, title: string, body:
resolve(-1);
}
/// #else
- resolve(-1);
+ const timeoutId = window.setTimeout(() => {
+ ipcRenderer.send(Constants.SIYUAN_CMD, {
+ cmd: "notification",
+ title,
+ body
+ });
+ }, delayInSeconds * 1000);
+ resolve(timeoutId);
/// #endif
});
};
-export const cancelMobileAppNotification = (id: number) => {
+export const cancelNotification = (id: number) => {
/// #if BROWSER
if (window.JSAndroid && window.JSAndroid.cancelNotification) {
window.JSAndroid.cancelNotification(id);
@@ -60,5 +70,7 @@ export const cancelMobileAppNotification = (id: number) => {
} else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.cancelNotification) {
window.webkit.messageHandlers.cancelNotification.postMessage(id);
}
+ /// else
+ clearTimeout(id);
/// #endif
};