2026-08-21 10:32:39 +08:00
|
|
|
"use strict";
|
|
|
|
|
const { contextBridge, ipcRenderer } = require("electron");
|
|
|
|
|
|
|
|
|
|
const SEND = new Set([
|
|
|
|
|
"pet:ready",
|
2026-08-25 14:15:29 +08:00
|
|
|
"pet:hit-rects",
|
2026-08-21 10:32:39 +08:00
|
|
|
"pet:drag-start",
|
|
|
|
|
"pet:drag-end",
|
|
|
|
|
"pet:context-menu",
|
|
|
|
|
"pet:tray-icon",
|
|
|
|
|
"pet:state",
|
|
|
|
|
"pet:log",
|
2026-08-21 15:11:56 +08:00
|
|
|
"pet:greeted",
|
2026-08-21 10:32:39 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
const ON = new Set([
|
|
|
|
|
"pet:init",
|
|
|
|
|
"pet:load",
|
|
|
|
|
"pet:scale",
|
|
|
|
|
"pet:settings",
|
|
|
|
|
"pet:event",
|
|
|
|
|
"pet:cursor",
|
2026-08-24 13:51:28 +08:00
|
|
|
"pet:cursor-pos",
|
2026-08-21 10:32:39 +08:00
|
|
|
"pet:drag-move",
|
2026-08-25 14:15:29 +08:00
|
|
|
"pet:drag-ended",
|
|
|
|
|
"pet:ignore-state",
|
2026-08-21 10:32:39 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
contextBridge.exposeInMainWorld("pet", {
|
|
|
|
|
send(channel, data) {
|
|
|
|
|
if (SEND.has(channel)) ipcRenderer.send(channel, data);
|
|
|
|
|
},
|
|
|
|
|
on(channel, callback) {
|
|
|
|
|
if (!ON.has(channel)) return () => {};
|
|
|
|
|
const listener = (_event, data) => callback(data);
|
|
|
|
|
ipcRenderer.on(channel, listener);
|
|
|
|
|
return () => ipcRenderer.removeListener(channel, listener);
|
|
|
|
|
},
|
|
|
|
|
});
|