diff --git a/README.md b/README.md index aa75afc..0dbf206 100644 --- a/README.md +++ b/README.md @@ -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 ``` \ No newline at end of file diff --git a/assets/close_system_tray.jpg b/assets/close_system_tray.jpg new file mode 100644 index 0000000..10e4827 Binary files /dev/null and b/assets/close_system_tray.jpg differ diff --git a/src/app.js b/src/app.js index 1cca9ae..e7bee6e 100644 --- a/src/app.js +++ b/src/app.js @@ -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 @@ -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) @@ -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!') diff --git a/src/tray.js b/src/tray.js index 6709402..92f872f 100644 --- a/src/tray.js +++ b/src/tray.js @@ -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)) @@ -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) } } diff --git a/src/win.js b/src/win.js index 154c673..5b3af76 100644 --- a/src/win.js +++ b/src/win.js @@ -5,6 +5,13 @@ const { QMainWindow, QIcon, QStackedWidget, + QMessageBox, + QPushButton, + QLabel, + QGridLayout, + QWidget, + QPixmap, + AlignmentFlag, } = require("@nodegui/nodegui") // Screens @@ -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