Skip to content

Commit

Permalink
Add "Always on top" setting which makes Heynote stay on top of other …
Browse files Browse the repository at this point in the history
…programs
  • Loading branch information
heyman committed Feb 9, 2024
1 parent a7e0f53 commit 2f22951
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
2 changes: 2 additions & 0 deletions electron/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const schema = {
"bufferPath" : {type: "string", default: ""},
"showInDock": {type: "boolean", default: true},
"showInMenu": {type: "boolean", default: false},
"alwaysOnTop": {type: "boolean", default: false},
"bracketClosing": {type: "boolean", default: false},

// when default font settings are used, fontFamily and fontSize is not specified in the
Expand Down Expand Up @@ -67,6 +68,7 @@ const defaults = {
bufferPath: "",
showInDock: true,
showInMenu: false,
alwaysOnTop: false,
bracketClosing: false,
},
theme: "system",
Expand Down
37 changes: 34 additions & 3 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,18 @@ function registerGlobalHotkey() {
return
}
if (win.isFocused()) {
if (!!app.hide) {
if (isMac) {
// app.hide() only available on macOS
// We want to use app.hide() so that the menu bar also gets changed
app?.hide()
if (CONFIG.get("settings.alwaysOnTop")) {
// if alwaysOnTop is on, calling app.hide() won't hide the window
win.hide()
}
} else {
win.blur()
if (CONFIG.get("settings.showInMenu")) {
// if we're using a tray icon we want to completely hide the window
if (CONFIG.get("settings.showInMenu") || CONFIG.get("settings.alwaysOnTop")) {
// if we're using a tray icon, or alwaysOnTop is on, we want to completely hide the window
win.hide()
}
}
Expand Down Expand Up @@ -275,11 +279,34 @@ function registerShowInMenu() {
}
}

function registerAlwaysOnTop() {
if (CONFIG.get("settings.alwaysOnTop")) {
const disableAlwaysOnTop = () => {
win.setAlwaysOnTop(true, "floating");
win.setVisibleOnAllWorkspaces(true, {visibleOnFullScreen: true});
win.setFullScreenable(false);
}
// if we're in fullscreen mode, we need to exit fullscreen before we can set alwaysOnTop
if (win.isFullScreen()) {
// on Mac setFullScreen happens asynchronously, so we need to wait for the event before we can disable alwaysOnTop
win.once("leave-full-screen", disableAlwaysOnTop)
win.setFullScreen(false)
} else {
disableAlwaysOnTop()
}
} else {
win.setAlwaysOnTop(false);
win.setVisibleOnAllWorkspaces(false);
win.setFullScreenable(true);
}
}

app.whenReady().then(createWindow).then(async () => {
initializeAutoUpdate(win)
registerGlobalHotkey()
registerShowInDock()
registerShowInMenu()
registerAlwaysOnTop()
})

app.on("before-quit", () => {
Expand Down Expand Up @@ -328,6 +355,7 @@ ipcMain.handle('settings:set', async (event, settings) => {
let showInDockChanged = settings.showInDock !== CONFIG.get("settings.showInDock");
let showInMenuChanged = settings.showInMenu !== CONFIG.get("settings.showInMenu");
let bufferPathChanged = settings.bufferPath !== CONFIG.get("settings.bufferPath");
let alwaysOnTopChanged = settings.alwaysOnTop !== CONFIG.get("settings.alwaysOnTop");
CONFIG.set("settings", settings)

win?.webContents.send(SETTINGS_CHANGE_EVENT, settings)
Expand All @@ -341,6 +369,9 @@ ipcMain.handle('settings:set', async (event, settings) => {
if (showInMenuChanged) {
registerShowInMenu()
}
if (alwaysOnTopChanged) {
registerAlwaysOnTop()
}
if (bufferPathChanged) {
const buffer = loadBuffer()
if (buffer.exists()) {
Expand Down
12 changes: 11 additions & 1 deletion src/components/settings/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
globalHotkey: this.initialSettings.globalHotkey,
showInDock: this.initialSettings.showInDock,
showInMenu: this.initialSettings.showInMenu,
alwaysOnTop: this.initialSettings.alwaysOnTop,
bracketClosing: this.initialSettings.bracketClosing,
autoUpdate: this.initialSettings.autoUpdate,
bufferPath: this.initialSettings.bufferPath,
Expand Down Expand Up @@ -82,6 +83,7 @@
globalHotkey: this.globalHotkey,
showInDock: this.showInDock,
showInMenu: this.showInMenu || !this.showInDock,
alwaysOnTop: this.alwaysOnTop,
autoUpdate: this.autoUpdate,
bracketClosing: this.bracketClosing,
bufferPath: this.bufferPath,
Expand Down Expand Up @@ -184,7 +186,7 @@
</div>
<div class="row" v-if="!isWebApp">
<div class="entry">
<h2>Show In</h2>
<h2>Window / Application</h2>
<label v-if="isMac">
<input
type="checkbox"
Expand All @@ -207,6 +209,14 @@
Show in system tray
</template>
</label>
<label>
<input
type="checkbox"
v-model="alwaysOnTop"
@change="updateSettings"
/>
Always on top
</label>
</div>
</div>
<div class="row" v-if="!isWebApp">
Expand Down

0 comments on commit 2f22951

Please sign in to comment.