Skip to content

Commit

Permalink
Added System Tray Icon
Browse files Browse the repository at this point in the history
  • Loading branch information
justinforlenza committed Jan 12, 2021
1 parent 0d6fe2c commit 2579f1f
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is a basic workflow to help you get started with Actions

name: Build Binaries
name: Build

# Controls when the action will run.
on:
Expand All @@ -12,7 +12,7 @@ on:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build-linux:
linux:
# The type of runner that the job will run on
runs-on: ubuntu-latest

Expand Down
1 change: 1 addition & 0 deletions dist/assets/bulb.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dist/bulb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 57 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { QMainWindow, QWidget, QLabel, FlexLayout } = require("@nodegui/nodegui");
const { QMainWindow, QWidget, QApplication, FlexLayout, QIcon, QSystemTrayIcon, QMenu, QAction, WindowType } = require("@nodegui/nodegui");
const bonjour = require('bonjour')()
const resolve = require('path').resolve

const KeyLight = require('./keylight')

Expand Down Expand Up @@ -33,8 +34,49 @@ function createHeaderWidget() {
return headerWidget
}

function createTrayIcon() {
const icon = new QIcon(resolve(__dirname, 'bulb.png'))
const tray = new QSystemTrayIcon()
const menu = new QMenu()

const main = async () => {
tray.setIcon(icon)

tray.addEventListener('activated', () => {
global.win.show()
})

tray.setContextMenu(menu)

const quitAction = new QAction()
quitAction.setText('Quit')

quitAction.addEventListener('triggered', () => {
process.exit(22)
})

menu.addAction(quitAction)

const toggleAction = new QAction()
toggleAction.setText('Show/Hide')

toggleAction.addEventListener('triggered', () => {
if (global.win.isVisible()) {
global.win.hide();
} else {
global.win.show();
}
})

menu.addAction(toggleAction)

tray.show()


global.tray = tray
}


function createMainWindow () {
const win = new QMainWindow()


Expand All @@ -56,12 +98,21 @@ const main = async () => {
view.layout.addWidget(keyLight.widget)
})

win.setCentralWidget(view)


win.setCentralWidget(view);
win.show()
win.setWindowFlag(WindowType.WindowMinimizeButtonHint, false)

global.win = win
}

main().catch(console.error)

function main() {
global.app = QApplication.instance()
global.app.setQuitOnLastWindowClosed(false)

createTrayIcon()
createMainWindow()
}


main()
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"@nodegui/nodegui": "^0.25.0",
"axios": "^0.21.1",
"bonjour": "^3.5.0",
"lodash": "^4.17.20"
"lodash": "^4.17.20",
"resolve": "^1.19.0"
},
"devDependencies": {
"@nodegui/packer": "^1.4.1"
Expand Down
20 changes: 20 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,13 @@ is-callable@^1.1.4, is-callable@^1.2.2:
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.2.tgz#c7c6715cd22d4ddb48d3e19970223aceabb080d9"
integrity sha512-dnMqspv5nU3LoewK2N/y7KLtxtakvTuaCsU9FU50/QDmdbHNy/4/JuRtMHqRU22o3q+W89YQndQEeCVwK+3qrA==

is-core-module@^2.1.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.2.0.tgz#97037ef3d52224d85163f5597b2b63d9afed981a"
integrity sha512-XRAfAdyyY5F5cOXn7hYQDqh2Xmii+DEfIcQGxK/uNwMHhIkPWO0g8msXcbzLe+MpGoR951MlqM/2iIlU4vKDdQ==
dependencies:
has "^1.0.3"

is-date-object@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/is-date-object/-/is-date-object-1.0.2.tgz#bda736f2cd8fd06d32844e7743bfa7494c3bfd7e"
Expand Down Expand Up @@ -1147,6 +1154,11 @@ path-key@^3.1.0:
resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375"
integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==

path-parse@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c"
integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==

performance-now@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
Expand Down Expand Up @@ -1325,6 +1337,14 @@ request@^2.54.0:
tunnel-agent "^0.6.0"
uuid "^3.3.2"

resolve@^1.19.0:
version "1.19.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.19.0.tgz#1af5bf630409734a067cae29318aac7fa29a267c"
integrity sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==
dependencies:
is-core-module "^2.1.0"
path-parse "^1.0.6"

rimraf@2:
version "2.7.1"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.7.1.tgz#35797f13a7fdadc566142c29d4f07ccad483e3ec"
Expand Down

0 comments on commit 2579f1f

Please sign in to comment.