Skip to content

Commit

Permalink
Saving windows position
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric committed Nov 2, 2018
1 parent 59870a6 commit dd74afa
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 14 deletions.
90 changes: 81 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"color": "3.1.0",
"color-blind": "^0.1.1",
"electron-log": "^2.2.17",
"electron-store": "^2.0.0",
"electron-updater": "3.0.4",
"focus-visible": "^4.1.5",
"robotjs": "git+https:/toinane/robotjs.git"
Expand Down
11 changes: 7 additions & 4 deletions src/browsers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@ module.exports = (dirname) => {

/**
* [init]
* @param {int} x [initial window x position]
* @param {int} Y [initial window y position]
* @param {boolean} force [force launching new window]
* @return {void} [new Colorpicker]
*/
let init = (force, color) => {
if (mainWindow === null || mainWindow === undefined || force) createWindow()
let init = (x, y, force) => {
if (mainWindow === null || mainWindow === undefined || force) createWindow(x, y)
else mainWindow.show()
}

let createWindow = () => {
let createWindow = (x, y) => {
// Create the browser window.
mainWindow = new BrowserWindow({
show: false, // Hide the application until the page has loaded
width: 480,
height: 0,
x: x,
y: y,
alwaysOnTop: true,
resizable: false,
focusable: true,
Expand Down
15 changes: 14 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
const { app, Menu } = require('electron')
const isDev = ('NODE_ENV' in process.env && process.env.NODE_ENV === 'dev')
const Store = require('electron-store');
const store = new Store();

const { checkForUpdates, installUpdate } = require('./update.js')

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', () => {
main.init()

x = store.get('main.position.x', null)
y = store.get('main.position.y', null)
main.init(x, y)

const menuTemplate = [
{
Expand Down Expand Up @@ -145,6 +150,14 @@ app.on('activate', () => {
main.init()
})

app.on('before-quit', () => {
// Save last position
pos = main.getWindow().getPosition()
console.log(pos)
store.set('main.position.x', pos[0])
store.set('main.position.y', pos[1])
})

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

Expand Down

0 comments on commit dd74afa

Please sign in to comment.