-
Notifications
You must be signed in to change notification settings - Fork 301
Bugfix/open new file after close #1246
Changes from 19 commits
bfe8b49
6931f09
9a8cefd
db94d3b
d55e250
57801c3
51ea581
79cb04f
1fb7435
ad1d62e
277e7b4
da45517
ca34523
744587f
c5a3d40
b0f534a
ce01b4c
dd544da
26bd23d
9d08ed2
b929b75
a3f4499
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,7 @@ ipcMain.on("focus-previous-instance", () => { | |
// Keep a global reference of the window object, if you don't, the window will | ||
// be closed automatically when the JavaScript object is garbage collected. | ||
let windows: BrowserWindow[] = [] | ||
let mainWindow: BrowserWindow = null | ||
let mainWindow: BrowserWindow = null | ||
|
||
// Only enable 'single-instance' mode when we're not in the hot-reload mode | ||
// Otherwise, all other open instances will also pick up the webpack bundle | ||
|
@@ -98,7 +98,16 @@ if (!isDevelopment && !isDebug) { | |
}) | ||
} | ||
|
||
export function createWindow(commandLineArguments, workingDirectory) { | ||
export interface IDelayedEvent { | ||
evt: string | ||
cmd: Array<string | string[]> | ||
} | ||
|
||
export function createWindow( | ||
commandLineArguments, | ||
workingDirectory, | ||
delayedEvent: IDelayedEvent = null, | ||
) { | ||
Log.info(`Creating window with arguments: ${commandLineArguments} and working directory: ${workingDirectory}`) | ||
const webPreferences = { | ||
blinkFeatures: "ResizeObserver,Accelerated2dCanvas,Canvas2dFixedRenderingMode", | ||
|
@@ -144,6 +153,14 @@ export function createWindow(commandLineArguments, workingDirectory) { | |
}) | ||
}) | ||
|
||
ipcMain.on("Oni.started", (evt) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at this - I'm wondering, will this be called for every window? In other words, if I'm wondering if this should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah @bryphe right on the money 👍 I had noticed this quirk yesterday and wasn't sure what it was and wracking my brain as to what to do did not realise there was a |
||
Log.info("Oni started") | ||
|
||
if (delayedEvent) { | ||
mainWindow.webContents.send(delayedEvent.evt, ...delayedEvent.cmd) | ||
} | ||
}) | ||
|
||
ipcMain.on("rebuild-menu", (_evt, loadInit) => { | ||
// ipcMain is a singleton so if there are multiple Oni instances | ||
// we may receive an event from a different instance | ||
|
@@ -180,6 +197,8 @@ export function createWindow(commandLineArguments, workingDirectory) { | |
}) | ||
|
||
windows.push(mainWindow) | ||
|
||
return mainWindow | ||
} | ||
|
||
app.on("open-file", (event, filePath) => { | ||
|
@@ -205,15 +224,12 @@ app.on("window-all-closed", () => { | |
app.on("activate", () => { | ||
// On OS X it's common to re-create a window in the app when the | ||
// dock icon is clicked and there are no other windows open. | ||
const currentWindow: BrowserWindow = windows[windows.length - 1] | ||
|
||
if (currentWindow) { | ||
currentWindow.show() | ||
} | ||
|
||
if (windows.length === 0) { | ||
if (!windows.length) { | ||
createWindow([], process.cwd()) | ||
} | ||
if (mainWindow) { | ||
mainWindow.show() | ||
} | ||
}) | ||
|
||
function updateMenu(browserWindow, loadInit) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach looks great to me - thanks @Akin909 !