Skip to content

Commit

Permalink
fix: fix open file directly at first time on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
purocean committed Sep 21, 2023
1 parent 546a77f commit 6fb1fb8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const isLinux = os.platform() === 'linux'

let urlMode: 'scheme' | 'dev' | 'prod' = 'scheme'
let skipBeforeUnloadCheck = false
let macOpenFilePath = ''

const trayEnabled = !(yargs.argv['disable-tray'])
const backendPort = Number(yargs.argv.port) || config.get('server.port', 3044)
Expand Down Expand Up @@ -247,13 +248,16 @@ const createWindow = () => {
restoreWindowBounds()
win.once('ready-to-show', () => {
// open file from argv
const filePath = getOpenFilePathFromArgv(process.argv)
const filePath = macOpenFilePath || getOpenFilePathFromArgv(process.argv)
if (filePath) {
win?.show()
tryOpenFile(filePath)
return
}

// reset macOpenFilePath
macOpenFilePath = ''

// hide window on startup
if (!config.get('hide-main-window-on-startup', false)) {
hideWindow()
Expand Down Expand Up @@ -528,7 +532,12 @@ if (!gotTheLock) {

app.on('open-file', (e, path) => {
e.preventDefault()
tryOpenFile(path)

if (!win || win.webContents.isLoading()) {
macOpenFilePath = path
} else {
tryOpenFile(path)
}
})

app.on('ready', () => {
Expand Down

1 comment on commit 6fb1fb8

@vercel
Copy link

@vercel vercel bot commented on 6fb1fb8 Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.