Skip to content

Commit

Permalink
refactor: Switched back to CommonJS modules
Browse files Browse the repository at this point in the history
  • Loading branch information
elyukai committed Oct 12, 2020
1 parent ab8e5ed commit 13921f0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
31 changes: 28 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { isUpdaterEnabled } from "./App/Utilities/CheckForUpdatesMain"
import { existsFile } from "./System/IO"

app.setAppUserModelId ("lukasobermann.optolith")
app.allowRendererProcessReuse = false

const setDerivedUserDataPath = async () => {
const isPrerelease = prerelease (app.getVersion ()) !== null
Expand All @@ -26,12 +25,16 @@ const setDerivedUserDataPath = async () => {
}

const createWindow = async () => {
console.log ("main (window): Initialize window state keeper")

const mainWindowState = windowStateKeeper ({
defaultHeight: 720,
defaultWidth: 1280,
file: "window.json",
})

console.log ("main (window): Initialize browser window")

const mainWindow = new BrowserWindow ({
x: mainWindowState.x,
y: mainWindowState.y,
Expand All @@ -49,13 +52,18 @@ const createWindow = async () => {
show: false,
webPreferences: {
nodeIntegration: true,
preload: path.join (app.getAppPath (), "app", "esmPreload.js"),
// preload: path.join (app.getAppPath (), "app", "esmPreload.js"),
enableRemoteModule: true,
},
})

console.log ("main (window): Manage browser window with state keeper")

mainWindowState.manage (mainWindow)

try {
console.log ("main (window): Load url")

await mainWindow.loadURL (url.format ({
pathname: path.join (__dirname, "index.html"),
protocol: "file:",
Expand All @@ -64,22 +72,32 @@ const createWindow = async () => {

// mainWindow.webContents.openDevTools ()

console.log ("main (window): Show window")

mainWindow.show ()

if (mainWindowState.isMaximized) {
console.log ("main (window): Maximize window ...")

mainWindow.maximize ()
}

ipcMain.addListener ("loading-done", () => {
let cancellationToken: CancellationToken | undefined = undefined

if (isUpdaterEnabled ()) {
console.log ("main: Updater is enabled, check for updates ...")

autoUpdater
.checkForUpdates ()
.then (res => {
if (res.cancellationToken !== undefined) {
if (res.cancellationToken === undefined) {
console.log ("main: No update available")
}
else {
const { cancellationToken: token } = res
cancellationToken = token
console.log ("main: Update is available")
mainWindow.webContents.send ("update-available", res.updateInfo)
}
})
Expand Down Expand Up @@ -125,6 +143,9 @@ const createWindow = async () => {
autoUpdater.quitAndInstall ()
})
}
else {
console.log ("main: Updater is not available")
}
})
}
catch (err) {
Expand All @@ -138,14 +159,18 @@ const main = () => {
autoUpdater.logger.transports.file.level = "info"
autoUpdater.autoDownload = false

console.log ("main: Install development extensions ...")
// install dev extensions
const edi = require ("electron-devtools-installer")
edi.default ([
edi.REACT_DEVELOPER_TOOLS,
edi.REDUX_DEVTOOLS,
])

console.log ("main: Set user data path ...")

setDerivedUserDataPath ()
.then (() => console.log ("main: Create Window ..."))
.then (createWindow)
.then (() => {
app.on ("window-all-closed", () => {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"importHelpers": true,
"jsx": "react",
"lib": ["esnext", "dom"],
"module": "ES2020",
"module": "CommonJS",
"moduleResolution": "node",
"noEmitHelpers": true,
"noFallthroughCasesInSwitch": true,
Expand Down

0 comments on commit 13921f0

Please sign in to comment.