Skip to content

Commit

Permalink
fix: Some image cannot show due to the path is not normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed May 28, 2023
1 parent 61ed745 commit 91b9caa
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions xmcl-runtime/lib/plugins/pluginCommonProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ const builtin: Record<string, string> = {
* 3. common `image:` with absolute file path
*/
export const pluginCommonProtocol: LauncherAppPlugin = (app) => {
const normalizePath = (path: string) => {
if (app.platform.name === 'windows') {
return decodeURIComponent(path.startsWith('/') ? path.substring(1) : path)
}
return decodeURIComponent(path.startsWith('//') ? path.substring(1) : path)
}
app.protocol.registerHandler('image', async ({ request, response }) => {
if (request.url.host === 'builtin') {
// Builtin image
Expand All @@ -45,7 +51,7 @@ export const pluginCommonProtocol: LauncherAppPlugin = (app) => {
}
} else if (!request.url.host) {
// Absolute image path
const pathname = decodeURIComponent(request.url.pathname.substring(1))
const pathname = normalizePath(request.url.pathname)
const { fromFile } = await import('file-type')
await fromFile(pathname).then((type) => {
if (type && type.mime.startsWith('image/')) {
Expand All @@ -62,7 +68,7 @@ export const pluginCommonProtocol: LauncherAppPlugin = (app) => {
})
app.protocol.registerHandler('video', async ({ request, response }) => {
// Absolute video path
const pathname = decodeURIComponent(request.url.pathname.substring(1))
const pathname = normalizePath(request.url.pathname)
const { fromFile } = await import('file-type')
await fromFile(pathname).then((type) => {
if (type && type.mime.startsWith('video/')) {
Expand Down

0 comments on commit 91b9caa

Please sign in to comment.