From 34ecdd8cdad9719eacadb4857ddc7ab80e600463 Mon Sep 17 00:00:00 2001 From: HoraceHyy Date: Sun, 28 Jan 2024 15:02:33 +0800 Subject: [PATCH] fix: type related issues in new API wrapper --- electron/main/index.ts | 34 ++++---- .../Components/GSCharDetailsOverlay.vue | 34 ++++---- .../Components/GenshinInfoCard.vue | 80 ++++++++++--------- src/pages/MainPage.vue | 2 +- vite.config.ts | 3 - 5 files changed, 81 insertions(+), 72 deletions(-) diff --git a/electron/main/index.ts b/electron/main/index.ts index 91998b5e..1ac0ff43 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -1,15 +1,21 @@ -import {app, BrowserWindow, ipcMain, Menu, nativeTheme, shell, Tray} from 'electron' +// const {dialog} = require('electron'); +import {app, BrowserWindow, dialog, ipcMain, Menu, nativeTheme, shell, Tray} from 'electron' import axios from 'axios' import {release} from 'node:os' +// const Store = require('electron-store') +import Store from 'electron-store' +// const child = require('child_process') +import child from 'child_process' +// const {EnkaClient, TextAssets, DynamicTextAssets} = require("enka-network-api"); +import {DynamicTextAssets, EnkaClient, TextAssets} from "enka-network-api"; -const fs = require('fs').promises -var path = require('path') +import {promises as fs} from 'fs'; + +// const fs = require('fs').promises +// var path = require('path') +import path from 'path' -const Store = require('electron-store'); const store = new Store(); -const child = require('child_process') -const {dialog} = require('electron'); -const {EnkaClient, TextAssets, DynamicTextAssets} = require("enka-network-api"); // The built directory structure // @@ -128,14 +134,7 @@ async function createWindow() { try { 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}`) @@ -158,6 +157,13 @@ async function createWindow() { if (obj instanceof TextAssets) { entries.push(["text", obj instanceof DynamicTextAssets ? obj.getNullableReplacedText() : obj.getNullable()]); // convert TextAssets to string } + if (obj instanceof Array) { + const arr = [] + for (const [_, entry] of entries) { + arr.push(entry) + } + return arr + } return Object.fromEntries(entries); } diff --git a/src/pages/GenshinPage/Components/GSCharDetailsOverlay.vue b/src/pages/GenshinPage/Components/GSCharDetailsOverlay.vue index 5990f3d2..06f448ed 100644 --- a/src/pages/GenshinPage/Components/GSCharDetailsOverlay.vue +++ b/src/pages/GenshinPage/Components/GSCharDetailsOverlay.vue @@ -1,5 +1,5 @@