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

pull/1050/head
lyswhut 2022-11-04 20:27:51 +08:00
parent 209bf9e0aa
commit 11d3754c08
12 changed files with 35 additions and 29 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "lx-music-desktop", "name": "lx-music-desktop",
"version": "2.0.0-beta.3", "version": "2.0.0-beta.4",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "lx-music-desktop", "name": "lx-music-desktop",
"version": "2.0.0-beta.3", "version": "2.0.0-beta.4",
"hasInstallScript": true, "hasInstallScript": true,
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "lx-music-desktop", "name": "lx-music-desktop",
"version": "2.0.0-beta.3", "version": "2.0.0-beta.4",
"description": "一个免费的音乐查找助手", "description": "一个免费的音乐查找助手",
"main": "./dist/main.js", "main": "./dist/main.js",
"productName": "lx-music-desktop", "productName": "lx-music-desktop",

View File

@ -175,3 +175,8 @@ export const sortInsert = (arr: Array<{ num: number, data: any }>, data: { num:
arr.splice(left, 0, data) arr.splice(left, 0, data)
} }
export const encodePath = (path: string) => {
// https://github.com/lyswhut/lx-music-desktop/issues/963
return path.replaceAll('%', '%25')
}

View File

@ -27,11 +27,6 @@ export function compareVer(currentVer: string, targetVer: string): -1 | 0 | 1 {
return 0 return 0
} }
export const encodePath = (path: string) => {
// https://github.com/lyswhut/lx-music-desktop/issues/963
return path.replaceAll('%', '%25')
}
export { export {
log, log,

View File

@ -7,7 +7,7 @@ import { navigationUrlWhiteList } from '@common/config'
import defaultSetting from '@common/defaultSetting' import defaultSetting from '@common/defaultSetting'
import { closeWindow, isExistWindow as isExistMainWindow, showWindow as showMainWindow } from './modules/winMain' import { closeWindow, isExistWindow as isExistMainWindow, showWindow as showMainWindow } from './modules/winMain'
import { createAppEvent, createListEvent } from '@main/event' import { createAppEvent, createListEvent } from '@main/event'
import { encodePath, isMac, log } from '@common/utils' import { isMac, log } from '@common/utils'
import createWorkers from './worker' import createWorkers from './worker'
import { migrateDBData } from './utils/migrate' import { migrateDBData } from './utils/migrate'
@ -84,8 +84,8 @@ export const setUserDataPath = () => {
} }
const userDataPath = app.getPath('userData') const userDataPath = app.getPath('userData')
global.lxDataPath = join(encodePath(userDataPath.replaceAll('\\', '/')), 'LxDatas') global.lxOldDataPath = userDataPath
global.lxOldDataPath = encodePath(userDataPath.replaceAll('\\', '/')) global.lxDataPath = join(userDataPath, 'LxDatas')
if (!existsSync(global.lxDataPath)) mkdirSync(global.lxDataPath) if (!existsSync(global.lxDataPath)) mkdirSync(global.lxDataPath)
} }

View File

