Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Bugfix/open new file after close #1246

Merged
merged 22 commits into from
Jan 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions browser/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ const start = async (args: string[]): Promise<void> => {
checkForUpdates()

Performance.endMeasure("Oni.Start")
ipcRenderer.send("Oni.started", "started")
Copy link
Member

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 !

}

ipcRenderer.on("init", (_evt: any, message: any) => {
Expand Down
34 changes: 25 additions & 9 deletions main/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -144,6 +153,14 @@ export function createWindow(commandLineArguments, workingDirectory) {
})
})

ipcMain.once("Oni.started", (evt) => {
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
Expand Down Expand Up @@ -180,6 +197,8 @@ export function createWindow(commandLineArguments, workingDirectory) {
})

windows.push(mainWindow)

return mainWindow
}

app.on("open-file", (event, filePath) => {
Expand All @@ -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) {
Expand Down
Loading