Skip to content

Commit

Permalink
fix: window will close if renderer is not running (#22)
Browse files Browse the repository at this point in the history
* fix: window will close if no app is running
  • Loading branch information
Kinerius authored Dec 21, 2021
1 parent 2fd6ee9 commit a4a31a6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
12 changes: 8 additions & 4 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ if (getOSName() === null) {
exit(1)
}

let isRendererOpen = false
let isExitAllowed = false
let rendererPath = `${app.getPath('appData')}/decentraland/renderer/`
let executablePath = `/unity-renderer-${osName}`
let versionPath = `/version.json`
const baseUrl = `https://renderer-artifacts.decentraland.org/desktop/`
const artifactUrl = `/unity-renderer-${osName}.zip`
const remoteVersionUrl = `/version.json`
let tray: Tray | null = null;
let tray: Tray | null = null
let contextMenu: Menu | undefined = undefined

if (getOSName() === 'windows') {
rendererPath = rendererPath.replace(/\//gi, '\\')
Expand Down Expand Up @@ -129,7 +131,7 @@ const hideWindowInTray = (win: BrowserWindow) => {
try {
tray = new Tray(iconPath)

const contextMenu = Menu.buildFromTemplate([
contextMenu = Menu.buildFromTemplate([
{
label: 'Exit',
accelerator: 'CmdOrCtrl+Q',
Expand Down Expand Up @@ -167,17 +169,19 @@ const startApp = async (): Promise<void> => {

const win = await createWindow()

ipcMain.on('checkVersion', async (event) => {
ipcMain.on('process-terminated', async (event) => {
isRendererOpen = false
showWindowAndHideTray(win)
})

ipcMain.on('executeProcess', (event) => {
isRendererOpen = true
hideWindowInTray(win)
})

win.on('close', (event: { preventDefault: () => void }) => {
// this prevents the launcher from closing when using the X button on the window
if (!isExitAllowed) {
if (!isExitAllowed && isRendererOpen) {
hideWindowInTray(win)
event.preventDefault();
}
Expand Down
8 changes: 4 additions & 4 deletions electron/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ const registerVersionEvent = (rendererPath: string, versionPath: string, baseUrl

if (validVersion) {
event.sender.executeJavaScript(
`globalThis.ROLLOUTS['@dcl/unity-renderer']['version'] = \"desktop-${
globalConfig.desktopBranch
`globalThis.ROLLOUTS['@dcl/unity-renderer']['version'] = \"desktop-${globalConfig.desktopBranch
}.commit-${globalConfig.remoteVersion.substr(0, 7)}\";`
)
}
Expand All @@ -71,7 +70,8 @@ const registerExecuteProcessEvent = (rendererPath: string, executablePath: strin
return
}

console.log(data.toString())
console.log("Process terminated - " + data.toString())
ipcMain.emit("process-terminated");
}

let path = rendererPath + getBranchName() + executablePath
Expand All @@ -82,7 +82,7 @@ const registerExecuteProcessEvent = (rendererPath: string, executablePath: strin

if (getOSName() === 'mac') {
const { exec } = require('child_process')
exec('open "' + path + '" --args' + extraParams, onExecute)
exec('open -W "' + path + '" --args' + extraParams, onExecute)
} else {
const { exec } = require('child_process')
exec(path + extraParams, onExecute)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dcl/explorer-desktop-launcher",
"version": "0.1.13",
"version": "0.1.14",
"author": "decentraland",
"description": "Decentraland Desktop Launcher",
"homepage": ".",
Expand Down Expand Up @@ -100,4 +100,4 @@
"last 1 safari version"
]
}
}
}

0 comments on commit a4a31a6

Please sign in to comment.