Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

Commit

Permalink
Restore window size and position. Fixes #224.
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad-shatskyi committed May 30, 2016
1 parent 4d9d869 commit 910db23
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/views/1_ApplicationComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {ipcRenderer} from "electron";
import {KeyCode} from "../Enums";
import {remote} from "electron";
import * as css from "./css/main";
import {restoreWindowBounds, saveWindowBounds} from "./ViewUtils";

interface State {
sessions: Session[];
Expand All @@ -18,21 +19,31 @@ export default class ApplicationComponent extends React.Component<{}, State> {

constructor(props: {}) {
super(props);
const focusedWindow = remote.BrowserWindow.getFocusedWindow();

restoreWindowBounds(focusedWindow);

this.addTab();
this.state = {sessions: this.activeTab.sessions};

$(window).resize(() => {
for (const tab of this.tabs) {
tab.updateAllSessionsDimensions();
}
});
focusedWindow
.on("move", () => saveWindowBounds(focusedWindow))
.on("resize", () => {
saveWindowBounds(focusedWindow);

for (const tab of this.tabs) {
tab.updateAllSessionsDimensions();
}
});

ipcRenderer.on("change-working-directory", (event: Electron.IpcRendererEvent, directory: string) =>
this.activeTab.activeSession().directory = directory
);

window.onbeforeunload = () => this.closeAllTabs();
window.onbeforeunload = () => {
focusedWindow.removeAllListeners();
this.closeAllTabs();
}
}

handleKeyDown(event: KeyboardEvent) {
Expand Down
16 changes: 16 additions & 0 deletions src/views/ViewUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,19 @@ export function getCaretPosition(element: any): number {
}
return caretOffset;
}

const windowBoundsKey = "windowBounds";

export function saveWindowBounds(browserWindow: Electron.BrowserWindow) {
const bounds = browserWindow.getBounds();

localStorage.setItem(windowBoundsKey, JSON.stringify(bounds));
}

export function restoreWindowBounds(browserWindow: Electron.BrowserWindow) {
const windowBounds: Electron.Rectangle = JSON.parse(localStorage.getItem(windowBoundsKey));

if (windowBounds) {
browserWindow.setBounds(windowBounds);
}
}

0 comments on commit 910db23

Please sign in to comment.