fix: windows file path (#3003)

* fix: tray menu

* fix: file path in windows
This commit is contained in:
DIYgod 2025-03-08 13:23:43 +08:00 committed by GitHub
parent e56505011c
commit eda72ab5a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 9 deletions

View File

@ -1,5 +1,3 @@
import url from "node:url"
import { electronApp, optimizer } from "@electron-toolkit/utils"
import { callWindowExpose } from "@follow/shared/bridge"
import { APP_PROTOCOL } from "@follow/shared/constants"
@ -77,7 +75,7 @@ function bootstrap() {
protocol.handle("app", (request) => {
try {
const urlObj = new URL(request.url)
return net.fetch(url.pathToFileURL(urlObj.pathname).toString())
return net.fetch(`file://${urlObj.pathname}`)
} catch {
logger.error("app protocol error", request.url)
return new Response("Not found", { status: 404 })

View File

@ -32,12 +32,22 @@ export const registerAppTray = () => {
click: showWindow,
},
{
role: "help",
label: t("menu.help"),
submenu: [
{ role: "reload", label: t("menu.reload") },
{ role: "forceReload", label: t("menu.forceReload") },
{ role: "toggleDevTools", label: t("menu.toggleDevTools") },
{
label: t("menu.reload"),
click: () => {
const mainWindow = getMainWindowOrCreate()
mainWindow.webContents.reload()
},
},
{
label: t("menu.toggleDevTools"),
click: () => {
const mainWindow = getMainWindowOrCreate()
mainWindow.webContents.toggleDevTools()
},
},
{
label: t("menu.openLogFile"),
click: async () => {

View File

@ -1,5 +1,5 @@
import path from "node:path"
import { fileURLToPath } from "node:url"
import { fileURLToPath, pathToFileURL } from "node:url"
import { is } from "@electron-toolkit/utils"
import { APP_PROTOCOL } from "@follow/shared"
@ -150,7 +150,8 @@ export function createWindow(
const dynamicRenderEntry = loadDynamicRenderEntry()
logger.info("load dynamic render entry", dynamicRenderEntry)
const appLoadFileEntry = dynamicRenderEntry || path.resolve(__dirname, "../renderer/index.html")
const appLoadEntry = `app://follow.is${appLoadFileEntry}${options?.extraPath || ""}`
const appLoadEntry = `app://follow.is${pathToFileURL(appLoadFileEntry).pathname}${options?.extraPath || ""}`
window.loadURL(appLoadEntry)
logger.log("load URL", appLoadEntry)