Skip to content

Commit

Permalink
remember window rect
Browse files Browse the repository at this point in the history
  • Loading branch information
cuteapple committed Mar 26, 2019
1 parent 50ccb1d commit 4305c5f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
1 change: 0 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ function initialize() {
})
mainWindow.setIgnoreMouseEvents(true)


for (let i of [1, 2]) {
let note = new BrowserWindow({
x: 30 + i * 100,
Expand Down
28 changes: 27 additions & 1 deletion note.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,33 @@
console.log(`note ${id} opened`)

function load() {
textContentElement.value = localStorage[id] || ''
const default_config = {
bounds: remote.getCurrentWindow().getBounds(),
content: '',
}

//TODO: proper update method (use indexdb?)
let memory = {}
memory.content = localStorage[id] || ''
try {
memory.bounds = JSON.parse(localStorage[id + '.bound'])
} catch{ }

let config = {
...default_config,
...memory
}

textContentElement.value = config.content
console.log(default_config, memory, config)
remote.getCurrentWindow().setBounds(config.bounds)
}


remote.getCurrentWindow().addListener('moved', save_bounds)
remote.getCurrentWindow().addListener('resize', save_bounds)
function save_bounds() {
localStorage[id + '.bound'] = JSON.stringify(remote.getCurrentWindow().getBounds())
}

function save() {
Expand Down

0 comments on commit 4305c5f

Please sign in to comment.