diff --git a/app/config.js b/app/config.js
index c60f4f3..00fe27e 100644
--- a/app/config.js
+++ b/app/config.js
@@ -9,6 +9,7 @@ module.exports = new Config({
shortcut: {
toggleApp: null
},
- mode: 'dark'
+ mode: 'dark',
+ floating: false
}
})
diff --git a/app/index.js b/app/index.js
index 89fcf51..03ae8ea 100644
--- a/app/index.js
+++ b/app/index.js
@@ -75,7 +75,12 @@ function createMainWindow() {
e.preventDefault()
if (process.platform === 'darwin') {
- app.hide()
+ if (config.get('floating')) {
+ // if app is floating, app.hide will not work
+ win.hide()
+ } else {
+ app.hide()
+ }
} else {
win.hide()
}
@@ -108,10 +113,16 @@ app.on('ready', () => {
Menu.setApplicationMenu(
createMenu({
toggleWindow
- })
+ }, app)
)
mainWindow = createMainWindow()
- tray.create(mainWindow)
+ if (config.get('floating') && process.platform === 'darwin') {
+ app.dock.hide()
+ mainWindow.setAlwaysOnTop(true, 'floating')
+ mainWindow.setVisibleOnAllWorkspaces(true)
+ mainWindow.setFullScreenable(false)
+ }
+ tray.create(mainWindow, app)
mainWindow.once('ready-to-show', () => {
mainWindow.show()
diff --git a/app/menu.js b/app/menu.js
index a682e3b..f6628c7 100644
--- a/app/menu.js
+++ b/app/menu.js
@@ -25,7 +25,7 @@ function updateMenu(opts) {
Menu.setApplicationMenu(createMenu(opts))
}
-function createMenu(opts) {
+function createMenu(opts, app) {
const toggleAppAccelerator =
config.get('shortcut.toggleApp') || 'CmdOrCtrl+Shift+D'
const toggleAppAcceleratorRegistered = globalShortcut.isRegistered(
@@ -48,6 +48,14 @@ function createMenu(opts) {
shell.openItem(configDir('custom.js'))
}
},
+ {
+ label: 'Turn On Floating Mode',
+ click() {
+ config.set('floating', true)
+ app.relaunch()
+ app.exit()
+ }
+ },
{
label: `${
toggleAppAcceleratorRegistered ? 'Disable' : 'Enable'
diff --git a/app/renderer/main.js b/app/renderer/main.js
index 8d822ed..e444f21 100644
--- a/app/renderer/main.js
+++ b/app/renderer/main.js
@@ -26,7 +26,15 @@ function ensureCustomFiles() {
function createHeader() {
const header = document.createElement('header')
header.className = 'header'
- header.innerHTML = '
Loading DevDocs...
'
+ header.innerHTML = `
+ Loading DevDocs...
+
+
+
+ `
header.addEventListener('dblclick', () => {
win.maximize()
})
@@ -34,6 +42,17 @@ function createHeader() {
webview.focus()
})
+ const pin = header.querySelector('.pin')
+ if (config.get('floating')) {
+ pin.classList.add('pinned')
+ }
+ pin.addEventListener('click', () => {
+ const app = remote.app
+ config.set('floating', !config.get('floating'))
+ app.relaunch()
+ app.exit()
+ })
+
document.body.append(header)
}
diff --git a/app/renderer/style.css b/app/renderer/style.css
index f14a32d..41596b3 100644
--- a/app/renderer/style.css
+++ b/app/renderer/style.css
@@ -72,9 +72,21 @@ body {
.header .app-title {
font-size: 12px;
font-weight: 400;
+ text-align: center;
margin: 0;
}
+.header .pin {
+ font-size: 12px;
+ margin: 0;
+ margin-left: 3px;
+ fill: #666666;
+}
+
+.header .pin.pinned {
+ fill: #2C70F4;
+}
+
.is-darwin .header {
display: flex;
}
diff --git a/app/static/tray-mac.png b/app/static/tray-mac.png
new file mode 100644
index 0000000..b5f9e35
Binary files /dev/null and b/app/static/tray-mac.png differ
diff --git a/app/static/tray-mac@2x.png b/app/static/tray-mac@2x.png
new file mode 100644
index 0000000..a28907e
Binary files /dev/null and b/app/static/tray-mac@2x.png differ
diff --git a/app/tray.js b/app/tray.js
index 3818591..007d4d8 100644
--- a/app/tray.js
+++ b/app/tray.js
@@ -1,14 +1,24 @@
const path = require('path')
const { app, Menu, Tray } = require('electron')
+const config = require('./config')
let tray = null
-exports.create = win => {
- if (process.platform === 'darwin' || tray) {
+exports.create = (win, app) => {
+ if (tray) {
return
}
- const iconPath = path.join(__dirname, 'static/tray.png')
+ let iconPath;
+ if (process.platform === 'darwin') {
+ if (config.get('floating')) {
+ iconPath = path.join(__dirname, 'static/tray-mac.png')
+ } else {
+ return
+ }
+ } else {
+ iconPath = path.join(__dirname, 'static/tray.png')
+ }
const toggleWin = () => {
if (win.isVisible()) {
@@ -18,13 +28,27 @@ exports.create = win => {
}
}
- const contextMenu = Menu.buildFromTemplate([
+ let menuItems = [
{
- label: 'Toggle',
+ label: 'Toggle Window',
click() {
toggleWin()
}
- },
+ }
+ ];
+ if (process.platform === 'darwin') {
+ menuItems = menuItems.concat([
+ {
+ label: 'Turn Off Floating Mode',
+ click() {
+ config.set('floating', false)
+ app.relaunch()
+ app.exit()
+ }
+ },
+ ])
+ }
+ menuItems = menuItems.concat([
{
type: 'separator'
},
@@ -33,6 +57,8 @@ exports.create = win => {
}
])
+ const contextMenu = Menu.buildFromTemplate(menuItems)
+
tray = new Tray(iconPath)
tray.setToolTip(`${app.getName()}`)
tray.setContextMenu(contextMenu)