Skip to content

Commit

Permalink
🐛 修复非主页面窗口在打包后找不到路径的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sulgweb committed May 7, 2024
1 parent 5065d23 commit 9bd648a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "baize-toolbox",
"version": "0.0.1",
"version": "0.0.1-beta2",
"description": "An Electron application with React and TypeScript",
"main": "./out/main/index.js",
"author": "xiaoyu@sulg.top",
Expand Down
8 changes: 7 additions & 1 deletion src/main/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ interface ICreateWin {
config: BrowserWindowConstructorOptions
url: string
injectData?: any
route?: string
}

export async function createWin({ config, url, injectData }: ICreateWin): Promise<BrowserWindow> {
export async function createWin({ config, url, injectData, route }: ICreateWin): Promise<BrowserWindow> {
const win = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
Expand All @@ -90,6 +91,11 @@ export async function createWin({ config, url, injectData }: ICreateWin): Promis
...injectData,
},
})
if (route) {
win.webContents.on("did-finish-load", () => {
win.webContents.send("INIT_ROUTE", route)
})
}
initWinUrl(win, url)
return win
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/plugin/modules/ipcWin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ app.on("ready", async () => {
transparent: true,
alwaysOnTop: true,
},
url: "/siteAssistTransprent/index.html#/record-win",
url: "/siteAssistTransprent/index.html",
route: "record-win",
})
recordWin.on("ready-to-show", () => {
showCustomMenu(recordWin)
Expand Down
6 changes: 4 additions & 2 deletions src/main/plugin/modules/screenShot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ const createImageWin = async (data) => {
}
const imageWin = await createWin({
config,
url: "/siteAssistTransprent/index.html#/image-win",
url: "/siteAssistTransprent/index.html",
injectData: { base64 },
route: "/image-win",
})
imageWin.setSize(width + 12, height + 12)
imageWin.show()
Expand All @@ -68,7 +69,8 @@ app.whenReady().then(async () => {
alwaysOnTop: true,
show: false,
},
url: "/siteAssistTransprent/index.html#/screen-shot-win",
url: "/siteAssistTransprent/index.html",
route: "/screen-shot-win",
})
screenShotWin.on("ready-to-show", () => {
showCustomMenu(screenShotWin)
Expand Down
34 changes: 23 additions & 11 deletions src/renderer/siteAssistTransprent/src/router/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, { useEffect } from "react"
import { lazy, Suspense } from "react"
import { Routes, Route, HashRouter, Navigate } from "react-router-dom"
import { Routes, Route, HashRouter, useNavigate } from "react-router-dom"
import { ROUTERS } from "./ROUTERS"
import { Spin } from "antd"
import "./index.module.less"

const RecordWin = lazy(() => import("@siteAssistTransprent/pages/RecordWin"))
Expand All @@ -12,15 +11,28 @@ const ImageWin = lazy(() => import("@siteAssistTransprent/pages/ImageWin"))
export default function BaseRouter() {
return (
<HashRouter>
<Suspense fallback={<></>}>
<Routes>
<Route path={"/"}>
<Route path={ROUTERS.RECODE_WIN} element={<RecordWin />} />
<Route path={ROUTERS.SCREEN_SHOT_WIN} element={<ScreenShotWin />} />
<Route path={ROUTERS.IMAGE_WIN} element={<ImageWin />} />
</Route>
</Routes>
</Suspense>
<App />
</HashRouter>
)
}

const App = () => {
const navigate = useNavigate()
useEffect(() => {
window.ipcOn("INIT_ROUTE", (e, data) => {
console.log("INIT_ROUTE", e, data)
navigate(data)
})
}, [])
return (
<Suspense fallback={<></>}>
<Routes>
<Route path={"/"}>
<Route path={ROUTERS.RECODE_WIN} element={<RecordWin />} />
<Route path={ROUTERS.SCREEN_SHOT_WIN} element={<ScreenShotWin />} />
<Route path={ROUTERS.IMAGE_WIN} element={<ImageWin />} />
</Route>
</Routes>
</Suspense>
)
}

0 comments on commit 9bd648a

Please sign in to comment.