From 87eac92b3dfa8708e646960a07b982a448d0b071 Mon Sep 17 00:00:00 2001 From: yuruo Date: Thu, 6 Jun 2024 17:24:40 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(index.ts)=EF=BC=9A=E9=87=8D=E6=9E=84U?= =?UTF-8?q?I=E7=AA=97=E5=8F=A3=E5=88=9B=E5=BB=BA=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E4=B8=BA=E7=8B=AC=E7=AB=8B=E6=96=87=E4=BB=B6=20=20=20?= =?UTF-8?q?=F0=9F=93=9D(window.ts)=EF=BC=9A=E6=B7=BB=E5=8A=A0=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E5=88=9B=E5=BB=BA=E5=92=8C=E9=85=8D=E7=BD=AE=E6=96=B9?= =?UTF-8?q?=E6=B3=95=20=20=20=F0=9F=93=9D(ipc.ts)=EF=BC=9A=E9=87=8D?= =?UTF-8?q?=E6=9E=84IPC=E6=B6=88=E6=81=AF=E6=B3=A8=E5=86=8C=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/autoMate/src/main/code/index.ts | 9 +++++ ui/autoMate/src/main/code/window.ts | 43 ++++++++++++++++++++++++ ui/autoMate/src/main/index.ts | 51 ++++------------------------- ui/autoMate/src/main/ipc.ts | 10 +++--- 4 files changed, 63 insertions(+), 50 deletions(-) create mode 100644 ui/autoMate/src/main/code/index.ts create mode 100644 ui/autoMate/src/main/code/window.ts diff --git a/ui/autoMate/src/main/code/index.ts b/ui/autoMate/src/main/code/index.ts new file mode 100644 index 0000000..fd07076 --- /dev/null +++ b/ui/autoMate/src/main/code/index.ts @@ -0,0 +1,9 @@ +import { app } from 'electron' +import { createWindow } from './window' + + +app.whenReady().then(() => { + createWindow() +}) + + diff --git a/ui/autoMate/src/main/code/window.ts b/ui/autoMate/src/main/code/window.ts new file mode 100644 index 0000000..94066a3 --- /dev/null +++ b/ui/autoMate/src/main/code/window.ts @@ -0,0 +1,43 @@ + +import { BrowserWindow, shell } from 'electron' +import { is } from '@electron-toolkit/utils' +import icon from '../../../resources/icon.png?asset' +import * as ipc from './ipc' +import { join } from 'path' + +export function createWindow(): void { // Create the browser window. + const mainWindow = new BrowserWindow({ + width: 600, + height: 350, + show: false, + // transparent: true, + // frame: false, + // alwaysOnTop: true, + autoHideMenuBar: true, + ...(process.platform === 'linux' ? { icon } : {}), + webPreferences: { + preload: join(__dirname, '../preload/index.js'), + sandbox: false + } + }) + ipc.registerIpc(mainWindow) + + mainWindow.webContents.openDevTools() + mainWindow.on('ready-to-show', () => { + mainWindow.show() + }) + + mainWindow.webContents.setWindowOpenHandler((details) => { + shell.openExternal(details.url) + return { action: 'deny' } + }) + + // HMR for renderer base on electron-vite cli. + // Load the remote URL for development or the local html file for production. + if (is.dev && process.env['ELECTRON_RENDERER_URL']) { + mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL']) + } else { + mainWindow.loadFile(join(__dirname, '../renderer/index.html')) + } + } + \ No newline at end of file diff --git a/ui/autoMate/src/main/index.ts b/ui/autoMate/src/main/index.ts index 8aa144f..d19da58 100644 --- a/ui/autoMate/src/main/index.ts +++ b/ui/autoMate/src/main/index.ts @@ -1,43 +1,5 @@ -import { app, shell, BrowserWindow, ipcMain } from 'electron' -import { join } from 'path' -import { electronApp, optimizer, is } from '@electron-toolkit/utils' -import icon from '../../resources/icon.png?asset' -import './ipc' - -function createWindow(): void { // Create the browser window. - const mainWindow = new BrowserWindow({ - width: 600, - height: 350, - show: false, - // transparent: true, - // frame: false, - // alwaysOnTop: true, - autoHideMenuBar: true, - ...(process.platform === 'linux' ? { icon } : {}), - webPreferences: { - preload: join(__dirname, '../preload/index.js'), - sandbox: false - } - }) - - mainWindow.webContents.openDevTools() - mainWindow.on('ready-to-show', () => { - mainWindow.show() - }) - - mainWindow.webContents.setWindowOpenHandler((details) => { - shell.openExternal(details.url) - return { action: 'deny' } - }) - - // HMR for renderer base on electron-vite cli. - // Load the remote URL for development or the local html file for production. - if (is.dev && process.env['ELECTRON_RENDERER_URL']) { - mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL']) - } else { - mainWindow.loadFile(join(__dirname, '../renderer/index.html')) - } -} +import { app, BrowserWindow, ipcMain } from 'electron' +import { electronApp, optimizer } from '@electron-toolkit/utils' // This method will be called when Electron has finished // initialization and is ready to create browser windows. @@ -55,15 +17,14 @@ app.whenReady().then(() => { // IPC test ipcMain.on('ping', () => console.log('pong')) - - createWindow() - + app.on('activate', function () { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. - if (BrowserWindow.getAllWindows().length === 0) createWindow() + if (BrowserWindow.getAllWindows().length === 0) code.createWindow() }) -}) + +}) // Quit when all windows are closed, except on macOS. There, it's common // for applications and their menu bar to stay active until the user quits diff --git a/ui/autoMate/src/main/ipc.ts b/ui/autoMate/src/main/ipc.ts index a3da8da..889ba7b 100644 --- a/ui/autoMate/src/main/ipc.ts +++ b/ui/autoMate/src/main/ipc.ts @@ -1,7 +1,7 @@ -import {ipcMain, BrowserWindow, IpcMainEvent } from "electron"; - -ipcMain.on('hideWindow', (event: IpcMainEvent) => { - const win = BrowserWindow.fromWebContents(event.sender) - if(win) win.hide() +import {ipcMain, BrowserWindow} from "electron"; +export const registerIpc = (win: BrowserWindow)=>{ +ipcMain.on('hideWindow', () => { + win.hide() }) +}