@ -3,7 +3,7 @@ import { BrowserWindow } from 'electron'
import fs from 'fs' import fs from 'fs'
import { join } from 'path' import { join } from 'path'
import { openDevTools as handleOpenDevTools } from '@main/utils' import { openDevTools as handleOpenDevTools } from '@main/utils'
import { encodePath, isWin } from '@common/utils' import { encodePath } from '@common/utils'
let browserWindow: Electron.BrowserWindow | null = null let browserWindow: Electron.BrowserWindow | null = null
@ -27,14 +27,14 @@ const winEvent = () => {
export const createWindow = async(userApi: LX.UserApi.UserApiInfo) => { export const createWindow = async(userApi: LX.UserApi.UserApiInfo) => {
await closeWindow() 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) { if (!html) {
html = await fs.promises.readFile(join(dir, 'renderer/user-api.html'), 'utf8') html = await fs.promises.readFile(join(dir, 'renderer/user-api.html'), 'utf8')
} }
const preloadUrl = global.isDev const preloadUrl = global.isDev
? `${join(encodePath(isWin ? __dirname.replaceAll('\\', '/') : __dirname), '../dist/user-api-preload.js')}` ? `${join(encodePath(__dirname), '../dist/user-api-preload.js')}`
: `${join(encodePath(isWin ? __dirname.replaceAll('\\', '/') : __dirname), 'user-api-preload.js')}` : `${join(encodePath(__dirname), 'user-api-preload.js')}`
// console.log(preloadUrl) // console.log(preloadUrl)
/** /**

View File

@ -1,6 +1,6 @@
import { join } from 'path' import { join } from 'path'
import { BrowserWindow } from 'electron' import { BrowserWindow } from 'electron'
import { debounce, encodePath, isLinux, isWin } from '@common/utils' import { debounce, encodePath, isLinux } from '@common/utils'
import { getLyricWindowBounds } from './utils' import { getLyricWindowBounds } from './utils'
import { mainSend } from '@common/mainIpc' 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))}`) void browserWindow.loadURL(winURL + `?dark=${shouldUseDarkColors}&theme=${encodeURIComponent(JSON.stringify(theme))}`)
winEvent() winEvent()

View File

@ -93,7 +93,7 @@ export const createWindow = () => {
} }
browserWindow = new BrowserWindow(options) 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))}`) void browserWindow.loadURL(winURL + `?dt=${!!global.envParams.cmdParams.dt}&dark=${shouldUseDarkColors}&theme=${encodeURIComponent(JSON.stringify(theme))}`)
winEvent() winEvent()

View File

@ -1,4 +1,4 @@
import { isUrl, throttle } from '@common/utils' import { encodePath, isUrl, throttle } from '@common/utils'
import migrateSetting from '@common/utils/migrateSetting' import migrateSetting from '@common/utils/migrateSetting'
import getStore from '@main/utils/store' import getStore from '@main/utils/store'
import { STORE_NAMES, URL_SCHEME_RXP } from '@common/constants' import { STORE_NAMES, URL_SCHEME_RXP } from '@common/constants'
@ -250,7 +250,7 @@ export const getTheme = () => {
theme.config.extInfo['--background-image'] = theme.config.extInfo['--background-image'] =
isUrl(theme.config.extInfo['--background-image']) isUrl(theme.config.extInfo['--background-image'])
? `url(${theme.config.extInfo['--background-image']})` ? `url(${theme.config.extInfo['--background-image']})`
: `url(file:///${joinPath(global.lxDataPath, 'theme_images', theme.config.extInfo['--background-image']).replaceAll('\\', '/')})` : `url(file:///${encodePath(joinPath(global.lxDataPath, 'theme_images', theme.config.extInfo['--background-image']).replaceAll('\\', '/'))})`
} }
} else { } else {
themeId = global.lx.appSetting['theme.id'] == 'auto' && shouldUseDarkColors ? 'black' : 'green' themeId = global.lx.appSetting['theme.id'] == 'auto' && shouldUseDarkColors ? 'black' : 'green'

View File

@ -1,3 +1,4 @@
import { encodePath } from '@common/utils/common'
import { updateListMusics } from '@renderer/store/list/action' import { updateListMusics } from '@renderer/store/list/action'
import { saveLyric, saveMusicUrl } from '@renderer/utils/ipc' import { saveLyric, saveMusicUrl } from '@renderer/utils/ipc'
import { getLocalFilePath } from '@renderer/utils/music' import { getLocalFilePath } from '@renderer/utils/music'
@ -19,7 +20,7 @@ export const getMusicUrl = async({ musicInfo, isRefresh, onToggleSource = () =>
}): Promise<string> => { }): Promise<string> => {
if (!isRefresh) { if (!isRefresh) {
const path = await getLocalFilePath(musicInfo) const path = await getLocalFilePath(musicInfo)
if (path) return path if (path) return encodePath(path)
} }
onToggleSource() onToggleSource()
const otherSource = await getOtherSource(musicInfo) const otherSource = await getOtherSource(musicInfo)

View File

@ -6,7 +6,7 @@
// return listId == 'download' ? downloadList : getListFromState(listId) // return listId == 'download' ? downloadList : getListFromState(listId)
// } // }
import { commonColorNames, commonDarkColorValues, commonLightColorValues } from '@common/config' import { commonColorNames, commonDarkColorValues, commonLightColorValues } from '@common/config'
import { isUrl } from '@common/utils/common' import { encodePath, isUrl } from '@common/utils/common'
import { joinPath } from '@common/utils/nodejs' import { joinPath } from '@common/utils/nodejs'
import { markRaw, shallowReactive } from '@common/utils/vueTools' import { markRaw, shallowReactive } from '@common/utils/vueTools'
import { getThemes as getTheme } from '@renderer/utils/ipc' import { getThemes as getTheme } from '@renderer/utils/ipc'
@ -19,7 +19,7 @@ export const assertApiSupport = (source: LX.Source): boolean => {
export const buildBgUrl = (originUrl: string, dataPath: string): string => { export const buildBgUrl = (originUrl: string, dataPath: string): string => {
return isUrl(originUrl) return isUrl(originUrl)
? `url(${originUrl})` ? `url(${originUrl})`
: `url(file:///${joinPath(dataPath, originUrl).replaceAll('\\', '/')})` : `url(file:///${encodePath(joinPath(dataPath, originUrl).replaceAll('\\', '/'))})`
} }
export const getThemes = (callback: (themeInfo: LX.ThemeInfo) => void) => { export const getThemes = (callback: (themeInfo: LX.ThemeInfo) => void) => {

View File

@ -120,7 +120,7 @@
import { joinPath, extname, copyFile, checkPath, createDir, removeFile, moveFile, basename } from '@common/utils/nodejs' import { joinPath, extname, copyFile, checkPath, createDir, removeFile, moveFile, basename } from '@common/utils/nodejs'
import { nextTick, ref, watch } from '@common/utils/vueTools' import { nextTick, ref, watch } from '@common/utils/vueTools'
import { applyTheme, buildThemeColors, getThemes, copyTheme } from '@renderer/store/utils' import { applyTheme, buildThemeColors, getThemes, copyTheme } from '@renderer/store/utils'
import { isUrl } from '@common/utils/common' import { isUrl, encodePath } from '@common/utils/common'
// import { appSetting, updateSetting } from '@renderer/store/setting' // import { appSetting, updateSetting } from '@renderer/store/setting'
// import { applyTheme, getThemes } from '@renderer/store/utils' // import { applyTheme, getThemes } from '@renderer/store/utils'
import { createThemeColors } from '@common/theme/utils' import { createThemeColors } from '@common/theme/utils'
@ -158,6 +158,7 @@ export default {
const isDark = ref(false) const isDark = ref(false)
const preview = ref(false) const preview = ref(false)
const bgImg = ref('') const bgImg = ref('')
let bgImgRaw = ''
let originBgName = '' let originBgName = ''
let currentBgPath = '' let currentBgPath = ''
@ -243,11 +244,13 @@ export default {
currentBgPath = '' currentBgPath = ''
if (theme.config.extInfo['--background-image'] == 'none') { if (theme.config.extInfo['--background-image'] == 'none') {
bgImg.value = '' bgImg.value = ''
bgImgRaw = ''
originBgName = '' originBgName = ''
} else { } else {
bgImg.value = isUrl(theme.config.extInfo['--background-image']) bgImgRaw = isUrl(theme.config.extInfo['--background-image'])
? theme.config.extInfo['--background-image'] ? theme.config.extInfo['--background-image']
: joinPath(themeInfo.dataPath, theme.config.extInfo['--background-image']) : joinPath(themeInfo.dataPath, theme.config.extInfo['--background-image'])
bgImg.value = encodePath(bgImgRaw)
originBgName = theme.config.extInfo['--background-image'] originBgName = theme.config.extInfo['--background-image']
} }
appBgColorOrigin = theme.config.extInfo['--color-app-background'] appBgColorOrigin = theme.config.extInfo['--color-app-background']
@ -372,7 +375,8 @@ export default {
const bgPath = joinPath(tempDir, fileName) const bgPath = joinPath(tempDir, fileName)
if (!await checkPath(tempDir)) await createDir(tempDir) if (!await checkPath(tempDir)) await createDir(tempDir)
await copyFile(path, bgPath) await copyFile(path, bgPath)
currentBgPath = bgImg.value = bgPath currentBgPath = bgImgRaw = bgPath
bgImg.value = encodePath(bgImgRaw)
theme.config.extInfo['--background-image'] = 'temp/' + fileName theme.config.extInfo['--background-image'] = 'temp/' + fileName
createPreview() createPreview()
@ -383,6 +387,7 @@ export default {
currentBgPath = '' currentBgPath = ''
} }
bgImg.value = '' bgImg.value = ''
bgImgRaw = ''
theme.config.extInfo['--background-image'] = 'none' theme.config.extInfo['--background-image'] = 'none'
createPreview() createPreview()
} }
@ -474,9 +479,9 @@ export default {
const name = basename(currentBgPath) const name = basename(currentBgPath)
await moveFile(currentBgPath, joinPath(themeInfo.dataPath, name)) await moveFile(currentBgPath, joinPath(themeInfo.dataPath, name))
theme.config.extInfo['--background-image'] = name theme.config.extInfo['--background-image'] = name
} else if (bgImg.value) { } else if (bgImgRaw) {
const fileName = `${theme.id}_${Date.now()}${extname(bgImg.value)}` const fileName = `${theme.id}_${Date.now()}${extname(bgImgRaw)}`
await copyFile(bgImg.value, joinPath(themeInfo.dataPath, fileName)) await copyFile(bgImgRaw, joinPath(themeInfo.dataPath, fileName))
theme.config.extInfo['--background-image'] = fileName theme.config.extInfo['--background-image'] = fileName
} }
} }