From da40448ca1a2485364334bd661cc5312e38a283b Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:41:29 +0100 Subject: [PATCH] Merge pull request #636 from Zagrios/bugfix/unable-to-load-bsm-files-if-path-to-bsm-contains-url-special-chars [bugfix] Unable to load bsm's files if path to bsm contain url special chars (cherry picked from commit 6666685c4349b31a4b13110605a054df9cdd7ddb) --- src/main/util.ts | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/util.ts b/src/main/util.ts index c9dac068..508c31fa 100644 --- a/src/main/util.ts +++ b/src/main/util.ts @@ -1,17 +1,15 @@ /* eslint import/prefer-default-export: off, import/no-mutable-exports: off */ -import { URL } from "url"; +import { pathToFileURL, URL } from "url"; import path from "path"; -export let resolveHtmlPath: (htmlFileName: string) => string; - -if (process.env.NODE_ENV === "development") { - const port = process.env.PORT || 1212; - resolveHtmlPath = (htmlFileName: string) => { +export function resolveHtmlPath (htmlFileName: string) { + if (process.env.NODE_ENV === "development") { + const port = process.env.PORT || 1212; const url = new URL(`http://localhost:${port}/${htmlFileName}`); return url.toString(); - }; -} else { - resolveHtmlPath = (htmlFileName: string) => { - return `file://${path.resolve(__dirname, "../renderer/", htmlFileName)}`; - }; -} + } + const filePath = path.resolve(__dirname, "..", "renderer", htmlFileName); + return pathToFileURL(filePath).toString(); +}; + +