From 4127e0a7072d510c3cfb7d106d3b9401d9dba617 Mon Sep 17 00:00:00 2001 From: Karol Putra Date: Wed, 2 Sep 2020 21:45:08 +0200 Subject: [PATCH 1/7] Added availableSpaceWatchDog Every minute it check free disk space. It uses new module - diskspace - works on Windows Linux and Mac. If the partition where Rambox is installed has < 1 GB available space: - a warning dialog appears with info about: -- remaining space -- rambox/electron installation path -- OK button which quits Rambox No matter how the dialog is dismissed, it will quit Rambox. --- electron/main.js | 40 +++++++++++++++++++++++++++++++++++++++- package.json | 1 + 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/electron/main.js b/electron/main.js index 74ad0c5d..43183f95 100644 --- a/electron/main.js +++ b/electron/main.js @@ -15,6 +15,10 @@ const updater = require('./updater'); var fs = require("fs"); const path = require('path'); +// Disk usage: +const disk = require('diskusage'); +const appPath = app.getAppPath(); + if ( isDev ) app.getVersion = function() { return require('../package.json').version; }; // FOR DEV ONLY, BECAUSE IN DEV RETURNS ELECTRON'S VERSION // Initial Config @@ -250,6 +254,40 @@ function updateBadge(title) { if ( messageCount > 0 && !mainWindow.isFocused() && !config.get('dont_disturb') && config.get('flash_frame') ) mainWindow.flashFrame(true); } +function formatBytes(bytes, decimals = 2) { + if (bytes === 0) return '0 Bytes'; + + const k = 1024; + const dm = decimals < 0 ? 0 : decimals; + const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + + const i = Math.floor(Math.log(bytes) / Math.log(k)); + + return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; +} + +async function availableSpaceWatchDog() { + // optionally render this information also in rambox window + try { + const { available } = await disk.check(appPath); + if (available < 1073741824) { // 1 GB + const options = { + type: 'warning', + buttons: ['OK, quit'], + defaultId: 0, + title: `Running out of disk space! - Rambox shutting down`, + detail: `You've got just ${formatBytes(available)} space left.\n\nRambox has been frozen to prevent settings corruption.\n\nOnce you quit this dialog, Rambox will shutdown.\n\n1 GB of avalable disk space is required.\nFree up space on partition where Rambox is installed then start the app again.\n\nRambox path: \n${appPath}`, + message: `Running out of disk space! - Rambox shutting down`, + }; + + dialog.showMessageBoxSync(null, options); + app.quit(); + } + } catch (err) { + console.error(err) + } +} + ipcMain.on('setBadge', function(event, messageCount, value) { mainWindow.setOverlayIcon(nativeImage.createFromDataURL(value), messageCount.toString()); }); @@ -474,8 +512,8 @@ if ( config.get('disable_gpu') ) app.disableHardwareAcceleration(); // initialization and is ready to create browser windows. app.on('ready', function() { config.get('master_password') ? createMasterPasswordWindow() : createWindow(); + setInterval(availableSpaceWatchDog, 1000 * 60); }); - // Quit when all windows are closed. app.on('window-all-closed', function () { // On OS X it is common for applications and their menu bar diff --git a/package.json b/package.json index 36d955e7..3eeda1db 100644 --- a/package.json +++ b/package.json @@ -209,6 +209,7 @@ "auth0-js": "9.13.2", "auto-launch-patched": "5.0.2", "crypto": "1.0.1", + "diskusage": "1.1.3", "electron-contextmenu-wrapper": "2.0.0", "electron-is-dev": "0.3.0", "electron-log": "2.2.17", From 072997e59c1319038de5035202e9cf66906a003c Mon Sep 17 00:00:00 2001 From: Karol Putra Date: Wed, 2 Sep 2020 21:45:08 +0200 Subject: [PATCH 2/7] Added availableSpaceWatchDog. Every minute it checks if available disk space < 1 GB. It requires new module - diskspace - works on Windows Linux and Mac. Tested only on Linux. If the partition where Rambox is running from has < 1 GB available space: - a warning dialog appears and Rambox freezes (synchronous dialog). Dialog has info about: -- remaining space -- rambox/electron installation path -- instruction to free up more space and that the app will exit upon dialog dismissal -- OK button which quits Rambox No matter how the dialog is dismissed, Rambox quits. --- electron/main.js | 40 +++++++++++++++++++++++++++++++++++++++- package.json | 1 + 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/electron/main.js b/electron/main.js index 74ad0c5d..43183f95 100644 --- a/electron/main.js +++ b/electron/main.js @@ -15,6 +15,10 @@ const updater = require('./updater'); var fs = require("fs"); const path = require('path'); +// Disk usage: +const disk = require('diskusage'); +const appPath = app.getAppPath(); + if ( isDev ) app.getVersion = function() { return require('../package.json').version; }; // FOR DEV ONLY, BECAUSE IN DEV RETURNS ELECTRON'S VERSION // Initial Config @@ -250,6 +254,40 @@ function updateBadge(title) { if ( messageCount > 0 && !mainWindow.isFocused() && !config.get('dont_disturb') && config.get('flash_frame') ) mainWindow.flashFrame(true); } +function formatBytes(bytes, decimals = 2) { + if (bytes === 0) return '0 Bytes'; + + const k = 1024; + const dm = decimals < 0 ? 0 : decimals; + const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + + const i = Math.floor(Math.log(bytes) / Math.log(k)); + + return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; +} + +async function availableSpaceWatchDog() { + // optionally render this information also in rambox window + try { + const { available } = await disk.check(appPath); + if (available < 1073741824) { // 1 GB + const options = { + type: 'warning', + buttons: ['OK, quit'], + defaultId: 0, + title: `Running out of disk space! - Rambox shutting down`, + detail: `You've got just ${formatBytes(available)} space left.\n\nRambox has been frozen to prevent settings corruption.\n\nOnce you quit this dialog, Rambox will shutdown.\n\n1 GB of avalable disk space is required.\nFree up space on partition where Rambox is installed then start the app again.\n\nRambox path: \n${appPath}`, + message: `Running out of disk space! - Rambox shutting down`, + }; + + dialog.showMessageBoxSync(null, options); + app.quit(); + } + } catch (err) { + console.error(err) + } +} + ipcMain.on('setBadge', function(event, messageCount, value) { mainWindow.setOverlayIcon(nativeImage.createFromDataURL(value), messageCount.toString()); }); @@ -474,8 +512,8 @@ if ( config.get('disable_gpu') ) app.disableHardwareAcceleration(); // initialization and is ready to create browser windows. app.on('ready', function() { config.get('master_password') ? createMasterPasswordWindow() : createWindow(); + setInterval(availableSpaceWatchDog, 1000 * 60); }); - // Quit when all windows are closed. app.on('window-all-closed', function () { // On OS X it is common for applications and their menu bar diff --git a/package.json b/package.json index 36d955e7..3eeda1db 100644 --- a/package.json +++ b/package.json @@ -209,6 +209,7 @@ "auth0-js": "9.13.2", "auto-launch-patched": "5.0.2", "crypto": "1.0.1", + "diskusage": "1.1.3", "electron-contextmenu-wrapper": "2.0.0", "electron-is-dev": "0.3.0", "electron-log": "2.2.17", From 58b597591296f5b2567ca13131a9a467e879a09b Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Thu, 8 Oct 2020 18:04:23 -0300 Subject: [PATCH 3/7] Added new Google URLs to avoid security rule Fixes #2835 --- app/Application.js | 10 ++++++++++ app/ux/Auth0.js | 4 +--- app/ux/WebView.js | 5 ++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/Application.js b/app/Application.js index a47452d6..bb50f913 100644 --- a/app/Application.js +++ b/app/Application.js @@ -23,7 +23,9 @@ Ext.define('Rambox.Application', { ,config: { totalServicesLoaded: 0 ,totalNotifications: 0 + ,googleURLs: [] } + ,launch: function () { const isOnline = require('is-online'); @@ -165,6 +167,14 @@ Ext.define('Rambox.Application', { // Check for updates if ( require('electron').remote.process.argv.indexOf('--without-update') === -1 ) Rambox.app.checkUpdate(true); + // Get Google URLs + Ext.Ajax.request({ + url: 'https://raw.githubusercontent.com/ramboxapp/community-edition/gh-pages/api/google.json' + ,method: 'GET' + ,success: function(response) { + Rambox.app.config.googleURLs = Ext.decode(response.responseText); + } + }); // Shortcuts const platform = require('electron').remote.process.platform; diff --git a/app/ux/Auth0.js b/app/ux/Auth0.js index 29360ad1..6d771b37 100644 --- a/app/ux/Auth0.js +++ b/app/ux/Auth0.js @@ -273,9 +273,7 @@ Ext.define('Rambox.ux.Auth0', { authWindow.webContents.on('did-start-loading', function(e) { authWindow.webContents.session.webRequest.onBeforeSendHeaders((details, callback) => { - let googleLoginURLs = ['accounts.google.com/signin/oauth', 'accounts.google.com/ServiceLogin', 'accounts.google.com/_/lookup/accountlookup'] - - googleLoginURLs.forEach((loginURL) => { + Rambox.app.config.googleURLs.forEach((loginURL) => { if ( details.url.indexOf(loginURL) > -1 ) details.requestHeaders['User-Agent'] = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0' }) callback({ cancel: false, requestHeaders: details.requestHeaders }); }); diff --git a/app/ux/WebView.js b/app/ux/WebView.js index c7229bf8..3fbd5475 100644 --- a/app/ux/WebView.js +++ b/app/ux/WebView.js @@ -276,7 +276,6 @@ Ext.define('Rambox.ux.WebView',{ if ( !me.record.get('enabled') ) return; var webview = me.getWebView(); - let googleLoginURLs = ['accounts.google.com/signin', 'accounts.google.com/ServiceLogin', 'accounts.google.com/_/lookup/accountlookup'] me.errorCodeLog = [] // Google Analytics Event @@ -290,7 +289,7 @@ Ext.define('Rambox.ux.WebView',{ console.info('Start loading...', me.src); webview.getWebContents().session.webRequest.onBeforeSendHeaders((details, callback) => { - googleLoginURLs.forEach((loginURL) => { if ( details.url.indexOf(loginURL) > -1 ) details.requestHeaders['User-Agent'] = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0'}) + Rambox.app.config.googleURLs.forEach((loginURL) => { if ( details.url.indexOf(loginURL) > -1 ) details.requestHeaders['User-Agent'] = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0'}) callback({ cancel: false, requestHeaders: details.requestHeaders }); }); @@ -600,7 +599,7 @@ Ext.define('Rambox.ux.WebView',{ }) eventsOnDom = true; - googleLoginURLs.forEach((loginURL) => { if ( webview.getURL().indexOf(loginURL) > -1 ) webview.reload() }) + Rambox.app.config.googleURLs.forEach((loginURL) => { if ( webview.getURL().indexOf(loginURL) > -1 ) webview.reload() }) } webview.executeJavaScript(js_inject).then(result => {} ).catch(err => { console.log(err) }) }); From 5eed7f02fd381a1b7d98e55e76532ef07cdb29d5 Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Thu, 8 Oct 2020 18:04:51 -0300 Subject: [PATCH 4/7] Changed URLs for updates and services --- Backers.md | 6 ------ app/Application.js | 4 ++-- app/store/ServicesList.js | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-) delete mode 100644 Backers.md diff --git a/Backers.md b/Backers.md deleted file mode 100644 index 485bd372..00000000 --- a/Backers.md +++ /dev/null @@ -1,6 +0,0 @@ -# Monthly Donators - -[Martin Grünbaum](https://github.com/alathon) - -Ivan Toshkov -[Simon Joda Stößer](https://github.com/SimJoSt) diff --git a/app/Application.js b/app/Application.js index bb50f913..dbe77934 100644 --- a/app/Application.js +++ b/app/Application.js @@ -277,12 +277,12 @@ Ext.define('Rambox.Application', { ,checkUpdate: function(silence) { console.info('Checking for updates...'); Ext.Ajax.request({ - url: 'https://rambox.pro/api/latestversion.json' + url: 'https://api.github.com/repos/ramboxapp/community-edition/releases/latest' ,method: 'GET' ,success: function(response) { var json = Ext.decode(response.responseText); var appVersion = new Ext.Version(require('electron').remote.app.getVersion()); - if ( appVersion.isLessThan(json.version) ) { + if ( appVersion.isLessThan(json.name) && !json.draft && !json.prerelease ) { console.info('New version is available', json.version); Ext.cq1('app-main').addDocked({ xtype: 'toolbar' diff --git a/app/store/ServicesList.js b/app/store/ServicesList.js index 59d42328..a2172525 100644 --- a/app/store/ServicesList.js +++ b/app/store/ServicesList.js @@ -10,7 +10,7 @@ Ext.define('Rambox.store.ServicesList', { ,proxy: { type: 'ajax', - url: 'https://raw.githubusercontent.com/saenzramiro/rambox/gh-pages/api/services.json', + url: 'https://raw.githubusercontent.com/ramboxapp/community-edition/gh-pages/api/services.json', reader: { type: 'json', rootProperty: 'responseText' From 2037dbafe5fd872017b0dd5069b6643ee00b69b9 Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Thu, 8 Oct 2020 18:07:59 -0300 Subject: [PATCH 5/7] Versioning --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 36d955e7..60ef66dc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "Rambox", "productName": "Rambox", - "version": "0.7.6", + "version": "0.7.7", "description": "Free and Open Source messaging and emailing app that combines common web applications into one.", "main": "electron/main.js", "repository": { From a8e5a42e516ef336295bb3514c80a4d7cd8fac14 Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Thu, 8 Oct 2020 18:35:01 -0300 Subject: [PATCH 6/7] Added new permissions to Snap package Fixes #2700 --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 60ef66dc..694c5079 100644 --- a/package.json +++ b/package.json @@ -124,7 +124,9 @@ ], "plugs": [ "default", - "camera" + "camera", + "audio-record", + "removable-media" ] }, "linux": { From 611235aee643376e556f5a9f4e8cbd38bca4ffe3 Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Fri, 16 Oct 2020 14:57:47 -0300 Subject: [PATCH 7/7] Added required scope to snap --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 694c5079..5b9dd25b 100644 --- a/package.json +++ b/package.json @@ -126,6 +126,7 @@ "default", "camera", "audio-record", + "audio-playback", "removable-media" ] },