mirror of
https://github.com/heyman/heynote.git
synced 2024-11-21 15:33:14 +01:00
Add "Always on top" setting which makes Heynote stay on top of other programs
This commit is contained in:
parent
a7e0f53c35
commit
2f22951e9f
@ -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
|
||||
@ -67,6 +68,7 @@ const defaults = {
|
||||
bufferPath: "",
|
||||
showInDock: true,
|
||||
showInMenu: false,
|
||||
alwaysOnTop: false,
|
||||
bracketClosing: false,
|
||||
},
|
||||
theme: "system",
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
@ -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", () => {
|
||||
@ -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)
|
||||
@ -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()) {
|
||||
|
@ -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,
|
||||
@ -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,
|
||||
@ -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"
|
||||
@ -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">
|
||||
|
Loading…
Reference in New Issue
Block a user