From 604fa91fe50911f70cf9fe7c00d26594a99db14e Mon Sep 17 00:00:00 2001 From: HoraceHyy Date: Sat, 6 Jan 2024 01:55:37 +0800 Subject: [PATCH] fix: type related errors --- electron/main/index.ts | 357 +++++++++--------- src/components/CustomUIDInput.vue | 6 +- src/components/TemplateDialog.vue | 15 +- .../Components/GenshinInfoCard.vue | 106 +++--- src/pages/GenshinPage/GenshinPage.vue | 4 +- src/pages/Honkai3Page.vue | 26 +- .../Components/StarRailInfoCard.vue | 32 +- src/pages/StarRailPage/StarRailPage.vue | 19 +- src/pages/tmpPage.vue | 2 +- src/types/starrail/srPlayerInfo.ts | 9 +- 10 files changed, 295 insertions(+), 281 deletions(-) diff --git a/electron/main/index.ts b/electron/main/index.ts index ee6ab31e..0d9c9658 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -1,16 +1,17 @@ -import { app, BrowserWindow, shell, ipcMain, nativeTheme, Tray, Menu } from 'electron' +import {app, BrowserWindow, ipcMain, Menu, nativeTheme, shell, Tray} from 'electron' import axios from 'axios' -import { release } from 'node:os' +import {release} from 'node:os' + const fs = require('fs').promises var path = require('path') const Store = require('electron-store'); const store = new Store(); const child = require('child_process') -const { dialog } = require('electron'); -const { Wrapper } = require('enkanetwork.js') -const { genshin } = new Wrapper({ - language: 'zh-CN' +const {dialog} = require('electron'); +const {Wrapper} = require('enkanetwork.js') +const {genshin} = new Wrapper({ + language: 'zh-CN' }) // The built directory structure @@ -26,8 +27,8 @@ const { genshin } = new Wrapper({ process.env.DIST_ELECTRON = path.join(__dirname, '..') process.env.DIST = path.join(process.env.DIST_ELECTRON, '../dist') process.env.PUBLIC = process.env.VITE_DEV_SERVER_URL - ? path.join(process.env.DIST_ELECTRON, '../public') - : process.env.DIST + ? path.join(process.env.DIST_ELECTRON, '../public') + : process.env.DIST // Disable GPU Acceleration for Windows 7 if (release().startsWith('6.1')) app.disableHardwareAcceleration() @@ -36,8 +37,8 @@ if (release().startsWith('6.1')) app.disableHardwareAcceleration() if (process.platform === 'win32') app.setAppUserModelId(app.getName()) if (!app.requestSingleInstanceLock()) { - app.quit() - process.exit(0) + app.quit() + process.exit(0) } // Remove electron security warnings @@ -61,189 +62,193 @@ var iconPath = path.join(process.env.PUBLIC, 'favicon.ico') var assetsPath = process.env.VITE_DEV_SERVER_URL ? '../../src/assets' : path.join(__dirname, '../../../src/assets') async function createWindow() { - win = new BrowserWindow({ - title: 'Main window', - icon: iconPath, - width: 1200, - height: 700, - resizable: false, - maximizable: false, - // transparent: true, - frame: false, - webPreferences: { - preload, - // Warning: Enable nodeIntegration and disable contextIsolation is not secure in production - // Consider using contextBridge.exposeInMainWorld - // Read more on https://www.electronjs.org/docs/latest/tutorial/context-isolation - nodeIntegration: false, - contextIsolation: true, - }, - }) - - // ---------- Window actions ---------- - ipcMain.on('win:close', () => { - win.close() - }) - ipcMain.on('win:min', () => { - win.minimize() - }) - ipcMain.on("win:tray", () => { - win.hide() - win.setSkipTaskbar(true) - }) - - // ---------- custom IPCs ---------- - - ipcMain.handle('store:get', (_event, key) => { - return store.get(key) - }) - ipcMain.on('store:set', (_event, key, value, json) => { - store.set(key, json ? JSON.parse(value) : value) - }) - ipcMain.on('store:delete', (_event, key) => { - store.delete(key) - }) - ipcMain.on('store:clear', () => { - store.clear() - }) - - ipcMain.on('child:exec', (_event, path) => { - child.execFile(path, function (err, data) { - if (err) { - console.error(err) - return - } - console.log(data.toString()) - }) - }) - - ipcMain.handle('dialog:show', async (_event, options) => { - const result = await dialog.showOpenDialog(win, options); - if (!result.canceled) { - return result.filePaths; - } else { - return []; - } - }); + win = new BrowserWindow({ + title: 'Main window', + icon: iconPath, + width: 1200, + height: 700, + resizable: false, + maximizable: false, + // transparent: true, + frame: false, + webPreferences: { + preload, + // Warning: Enable nodeIntegration and disable contextIsolation is not secure in production + // Consider using contextBridge.exposeInMainWorld + // Read more on https://www.electronjs.org/docs/latest/tutorial/context-isolation + nodeIntegration: false, + contextIsolation: true, + }, + }) + + // ---------- Window actions ---------- + ipcMain.on('win:close', () => { + win.close() + }) + ipcMain.on('win:min', () => { + win.minimize() + }) + ipcMain.on("win:tray", () => { + win.hide() + win.setSkipTaskbar(true) + }) - ipcMain.handle('dialog:showAndCopy', async (_event, options) => { - try { - const result = await dialog.showOpenDialog(win, options) - if (!result.canceled && result.filePaths.length > 0) { + // ---------- custom IPCs ---------- + + ipcMain.handle('store:get', (_event, key) => { + return store.get(key) + }) + ipcMain.on('store:set', (_event, key, value, json) => { + store.set(key, json ? JSON.parse(value) : value) + }) + ipcMain.on('store:delete', (_event, key) => { + store.delete(key) + }) + ipcMain.on('store:clear', () => { + store.clear() + }) + + ipcMain.on('child:exec', (_event, path) => { + child.execFile(path, function (err, data) { + if (err) { + console.error(err) + return + } + console.log(data.toString()) + }) + }) + + ipcMain.handle('dialog:show', async (_event, options) => { + const result = await dialog.showOpenDialog(win, options); + if (!result.canceled) { + return result.filePaths; + } else { + return []; + } + }); + + ipcMain.handle('dialog:showAndCopy', async (_event, options) => { try { - await fs.access(imageFolder) - } catch { - await fs.mkdir(imageFolder) + const result = await dialog.showOpenDialog(win, options) + if (!result.canceled && result.filePaths.length > 0) { + try { + await fs.access(imageFolder) + } catch { + await fs.mkdir(imageFolder) + } + + const sourcePath = result.filePaths[0]; + + const dataURL = await fs.readFile(sourcePath, 'base64') + .then(data => `data:image/png;base64,${data}`) + + return dataURL + } else { + return '' + } + } catch (err) { + console.error('Error copying image:', err); + throw err; } + }); - const sourcePath = result.filePaths[0]; + ipcMain.handle("enka:getGenshinPlayer", async (_event, uid, lang) => { + console.log("genshin enka ipcMain" + uid) + genshin.language = lang + const result = await genshin.getPlayer(uid) + return result + }) - const dataURL = await fs.readFile(sourcePath, 'base64') - .then(data => `data:image/png;base64,${data}`) + ipcMain.handle("path:joinDirnameAsset", (_event, arg) => { + return path.join(assetsPath, arg) + }) + + ipcMain.handle("axios:post", async (_event, url) => { + const result = await axios.post(url) + return result.data + }) + ipcMain.handle("axios:get", async (_event, url) => { + const result = await axios.get(url) + return result.data + }) + + ipcMain.on("elec:openExtLink", (_event, url) => { + shell.openExternal(url) + }) + + const {Octokit} = require("@octokit/core") + const octokit = new Octokit({ + auth: "" + }) + ipcMain.handle("github:getLatestRelease", async (_event) => { + const result = await octokit.request("GET /repos/horacehuang-ui/mihoyo-mixed-launcher/releases/latest", { + owner: "HoraceHuang-ui", + repo: "MiHOYO-MiXED-Launcher" + }) + return result + }) - return dataURL - } else { - return '' - } - } catch (err) { - console.error('Error copying image:', err); - throw err; + // --------- Window configs ------------ + // win.setWindowButtonVisibility(true) + nativeTheme.themeSource = "light" + if (process.env.VITE_DEV_SERVER_URL) { // electron-vite-vue#298 + win.loadURL(url) + //win.loadFile('./dist/index.html') + // Open devTool if the app is not packaged + win.webContents.openDevTools() + } else { + win.loadFile(indexHtml) } - }); - - ipcMain.handle("enka:getGenshinPlayer", async (_event, uid, lang) => { - console.log("genshin enka ipcMain" + uid) - genshin.language = lang - const result = await genshin.getPlayer(uid) - return result - }) - - ipcMain.handle("path:joinDirnameAsset", (_event, arg) => { - return path.join(assetsPath, arg) - }) - - ipcMain.handle("axios:post", async (_event, url) => { - const result = await axios.post(url) - return result.data - }) - ipcMain.handle("axios:get", async (_event, url) => { - const result = await axios.get(url) - return result.data - }) - - ipcMain.on("elec:openExtLink", (_event, url) => { - shell.openExternal(url) - }) - - const { Octokit } = require("@octokit/core") - const octokit = new Octokit({ - auth: "" - }) - ipcMain.handle("github:getLatestRelease", async (_event) => { - const result = await octokit.request("GET /repos/horacehuang-ui/mihoyo-mixed-launcher/releases/latest", { - owner: "HoraceHuang-ui", - repo: "MiHOYO-MiXED-Launcher" - }) - return result - }) - - // --------- Window configs ------------ - // win.setWindowButtonVisibility(true) - nativeTheme.themeSource = "light" - if (process.env.VITE_DEV_SERVER_URL) { // electron-vite-vue#298 - win.loadURL(url) - //win.loadFile('./dist/index.html') - // Open devTool if the app is not packaged - win.webContents.openDevTools() - } else { - win.loadFile(indexHtml) - } - - const contextMenu = Menu.buildFromTemplate([ - { label: '退出', click: () => { win.destroy() } }, - ]) - tray = new Tray(path.join(process.env.PUBLIC, 'favicon.ico')) - tray.setToolTip('miXeD') - tray.setContextMenu(contextMenu) - tray.on('click', () => { - win.isVisible() ? win.hide() : win.show() - win.isVisible() ? win.setSkipTaskbar(false) : win.setSkipTaskbar(true) - }) - - // Test actively push message to the Electron-Renderer - // win.webContents.on('did-finish-load', () => { - // win?.webContents.send('main-process-message', new Date().toLocaleString()) - // }) - - // Make all links open with the browser, not with the application - win.webContents.setWindowOpenHandler(({ url }) => { - if (url.startsWith('https:')) shell.openExternal(url) - return { action: 'deny' } - }) - // win.webContents.on('will-navigate', (event, url) => { }) #344 + + const contextMenu = Menu.buildFromTemplate([ + { + label: '退出', click: () => { + win.destroy() + } + }, + ]) + tray = new Tray(path.join(process.env.PUBLIC, 'favicon.ico')) + tray.setToolTip('miXeD') + tray.setContextMenu(contextMenu) + tray.on('click', () => { + win.isVisible() ? win.hide() : win.show() + win.isVisible() ? win.setSkipTaskbar(false) : win.setSkipTaskbar(true) + }) + + // Test actively push message to the Electron-Renderer + // win.webContents.on('did-finish-load', () => { + // win?.webContents.send('main-process-message', new Date().toLocaleString()) + // }) + + // Make all links open with the browser, not with the application + win.webContents.setWindowOpenHandler(({url}) => { + if (url.startsWith('https:')) shell.openExternal(url) + return {action: 'deny'} + }) + // win.webContents.on('will-navigate', (event, url) => { }) #344 } app.whenReady().then(createWindow) app.on('window-all-closed', () => { - win = null - if (process.platform !== 'darwin') app.quit() + win = null + if (process.platform !== 'darwin') app.quit() }) app.on('second-instance', () => { - if (win) { - // Focus on the main window if the user tried to open another - if (win.isMinimized()) win.restore() - win.focus() - } + if (win) { + // Focus on the main window if the user tried to open another + if (win.isMinimized()) win.restore() + win.focus() + } }) app.on('activate', () => { - const allWindows = BrowserWindow.getAllWindows() - if (allWindows.length) { - allWindows[0].focus() - } else { - createWindow() - } + const allWindows = BrowserWindow.getAllWindows() + if (allWindows.length) { + allWindows[0].focus() + } else { + createWindow() + } }) diff --git a/src/components/CustomUIDInput.vue b/src/components/CustomUIDInput.vue index 1c54a323..3dbf0584 100644 --- a/src/components/CustomUIDInput.vue +++ b/src/components/CustomUIDInput.vue @@ -1,12 +1,16 @@
- {{ parseInt(playerInfo.characters[charDialogId].stats.baseHp.value) }} + {{ parseInt(playerInfo.characters[charDialogId].stats.baseHp.value as string) }} +{{ - parseInt(playerInfo.characters[charDialogId].stats.maxHp.value) - - parseInt(playerInfo.characters[charDialogId].stats.baseHp.value) + parseInt(playerInfo.characters[charDialogId].stats.maxHp.value as string) + - parseInt(playerInfo.characters[charDialogId].stats.baseHp.value as string) }}
@@ -376,12 +376,12 @@ const findSkillIdByProud = (proudId: number): number => { style="margin-top: 2px;"/>
- {{ parseInt(playerInfo.characters[charDialogId].stats.baseAtk.value) }} + {{ parseInt(playerInfo.characters[charDialogId].stats.baseAtk.value as string) }} +{{ - parseInt(playerInfo.characters[charDialogId].stats.atk.value) - - parseInt(playerInfo.characters[charDialogId].stats.baseAtk.value) + parseInt(playerInfo.characters[charDialogId].stats.atk.value as string) - + parseInt(playerInfo.characters[charDialogId].stats.baseAtk.value as string) }}
@@ -391,17 +391,17 @@ const findSkillIdByProud = (proudId: number): number => { style="margin-top: 2px;"/>
- {{ parseInt(playerInfo.characters[charDialogId].stats.baseDef.value) }} + {{ parseInt(playerInfo.characters[charDialogId].stats.baseDef.value as string) }} +{{ - parseInt(playerInfo.characters[charDialogId].stats.def.value) - - parseInt(playerInfo.characters[charDialogId].stats.baseDef.value) + parseInt(playerInfo.characters[charDialogId].stats.def.value as string) - + parseInt(playerInfo.characters[charDialogId].stats.baseDef.value as string) }}
+ :val="playerInfo.characters[charDialogId].stats.elementalMastery.value ? parseInt(playerInfo.characters[charDialogId].stats.elementalMastery.value as string).toString() : '0'">