Skip to content

Commit

Permalink
Settings improvements (#88)
Browse files Browse the repository at this point in the history
* Organize Settings in different tabs

* Add setting for turning off/on auto updates.

* Remove debug log

* Use a better variable name (systemTheme -> themeSetting)

* Store theme setting for Heynote webapp in local storage
  • Loading branch information
heyman authored Dec 28, 2023
1 parent 77ed45c commit 6022356
Show file tree
Hide file tree
Showing 9 changed files with 277 additions and 136 deletions.
2 changes: 2 additions & 0 deletions electron/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const schema = {
"emacsMetaKey": { "enum": [null, "alt", "meta"], default: null },
"showLineNumberGutter": {type: "boolean", default:true},
"showFoldGutter": {type: "boolean", default:true},
"autoUpdate": {type: "boolean", default: true},
"allowBetaVersions": {type: "boolean", default: false},
"enableGlobalHotkey": {type: "boolean", default: false},
"globalHotkey": {type: "string", default: "CmdOrCtrl+Shift+H"},
Expand All @@ -49,6 +50,7 @@ const defaults = {
emacsMetaKey: "meta",
showLineNumberGutter: true,
showFoldGutter: true,
autoUpdate: true,
allowBetaVersions: false,
enableGlobalHotkey: false,
globalHotkey: "CmdOrCtrl+Shift+H",
Expand Down
13 changes: 7 additions & 6 deletions src/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
languageAuto: true,
theme: window.heynote.themeMode.initial,
initialTheme: window.heynote.themeMode.initial,
systemTheme: 'system',
themeSetting: 'system',
development: window.location.href.indexOf("dev=1") !== -1,
showLanguageSelector: false,
showSettings: false,
Expand All @@ -32,7 +32,7 @@
mounted() {
window.heynote.themeMode.get().then((mode) => {
this.theme = mode.computed
this.systemTheme = mode.theme
this.themeSetting = mode.theme
})
const onThemeChange = (theme) => {
this.theme = theme
Expand Down Expand Up @@ -69,12 +69,12 @@
let newTheme
// when the "system" theme is used, make sure that the first click always results in amn actual theme change
if (this.initialTheme === "light") {
newTheme = this.systemTheme === "system" ? "dark" : (this.systemTheme === "dark" ? "light" : "system")
newTheme = this.themeSetting === "system" ? "dark" : (this.themeSetting === "dark" ? "light" : "system")
} else {
newTheme = this.systemTheme === "system" ? "light" : (this.systemTheme === "light" ? "dark" : "system")
newTheme = this.themeSetting === "system" ? "light" : (this.themeSetting === "light" ? "dark" : "system")
}
window.heynote.themeMode.set(newTheme)
this.systemTheme = newTheme
this.themeSetting = newTheme
this.$refs.editor.focus()
},
Expand Down Expand Up @@ -129,7 +129,8 @@
:language="language"
:languageAuto="languageAuto"
:theme="theme"
:systemTheme="systemTheme"
:themeSetting="themeSetting"
:autoUpdate="settings.autoUpdate"
:allowBetaVersions="settings.allowBetaVersions"
@toggleTheme="toggleTheme"
@openLanguageSelector="openLanguageSelector"
Expand Down
11 changes: 8 additions & 3 deletions src/components/StatusBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"language",
"languageAuto",
"theme",
"systemTheme",
"themeSetting",
"autoUpdate",
"allowBetaVersions",
],
Expand Down Expand Up @@ -84,9 +85,13 @@
>
<span class="icon icon-format"></span>
</div>
<UpdateStatusItem v-if="updatesEnabled" :allowBetaVersions="allowBetaVersions" />
<UpdateStatusItem
v-if="updatesEnabled"
:autoUpdate="autoUpdate"
:allowBetaVersions="allowBetaVersions"
/>
<div class="status-block theme clickable" @click="$emit('toggleTheme')" title="Toggle dark/light mode">
<span :class="'icon ' + systemTheme"></span>
<span :class="'icon ' + themeSetting"></span>
</div>
</div>
</template>
Expand Down
34 changes: 21 additions & 13 deletions src/components/UpdateStatusItem.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script>
export default {
props: [
"autoUpdate",
"allowBetaVersions",
],
Expand All @@ -16,7 +17,6 @@
total: 0.0,
bytesPerSecond: 0.0,
},
checkForUpdateIntervalId: null,
}
},
Expand Down Expand Up @@ -50,14 +50,6 @@
this.updateProgress = progress
}
})
// check for update now
this.checkForUpdate()
// check for updates every 8 hours
this.checkForUpdateIntervalId = setInterval(() => {
this.checkForUpdate()
}, 1000 * 3600 * 8)
},
beforeUnmount() {
Expand All @@ -67,11 +59,27 @@
},
watch: {
allowBetaVersions: {
handler: function (newValue) {
this.checkForUpdate()
autoUpdate: {
immediate: true,
handler(autoUpdate) {
if (this.checkForUpdateIntervalId) {
clearInterval(this.checkForUpdateIntervalId)
}
if (autoUpdate) {
// check for update now
this.checkForUpdate()
// check for updates every 8 hours
this.checkForUpdateIntervalId = setInterval(() => {
this.checkForUpdate()
}, 1000 * 3600 * 8)
}
},
}
},
allowBetaVersions(newValue) {
this.checkForUpdate()
},
},
computed: {
Expand Down
Loading

0 comments on commit 6022356

Please sign in to comment.