Skip to content

Commit

Permalink
fix(main): split process and it works
Browse files Browse the repository at this point in the history
chore: edit comments

Signed-off-by: kash / Hytus <[email protected]>
  • Loading branch information
KashEight committed Oct 28, 2023
1 parent 1b098b7 commit 262da2a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 27 deletions.
2 changes: 2 additions & 0 deletions src/assets/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import "./style.css"

// ? Handlers in index.heml is not working correctly (it might be an effect of webpack?)

const launcherConfig = {
launcherVersion: "1.0", // TODO: should come from package.json
gameLaunchPossible: true, // TODO: unimplemented
Expand Down
4 changes: 2 additions & 2 deletions src/installlocators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { lstat, readFile, readdir } from "node:fs/promises"
import path from "node:path"

import drivelist from "drivelist"
import { list } from "drivelist"
import regedit from "winreg"

// TODO: refactor
Expand Down Expand Up @@ -47,7 +47,7 @@ function locateSteamInstall() {
}

async function locateMsStoreInstall(): Promise<string> {
const drives = await drivelist.list()
const drives = await list()
const mountPaths = drives
.filter((drive) => drive.isSystem)
.flatMap((drive) => drive.mountpoints)
Expand Down
51 changes: 28 additions & 23 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,34 @@ function createWindow() {

// () => app.enableSandbox()

function init() {
ipcMain.on("launch-game", handleLaunchGame)
ipcMain.on("install-mods", (event, packagePaths) =>
installAllPackages(packagePaths, false)
)
ipcMain.on(
"set-config-value",
async <T extends MMLConfigKeyType>(
_: IpcMainEvent,
key: T,
value: MMLConfigType[T]
) => {
await config.setConfigValue(key, value)
}
)
ipcMain.handle(
"get-config-value",
<T extends MMLConfigKeyType>(_: IpcMainInvokeEvent, key: T) => {
return config.getConfigValue(key)
}
)
createWindow()
}

app.whenReady().then(() => {
init()
})

app.on("ready", () => {
const installPackagesPaths = process.argv
.slice(1)
Expand All @@ -79,29 +107,6 @@ app.on("ready", () => {

if (installPackagesPaths.length > 0) {
installAllPackages(installPackagesPaths, true)
} else {
ipcMain.on("launch-game", handleLaunchGame)
ipcMain.on("install-mods", (event, packagePaths) =>
installAllPackages(packagePaths, false)
)
ipcMain.on(
"set-config-value",
async <T extends MMLConfigKeyType>(
_: IpcMainEvent,
key: T,
value: MMLConfigType[T]
) => {
await config.setConfigValue(key, value)
}
)
ipcMain.handle(
"get-config-value",
<T extends MMLConfigKeyType>(_: IpcMainInvokeEvent, key: T) => {
return config.getConfigValue(key)
}
)

createWindow()
}
})

Expand Down
1 change: 0 additions & 1 deletion src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { MMLConfigKeyType, MMLConfigType } from "./types/config"
// import { ILP_getInstalledMods } from "./installedlistpopulator"

// TODO: refactor
// TODO: fix not exposing keys (use ipc instead)

// contextBridge.exposeInMainWorld("installedpopulator", ILP_getInstalledMods)
contextBridge.exposeInMainWorld("moolah", {
Expand Down
2 changes: 1 addition & 1 deletion webpack.renderer.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { rendererRules } from "./webpack.rules"
const rendererConfig: Configuration = {
// XXX: should add `optimization` key for production?
// XXX: should add `cache` key for developing?
devtool: "inline-source-map",
// devtool: "inline-source-map",
module: {
rules: rendererRules,
},
Expand Down

0 comments on commit 262da2a

Please sign in to comment.