Track bundled vendor runtime sources
This commit is contained in:
52
vendor/aigcpanel/electron/lib/hooks.ts
vendored
Normal file
52
vendor/aigcpanel/electron/lib/hooks.ts
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
import { BrowserView, BrowserWindow } from "electron";
|
||||
import { AppsMain } from "../mapi/app/main";
|
||||
|
||||
type HookType =
|
||||
| never
|
||||
| "Show"
|
||||
| "Hide"
|
||||
| "EnterFullScreen"
|
||||
| "LeaveFullScreen"
|
||||
| "ShowQuitConfirmDialog";
|
||||
|
||||
export const executeHooks = async (
|
||||
win: BrowserWindow,
|
||||
hook: HookType,
|
||||
data?: any,
|
||||
) => {
|
||||
const evalJs = `
|
||||
if(window.__page && window.__page.hooks && typeof window.__page.hooks.on${hook} === 'function' ) {
|
||||
try {
|
||||
window.__page.hooks.on${hook}(${JSON.stringify(data)});
|
||||
} catch(e) {
|
||||
console.log('executeHooks.on${hook}.error', e);
|
||||
}
|
||||
}`;
|
||||
return win.webContents?.executeJavaScript(evalJs);
|
||||
};
|
||||
|
||||
export const executeDarkMode = async (
|
||||
view: BrowserWindow | BrowserView,
|
||||
data: {
|
||||
isSystem: boolean;
|
||||
},
|
||||
) => {
|
||||
data = Object.assign(
|
||||
{
|
||||
isSystem: false,
|
||||
},
|
||||
data,
|
||||
);
|
||||
if (await AppsMain.shouldDarkMode()) {
|
||||
// body and html
|
||||
view.webContents.executeJavaScript(`
|
||||
document.body.setAttribute('data-theme', 'dark');
|
||||
document.documentElement.setAttribute('data-theme', 'dark');
|
||||
`);
|
||||
if (data.isSystem) {
|
||||
view.webContents.executeJavaScript(
|
||||
`document.body.setAttribute('arco-theme', 'dark');`,
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user