Skip to content

Commit

Permalink
feat: inform on first time use that the program will run in the backg…
Browse files Browse the repository at this point in the history
…round (#20)

Add information about the application running in the background when
clicking on the cross and how to definitely stop the application.

Also improve the reduce action to show and hide the app.
  • Loading branch information
rllola authored Jul 14, 2024
1 parent 9371f18 commit f62bd1a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 14 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ This is the Graphic User Interface for the Dogecoin SPV wallet. It is built usin

```
$ NETWORK=testnet DEV=true DEBUG=* npm start
```

Or with nodemon (this allow automatic reloading developing)

```
$ NETWORK=regtest DEV=true DEBUG="*,-nodemon:*" npm run dev
```
Binary file added assets/close_system_tray.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 20 additions & 4 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ async function app (args) {
fs.mkdirSync(path.join(settings.DATA_FOLDER, 'wallet'))
}

// detect if first use
const firstUse = !fs.existsSync(path.join(settings.DATA_FOLDER, '..', '.firstuse'))

if (firstUse) {
fs.writeFileSync(path.join(settings.DATA_FOLDER, '..', '.firstuse'), "")
}

const SEED_FILE = path.join(settings.DATA_FOLDER, 'seed.json')

// Will be needed in the interface
Expand Down Expand Up @@ -120,8 +127,19 @@ async function app (args) {
}

// Create interface with nodegui
const ui = new Win(store, {getAddress, sendTransaction})
const tray = new Tray(shutdown)
const ui = new Win(store, {getAddress, sendTransaction, firstUse})

const reopen = () => {
if (ui.isMinimized()) {
// if minimize we try to show it
ui.activateWindow()
return
}

ui.show()
}

const tray = new Tray(shutdown, reopen)

// Create Wallet
const wallet = new Wallet(settings)
Expand All @@ -143,8 +161,6 @@ async function app (args) {

// Initiate wallet
await wallet.init()
// show main screen
ui.showMainScreen()

wallet.on('balance', function () {
debug('BALANCE UPDATED!')
Expand Down
12 changes: 10 additions & 2 deletions src/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const path = require("path")
const iconWhite = typeof __webpack_require__ === 'function' ? "./assets/logo_white.png" : "../assets/logo_white.png"

class Tray extends QSystemTrayIcon {
constructor(shutdown) {
constructor(shutdown, reopen) {
super()

const trayIcon = new QIcon(path.resolve(__dirname, iconWhite))
Expand All @@ -27,10 +27,18 @@ class Tray extends QSystemTrayIcon {
// -------------------
const quitAction = new QAction()
quitAction.setText("Quit")
quitAction.setIcon(trayIcon)
quitAction.addEventListener("triggered", shutdown)

// -------------------
// Reopen Action
// -------------------
const reopenAction = new QAction()
reopenAction.setText("Open")
reopenAction.addEventListener("triggered", reopen)


menu.addAction(quitAction)
menu.addAction(reopenAction)

}
}
Expand Down
41 changes: 33 additions & 8 deletions src/win.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ const {
QMainWindow,
QIcon,
QStackedWidget,
QMessageBox,
QPushButton,
QLabel,
QGridLayout,
QWidget,
QPixmap,
AlignmentFlag,
} = require("@nodegui/nodegui")

// Screens
Expand Down Expand Up @@ -87,17 +94,35 @@ class Win extends QMainWindow {

this.viewManager = viewManager

if (opts.firstUse) {
// if we are using the app for the first time we show a dialog box to inform that the app is not being really closing
this.addEventListener('Close', () => {
console.log('clicked on closed')

const messageBox = new QMessageBox()
messageBox.setWindowTitle('Deadbrain Wallet')
messageBox.setText('Clicking on the cross doesn\'t leave the app. The app will run in the background. To fully close the app you can use the system tray icon.')

const layout = messageBox.layout()

const label = new QLabel()
const image = new QPixmap('./assets/close_system_tray.jpg')
label.setInlineStyle('margin: 20px;')

label.setPixmap(image)
layout.addWidget(label, 1, 0, 1, 0, AlignmentFlag.AlignHCenter)

const button = new QPushButton()
button.setText('Got it')
messageBox.addButton(button, button.AcceptRole)
messageBox.exec()
})

}

const qApp = QApplication.instance()
qApp.setQuitOnLastWindowClosed(false) // required so that app doesnt close if we close all windows.
}

showMnemonicScreen (mnemonic) {
console.log(mnemonic)
}

showMainScreen () {
console.log('show main screen')
}
}

module.exports = Win

0 comments on commit f62bd1a

Please sign in to comment.