Skip to content

Commit

Permalink
Add trycatch to startup
Browse files Browse the repository at this point in the history
  • Loading branch information
miikaah committed Jul 26, 2024
1 parent c7be901 commit b767058
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit b767058

Please sign in to comment.