index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const { initRemix } = require("remix-electron")
  2. const { app, BrowserWindow, dialog } = require("electron")
  3. const path = require("node:path")
  4. /** @type {BrowserWindow | undefined} */
  5. let win
  6. /** @param {string} url */
  7. async function createWindow(url) {
  8. win = new BrowserWindow({ show: false })
  9. await win.loadURL(url)
  10. win.show()
  11. if (process.env.NODE_ENV === "development") {
  12. win.webContents.openDevTools()
  13. }
  14. }
  15. app.on("ready", () => {
  16. void (async () => {
  17. try {
  18. if (process.env.NODE_ENV === "development") {
  19. const {
  20. default: installExtension,
  21. REACT_DEVELOPER_TOOLS,
  22. } = require("electron-devtools-installer")
  23. await installExtension(REACT_DEVELOPER_TOOLS)
  24. }
  25. const url = await initRemix({
  26. serverBuild: path.join(__dirname, "../build/index.js"),
  27. })
  28. await createWindow(url)
  29. } catch (error) {
  30. dialog.showErrorBox("Error", getErrorStack(error))
  31. console.error(error)
  32. }
  33. })()
  34. })
  35. /** @param {unknown} error */
  36. function getErrorStack(error) {
  37. return error instanceof Error ? error.stack || error.message : String(error)
  38. }