Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
/ Orion Public archive

Feature/105 add tray icon #101

Merged
merged 7 commits into from
May 10, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function startIPFSDaemon () {
ipfsProcess.stderr.pipe(tmpLogPipe)

ipfsProcess.on('close', (exit) => {
if (exit !== 0) {
if (exit !== 0 && exit !== null) {
let msg = `IPFS Daemon was closed with exit code ${exit}. `
msg += 'The app will be closed. Try again. '
msg += `Log file: ${tmpLog.name}`
Expand Down
14 changes: 4 additions & 10 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { join as pathJoin } from 'path'
import pjson from '../package.json'
import './report'
import rootDir from 'app-root-dir'
import setupTrayIcon from './setup-tray-icon'

import {
startIPFSDaemon,
Expand Down Expand Up @@ -72,6 +73,8 @@ function askWhichNodeToUse (apiVersion) {
}

app.on('ready', () => {
setupTrayIcon()

// Ask github whether there is an update
autoUpdater.checkForUpdates()
autoUpdater.on('update-available', (info) => {
Expand Down Expand Up @@ -234,17 +237,8 @@ app.on('ready', () => {
})
})

// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})

app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// Re-create the window in the app when the
// dock icon is clicked and there are no other windows open.
if (app.mainWindow) {
app.mainWindow.once('ready-to-show', () => {
Expand Down
28 changes: 28 additions & 0 deletions app/setup-tray-icon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import path from 'path'
import { app, Menu, Tray } from 'electron'

let appIcon = null
const iconPath = path.join(__dirname, '../docs/logo.png')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use NativeImage (https://electronjs.org/docs/api/native-image#nativeimagecreatefrompathpath)
This will ensure to have the best graphics and scaled image. AFAIK


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs? Maybe? :D

function setupTrayIcon () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disable here the trayicon on macOS! There is no need for that as the app on that platform will not quit if all the windows are closed.

appIcon = new Tray(iconPath)
const contextMenu = Menu.buildFromTemplate([
{
label: 'Open Siderus Orion',
click () {
app.emit('activate')
}
},
{
label: 'Quit',
click () {
app.quit()
}
}
])

// Call this again for Linux because we modified the context menu
appIcon.setContextMenu(contextMenu)
}

export default setupTrayIcon