-
-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathoptions.js
More file actions
66 lines (56 loc) · 1.63 KB
/
Copy pathoptions.js
File metadata and controls
66 lines (56 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict'
function Options () {
this.electron = require('electron');
const root = document.documentElement
this.colWidth = 80
this.w = 900
this.h = 500
this.setDimensions = function () {
var window = this.electron.remote.getCurrentWindow();
const { w, h } = window.getSize()
this.w = window.getSize()[0]
this.h = window.getSize()[1]
this.updateVariables()
}
this.start = function () {
this.element = document.querySelector('textarea')
// If localStorage has information about the options,
// load the saved values and apply them
if (localStorage.getItem('options')) {
console.log(JSON.parse(localStorage.getItem('options')))
const { colWidth, w, h } = JSON.parse(localStorage.getItem('options'))
this.colWidth = colWidth
this.w = w
this.h = h
this.updateVariables()
}
}
this.setTextAreaColumns = function (size) {
this.colWidth = size
this.updateVariables()
}
// Update the CSS variables, save the values to localStorage
this.updateVariables = function () {
this.element.style.setProperty('width', `${this.colWidth}ch`)
var window = this.electron.remote.getCurrentWindow();
window.setSize(this.w, this.h)
window.center()
this.save()
}
// Save the font-related values to localStorage
this.save = function () {
localStorage.setItem('options', JSON.stringify({
colWidth: this.colWidth,
w: this.w,
h: this.h
}))
}
this.reset = function () {
localStorage.removeItem('options')
this.colWidth = 80
this.w = 900
this.h = 500
this.updateVariables()
}
}
module.exports = Options