From b76705809ddeb83aa2b990fd92279b97ac746a55 Mon Sep 17 00:00:00 2001 From: Miika Henttonen Date: Fri, 26 Jul 2024 10:49:33 +0300 Subject: [PATCH] Add trycatch to startup --- src/index.ts | 58 ++++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4c9c967..ef52eb1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -61,39 +61,43 @@ ipc.handle("getArtists", async () => { let musicLibraryPath = ""; const init = async (event: Electron.IpcMainInvokeEvent) => { - const state = await Fs.getState(stateFile); - const electronFileProtocol = "media://"; - musicLibraryPath = state?.musicLibraryPath || ""; - console.log("state", state, "\n"); - - if (!musicLibraryPath) { - const warning = - "No music library path specified. Go to settings and add it to start scanning.\n"; - console.log(warning); - - return; - } + try { + const state = await Fs.getState(stateFile); + const electronFileProtocol = "media://"; + musicLibraryPath = state?.musicLibraryPath || ""; + console.log("state", state, "\n"); + + if (!musicLibraryPath) { + const warning = + "No music library path specified. Go to settings and add it to start scanning.\n"; + console.log(warning); + + return; + } - Normalization.init( - utilityProcess.fork, - isDevOrTest - ? path.join(__dirname, "../../musa-core/lib/normalization/worker.js") - : path.join(app.getAppPath(), "/normalization/worker.js"), - ); + Normalization.init( + utilityProcess.fork, + isDevOrTest + ? path.join(__dirname, "../../musa-core/lib/normalization/worker.js") + : path.join(app.getAppPath(), "/normalization/worker.js"), + ); - await createApi(musicLibraryPath, electronFileProtocol); + await createApi(musicLibraryPath, electronFileProtocol); - Db.init(musicLibraryPath); + Db.init(musicLibraryPath); - await Scanner.init({ - musicLibraryPath, - isElectron: true, - electronFileProtocol, - }); + await Scanner.init({ + musicLibraryPath, + isElectron: true, + electronFileProtocol, + }); - event.sender.send("musa:ready"); + event.sender.send("musa:ready"); - Scanner.update({ musicLibraryPath, event, scanColor }); + Scanner.update({ musicLibraryPath, event, scanColor }); + } catch (error) { + console.error("Crashed during startup", error); + } }; ipc.handle("onInit", init);