处理路径中存在百分号导致的问题

This commit is contained in:
lyswhut
2022-11-04 20:27:51 +08:00
parent 209bf9e0aa
commit 11d3754c08
12 changed files with 35 additions and 29 deletions
+4 -4
View File
@@ -3,7 +3,7 @@ import { BrowserWindow } from 'electron'
import fs from 'fs'
import { join } from 'path'
import { openDevTools as handleOpenDevTools } from '@main/utils'
import { encodePath, isWin } from '@common/utils'
import { encodePath } from '@common/utils'
let browserWindow: Electron.BrowserWindow | null = null
@@ -27,14 +27,14 @@ const winEvent = () => {
export const createWindow = async(userApi: LX.UserApi.UserApiInfo) => {
await closeWindow()
if (!dir) dir = global.isDev ? webpackUserApiPath : join(encodePath(isWin ? __dirname.replaceAll('\\', '/') : __dirname), 'userApi')
if (!dir) dir = global.isDev ? webpackUserApiPath : join(encodePath(__dirname), 'userApi')
if (!html) {
html = await fs.promises.readFile(join(dir, 'renderer/user-api.html'), 'utf8')
}
const preloadUrl = global.isDev
? `${join(encodePath(isWin ? __dirname.replaceAll('\\', '/') : __dirname), '../dist/user-api-preload.js')}`
: `${join(encodePath(isWin ? __dirname.replaceAll('\\', '/') : __dirname), 'user-api-preload.js')}`
? `${join(encodePath(__dirname), '../dist/user-api-preload.js')}`
: `${join(encodePath(__dirname), 'user-api-preload.js')}`
// console.log(preloadUrl)
/**
+2 -2
View File
@@ -1,6 +1,6 @@
import { join } from 'path'
import { BrowserWindow } from 'electron'
import { debounce, encodePath, isLinux, isWin } from '@common/utils'
import { debounce, encodePath, isLinux } from '@common/utils'
import { getLyricWindowBounds } from './utils'
import { mainSend } from '@common/mainIpc'
@@ -133,7 +133,7 @@ export const createWindow = () => {
},
})
const winURL = global.isDev ? 'http://localhost:9081/lyric.html' : `file://${join(encodePath(isWin ? __dirname.replaceAll('\\', '/') : __dirname), 'lyric.html')}`
const winURL = global.isDev ? 'http://localhost:9081/lyric.html' : `file://${join(encodePath(__dirname), 'lyric.html')}`
void browserWindow.loadURL(winURL + `?dark=${shouldUseDarkColors}&theme=${encodeURIComponent(JSON.stringify(theme))}`)
winEvent()
+1 -1
View File
@@ -93,7 +93,7 @@ export const createWindow = () => {
}
browserWindow = new BrowserWindow(options)
const winURL = global.isDev ? 'http://localhost:9080' : `file://${join(encodePath(isWin ? __dirname.replaceAll('\\', '/') : __dirname), 'index.html')}`
const winURL = global.isDev ? 'http://localhost:9080' : `file://${join(encodePath(__dirname), 'index.html')}`
void browserWindow.loadURL(winURL + `?dt=${!!global.envParams.cmdParams.dt}&dark=${shouldUseDarkColors}&theme=${encodeURIComponent(JSON.stringify(theme))}`)
winEvent()