From ab6cdfb797fab2fa6080bdb42eb748d0dcd836af Mon Sep 17 00:00:00 2001 From: gaze <397334393@qq.com> Date: Sun, 14 Jul 2024 02:53:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron-builder.yml | 1 + package.json | 15 +++++++++----- src/main/index.js | 45 +++++++++++++++++++++++++++++++++++++--- src/preload/index.js | 8 ++++++- src/renderer/src/App.vue | 19 ++++++++++++++++- 5 files changed, 78 insertions(+), 10 deletions(-) diff --git a/electron-builder.yml b/electron-builder.yml index c0dfc87..a465508 100644 --- a/electron-builder.yml +++ b/electron-builder.yml @@ -12,6 +12,7 @@ asarUnpack: - resources/** win: executableName: lol-assistant + requestedExecutionLevel: requireAdministrator nsis: artifactName: ${name}-${version}-setup.${ext} shortcutName: ${productName} diff --git a/package.json b/package.json index f975591..c47cfca 100644 --- a/package.json +++ b/package.json @@ -9,13 +9,18 @@ "format": "prettier --write .", "lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix", "start": "electron-vite preview", - "dev": "electron-vite dev", + "dev": "powershell -Command \"Start-Process cmd -ArgumentList '/k', 'cd %cd% && npm run dev:base' -Verb RunAs\"", + "dev:base": "electron-vite dev", "build": "electron-vite build", "postinstall": "electron-builder install-app-deps", - "build:unpack": "npm run build && electron-builder --dir", - "build:win": "npm run build && electron-builder --win", - "build:mac": "npm run build && electron-builder --mac", - "build:linux": "npm run build && electron-builder --linux" + "build:unpack:base": "npm run build && electron-builder --dir", + "build:win:base": "npm run build && electron-builder --win", + "build:mac:base": "npm run build && electron-builder --mac", + "build:linux:base": "npm run build && electron-builder --linux", + "build:unpack": "powershell -Command \"Start-Process cmd -ArgumentList '/k', 'cd %cd% && npm run build:unpack:base' -Verb RunAs\"", + "build:win": "powershell -Command \"Start-Process cmd -ArgumentList '/k', 'cd %cd% && npm run build:win:base' -Verb RunAs\"", + "build:mac": "powershell -Command \"Start-Process cmd -ArgumentList '/k', 'cd %cd% && npm run build:mac:base' -Verb RunAs\"", + "build:linux": "powershell -Command \"Start-Process cmd -ArgumentList '/k', 'cd %cd% && npm run build:linux:base' -Verb RunAs\"" }, "dependencies": { "@electron-toolkit/preload": "^3.0.1", diff --git a/src/main/index.js b/src/main/index.js index da9e3d0..10b5cda 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -2,6 +2,47 @@ 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 { exec } from 'child_process' + +const getBaseConfig = () => { + return new Promise((resolve) => + exec( + "chcp 936 && WMIC PROCESS WHERE name='LeagueClientUx.exe' GET commandline", + (error, stdout, stderr) => { + if (error) { + resolve({ + Auth: '', + BASE_URL: '' + }) + return + } + if (stderr) { + resolve({ + Auth: '', + BASE_URL: '' + }) + return + } + const tokenMatch = stdout.match(/--remoting-auth-token=([^\s"]+)/) + const portMatch = stdout.match(/--app-port=([^\s"]+)/) + const token = tokenMatch?.[1] || '' + const auth = Buffer.from(`riot:${token}`).toString('base64') + const port = portMatch?.[1] || '' + resolve( + token !== '' + ? { + Auth: `Basic ${auth}`, + BASE_URL: `https://127.0.0.1:${port}` + } + : { + Auth: 'Auth required', + BASE_URL: '' + } + ) + } + ) + ) +} function createWindow() { // Create the browser window. @@ -42,6 +83,7 @@ app.whenReady().then(() => { // Set app user model id for windows electronApp.setAppUserModelId('com.electron') + ipcMain.handle('getBaseConfig', getBaseConfig) // Default open or close DevTools by F12 in development // and ignore CommandOrControl + R in production. // see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils @@ -49,9 +91,6 @@ app.whenReady().then(() => { optimizer.watchWindowShortcuts(window) }) - // IPC test - ipcMain.on('ping', () => console.log('pong')) - createWindow() app.on('activate', function () { diff --git a/src/preload/index.js b/src/preload/index.js index 8d62cb9..7b4aca7 100644 --- a/src/preload/index.js +++ b/src/preload/index.js @@ -1,4 +1,4 @@ -import { contextBridge } from 'electron' +import { contextBridge, ipcRenderer } from 'electron' import { electronAPI } from '@electron-toolkit/preload' // Custom APIs for renderer @@ -11,10 +11,16 @@ if (process.contextIsolated) { try { contextBridge.exposeInMainWorld('electron', electronAPI) contextBridge.exposeInMainWorld('api', api) + contextBridge.exposeInMainWorld('electronAPI', { + getBaseConfig: () => ipcRenderer.invoke('getBaseConfig') + }) } catch (error) { console.error(error) } } else { window.electron = electronAPI window.api = api + window.electronAPI = { + getBaseConfig: () => ipcRenderer.invoke('getBaseConfig') + } } diff --git a/src/renderer/src/App.vue b/src/renderer/src/App.vue index 3988215..c9e1da6 100644 --- a/src/renderer/src/App.vue +++ b/src/renderer/src/App.vue @@ -1,7 +1,24 @@