From 5c8585de975325b2f5e352dfae95eb016322cc6b Mon Sep 17 00:00:00 2001 From: Quentin Goinaud Date: Thu, 28 Jun 2018 17:13:46 +0200 Subject: [PATCH 1/7] preliminary work --- main.js | 43 ++++++++++++++++++++++++++++++++++++++++--- package.json | 4 +++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/main.js b/main.js index 7e65562..ae010e4 100644 --- a/main.js +++ b/main.js @@ -2,6 +2,8 @@ const electron = require('electron'); const path = require('path'); const url = require('url'); +const notifier = require('node-notifier'); +const {ipcMain} = require('electron') const windowStateKeeper = require('electron-window-state'); const {app, BrowserWindow, Menu, MenuItem} = electron; @@ -21,8 +23,39 @@ function createWindow () { width: mainWindowState.width, height: mainWindowState.height, title: app.getName(), - icon: path.join(__dirname, '/icons/png/512.png') - } + icon: path.join(__dirname, '/icons/png/512.png'), + webPreferences: { + // Load `electron-notification-shim` in rendering view. + preload: path.join(__dirname, 'browser.js') + } + } + + ipcMain.on('notification-shim', (e, msg) => { + console.log(JSON.stringify(msg)); + console.log(`Title: ${msg.title}, Body: ${msg.options.body}`); + notifier.notify( + { + title: msg.title, + subtitle: "", + message: msg.options.body, + sound: false, // Case Sensitive string for location of sound file, or use one of macOS' native sounds (see below) + icon: 'Terminal Icon', // Absolute Path to Triggering Icon + // contentImage: "", // Absolute Path to Attached Image (Content Image) + // open: void 0, // URL to open on Click + // wait: false, // Wait for User Action against Notification or times out. Same as timeout = 5 seconds + + // New in latest version. See `example/macInput.js` for usage + // timeout: 5, // Takes precedence over wait if both are defined. + closeLabel: "Close", // String. Label for cancel button + actions: ["Reply", "Mark as read"], // String | Array. Action label or list of labels in case of dropdown + // dropdownLabel: void 0, // String. Label to be used if multiple actions + reply: true // Boolean. If notification should take input. Value passed as third argument in callback and event emitter. + }, + function(error, response, metadata) { + console.log(response, metadata); + } + ); + }); mainWindow = new BrowserWindow(windowOptions) //mainWindow.webContents.openDevTools(); @@ -32,7 +65,11 @@ function createWindow () { pathname: path.join('messages.android.com'), protocol: 'https:', slashes: true - })) + })) + + mainWindow.webContents.on('did-finish-load', () => { + mainWindow.webContents.executeJavaScript('new Notification("Hello!", {body: "Notification world!"})'); + }); //When a SMS arrived in the app, change the badge if (process.platform === 'darwin') { diff --git a/package.json b/package.json index 475bdef..075d341 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,8 @@ }, "dependencies": { "electron-context-menu": "^0.10.0", - "electron-window-state": "^4.1.1" + "electron-notification-shim": "^1.1.0", + "electron-window-state": "^4.1.1", + "node-notifier": "^5.2.1" } } From 017c8858569b9c0b8564164b93535599cfdf9653 Mon Sep 17 00:00:00 2001 From: Antoine Guilbert Date: Thu, 28 Jun 2018 19:29:14 +0200 Subject: [PATCH 2/7] Add screenshot --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 2bd3d79..a54aea0 100755 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ Just a simple project made with electron JS to show Android Messages from Google To download the latest version, go to [release page](https://github.com/antoineguilbert/android-messages-for-desktop/releases). +![android-messages-macos](https://user-images.githubusercontent.com/16510381/42050509-71cc3c3a-7b09-11e8-8af2-419593ac033a.jpg) + + ## Todo - [ ] Add custom notification with only the app icon From ae73522a59ce0faa94f80a08bc73f584273dfad0 Mon Sep 17 00:00:00 2001 From: Quentin Goinaud Date: Thu, 28 Jun 2018 19:37:47 +0200 Subject: [PATCH 3/7] Revert "WIP: Custom notification support" --- main.js | 43 +++---------------------------------------- package.json | 4 +--- 2 files changed, 4 insertions(+), 43 deletions(-) diff --git a/main.js b/main.js index ae010e4..7e65562 100644 --- a/main.js +++ b/main.js @@ -2,8 +2,6 @@ const electron = require('electron'); const path = require('path'); const url = require('url'); -const notifier = require('node-notifier'); -const {ipcMain} = require('electron') const windowStateKeeper = require('electron-window-state'); const {app, BrowserWindow, Menu, MenuItem} = electron; @@ -23,39 +21,8 @@ function createWindow () { width: mainWindowState.width, height: mainWindowState.height, title: app.getName(), - icon: path.join(__dirname, '/icons/png/512.png'), - webPreferences: { - // Load `electron-notification-shim` in rendering view. - preload: path.join(__dirname, 'browser.js') - } - } - - ipcMain.on('notification-shim', (e, msg) => { - console.log(JSON.stringify(msg)); - console.log(`Title: ${msg.title}, Body: ${msg.options.body}`); - notifier.notify( - { - title: msg.title, - subtitle: "", - message: msg.options.body, - sound: false, // Case Sensitive string for location of sound file, or use one of macOS' native sounds (see below) - icon: 'Terminal Icon', // Absolute Path to Triggering Icon - // contentImage: "", // Absolute Path to Attached Image (Content Image) - // open: void 0, // URL to open on Click - // wait: false, // Wait for User Action against Notification or times out. Same as timeout = 5 seconds - - // New in latest version. See `example/macInput.js` for usage - // timeout: 5, // Takes precedence over wait if both are defined. - closeLabel: "Close", // String. Label for cancel button - actions: ["Reply", "Mark as read"], // String | Array. Action label or list of labels in case of dropdown - // dropdownLabel: void 0, // String. Label to be used if multiple actions - reply: true // Boolean. If notification should take input. Value passed as third argument in callback and event emitter. - }, - function(error, response, metadata) { - console.log(response, metadata); - } - ); - }); + icon: path.join(__dirname, '/icons/png/512.png') + } mainWindow = new BrowserWindow(windowOptions) //mainWindow.webContents.openDevTools(); @@ -65,11 +32,7 @@ function createWindow () { pathname: path.join('messages.android.com'), protocol: 'https:', slashes: true - })) - - mainWindow.webContents.on('did-finish-load', () => { - mainWindow.webContents.executeJavaScript('new Notification("Hello!", {body: "Notification world!"})'); - }); + })) //When a SMS arrived in the app, change the badge if (process.platform === 'darwin') { diff --git a/package.json b/package.json index 075d341..475bdef 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,6 @@ }, "dependencies": { "electron-context-menu": "^0.10.0", - "electron-notification-shim": "^1.1.0", - "electron-window-state": "^4.1.1", - "node-notifier": "^5.2.1" + "electron-window-state": "^4.1.1" } } From 50d02d882fec8ef29955d88e88f0c0b37aa3f345 Mon Sep 17 00:00:00 2001 From: Antoine Guilbert Date: Thu, 28 Jun 2018 20:27:31 +0200 Subject: [PATCH 4/7] Set theme jekyll-theme-cayman --- _config.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 _config.yml diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..c419263 --- /dev/null +++ b/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-cayman \ No newline at end of file From 11f39e0108b116ddf0af2875cdf7af7d7ad315a1 Mon Sep 17 00:00:00 2001 From: Antoine Guilbert Date: Thu, 28 Jun 2018 20:47:53 +0200 Subject: [PATCH 5/7] Delete _config.yml --- _config.yml | 1 - 1 file changed, 1 deletion(-) delete mode 100644 _config.yml diff --git a/_config.yml b/_config.yml deleted file mode 100644 index c419263..0000000 --- a/_config.yml +++ /dev/null @@ -1 +0,0 @@ -theme: jekyll-theme-cayman \ No newline at end of file From d9dd44fe1e624a2eb94652ec8e667ac9c36c98fc Mon Sep 17 00:00:00 2001 From: Antoine Guilbert Date: Fri, 29 Jun 2018 00:20:15 +0200 Subject: [PATCH 6/7] Localize the app --- main.js | 31 ++++++++++++++++--------------- package.json | 3 ++- translations/en.js | 18 ++++++++++++++++++ translations/fr.js | 18 ++++++++++++++++++ translations/i18n.js | 25 +++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 16 deletions(-) create mode 100644 translations/en.js create mode 100644 translations/fr.js create mode 100644 translations/i18n.js diff --git a/main.js b/main.js index 7e65562..ba77aca 100644 --- a/main.js +++ b/main.js @@ -26,7 +26,6 @@ function createWindow () { mainWindow = new BrowserWindow(windowOptions) //mainWindow.webContents.openDevTools(); - //mainWindow.webContents.executeJavaScript("var elements = document.getElementsByTagName('link'); while (elements[0]) elements[0].parentNode.removeChild(elements[0])"); mainWindow.loadURL(url.format({ pathname: path.join('messages.android.com'), @@ -55,19 +54,21 @@ function createWindow () { //Creating the menu function createMenu (){ + var i18n = new(require('./translations/i18n')); + const template = [ { - label: 'Edition', + label: i18n.__('Edit'), submenu: [ - {label:'Copier',role: 'copy'}, - {label:'Coller',role: 'paste'}, - {label:'Tout sélectionner',role: 'selectall'}, + {label: i18n.__('Copy'),role: 'copy'}, + {label: i18n.__('Paste'),role: 'paste'}, + {label: i18n.__('Select all'),role: 'selectall'}, {type: 'separator'}, - {label:'Recharger',accelerator: 'CmdOrCtrl+R',click (item, focusedWindow) {if (focusedWindow) focusedWindow.reload()}}, + {label: i18n.__('Reload'),accelerator: 'CmdOrCtrl+R',click (item, focusedWindow) {if (focusedWindow) focusedWindow.reload()}}, ] }, { - label: 'Fenêtre', + label: i18n.__('Window'), role: 'window' } ] @@ -77,23 +78,23 @@ function createMenu (){ template.unshift({ label: name, submenu: [ - {label:'À propos',role: 'about'}, + {label: i18n.__('About'),role: 'about'}, {type: 'separator'}, - {label:'Déconnecter le compte', click: function click() {clearAppCache(); }}, + {label: i18n.__('Disconnect account'), click: function click() {clearAppCache(); }}, {type: 'separator'}, - {label:'Masquer '+name,role: 'hide'}, - {label:'Masquer les autres',role: 'hideothers'}, - {label:'Tout afficher',role: 'unhide'}, + {label: i18n.__('Hide')+' '+name,role: 'hide'}, + {label: i18n.__('Hider others'),role: 'hideothers'}, + {label: i18n.__('Unhide'),role: 'unhide'}, {type: 'separator'}, - {label:'Quitter',role: 'quit'} + {label: i18n.__('Quit'),role: 'quit'} ] }) template[1].submenu.push() template[2].submenu = [ - {label: 'Réduire',accelerator: 'CmdOrCtrl+M',role: 'minimize'}, - {label: 'Agrandir',role: 'zoom'} + {label: i18n.__('Minimize'),accelerator: 'CmdOrCtrl+M',role: 'minimize'}, + {label: i18n.__('Zoom'),role: 'zoom'} ] } diff --git a/package.json b/package.json index 475bdef..77a7a85 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ }, "dependencies": { "electron-context-menu": "^0.10.0", - "electron-window-state": "^4.1.1" + "electron-window-state": "^4.1.1", + "i18n": "^0.8.3" } } diff --git a/translations/en.js b/translations/en.js new file mode 100644 index 0000000..8d4b517 --- /dev/null +++ b/translations/en.js @@ -0,0 +1,18 @@ +{ + "Edit": "Edit", + "Cut": "Cut", + "Copy": "Copy", + "Paste": "Paste", + "Delete": "Delete", + "Select all": "Select all", + "Reload": "Reload", + "Window": "Window", + "Minimize": "Minimize", + "Zoom": "Zoom", + "About": "About", + "Disconnect account": "Disconnect account", + "Hide": "Hide", + "Hide others": "Hide others", + "Unhide": "Unhide", + "Quit": "Quit" +} diff --git a/translations/fr.js b/translations/fr.js new file mode 100644 index 0000000..a9645f1 --- /dev/null +++ b/translations/fr.js @@ -0,0 +1,18 @@ +{ + "Edit": "Édition", + "Cut": "Couper", + "Copy": "Copier", + "Paste": "Coller", + "Delete": "Supprimer", + "Select all": "Tout sélectionner", + "Reload": "Recharger", + "Window": "Fenêtre", + "Minimize": "Réduire", + "Zoom": "Agrandir", + "About": "À propos", + "Disconnect account": "Déconnecter le compte", + "Hide": "Masquer", + "Hide others": "Masquer les autres", + "Unhide": "Tout afficher", + "Quit": "Quitter" +} diff --git a/translations/i18n.js b/translations/i18n.js new file mode 100644 index 0000000..b8812f2 --- /dev/null +++ b/translations/i18n.js @@ -0,0 +1,25 @@ +//Constants +const path = require('path') +const electron = require('electron') +const fs = require('fs'); + +let loadedLanguage; +let app = electron.app; + +module.exports = i18n; + +function i18n() { + if(fs.existsSync(path.join(__dirname, app.getLocale() + '.js'))) { + loadedLanguage = JSON.parse(fs.readFileSync(path.join(__dirname, app.getLocale() + '.js'), 'utf8')); + }else{ + loadedLanguage = JSON.parse(fs.readFileSync(path.join(__dirname, 'en.js'), 'utf8')); + } +} + +i18n.prototype.__ = function(phrase) { + let translation = loadedLanguage[phrase] + if(translation === undefined) { + translation = phrase + } + return translation +} From 5f4c68221693dfd4d419b3e5da9cfb11a1610180 Mon Sep 17 00:00:00 2001 From: Antoine Guilbert Date: Fri, 29 Jun 2018 00:57:31 +0200 Subject: [PATCH 7/7] Change version to 1.1.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 77a7a85..04e7d01 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "android-messages", "productName": "Android Messages", "appId": "com.antoineguilbert.android-messages", - "version": "1.1.1", + "version": "1.1.2", "description": "Just a simple project made with electron JS to show Android Messages from Google in a app with notifications.", "main": "main.js", "scripts": {