Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Strip userAgent of Electron/app name. Remove default userAgent overri…
Browse files Browse the repository at this point in the history
…des.

I've kept around an entire custom User Agent builder, just in case.

Mostly fixes #75.
Everything else is due to them expecting stable Chrome
instead of whatever Electron stable is using.
It'll be easier to add a version override specifically for that now.
  • Loading branch information
TheGoddessInari committed Apr 17, 2019
1 parent 663f2f5 commit 4aab913
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 11 deletions.
6 changes: 0 additions & 6 deletions app/store/ServicesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://web.whatsapp.com/'
,type: 'messaging'
,js_unread: `let checkUnread=()=>{const elements=document.querySelectorAll(".CxUIE, .unread");let count=0;for(let i of elements)0===i.querySelectorAll('*[data-icon="muted"]').length&&count++;rambox.updateBadge(count)};setInterval(checkUnread,1e3);let unregister_queue=[];navigator.serviceWorker.getRegistrations().then(registrations=>{for(const registration of registrations)unregister_queue.push(registration.unregister());return unregister_queue}).then(queue=>{}).catch(err=>{});`
,userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3445.2 Safari/537.36'
},
{
id: 'slack'
Expand Down Expand Up @@ -57,7 +56,6 @@ Ext.define('Rambox.store.ServicesList', {
,type: 'messaging'
,titleBlink: true
,note: 'To enable desktop notifications, you have to go to Options inside Messenger.'
,userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3445.2 Safari/537.36'
},
{
id: 'skype'
Expand All @@ -66,7 +64,6 @@ Ext.define('Rambox.store.ServicesList', {
,description: locale['services[4]']
,url: 'https://web.skype.com/'
,type: 'messaging'
,userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3445.2 Safari/537.36'
,note: 'Text and Audio calls are supported only. <a href="https://github.com/TheGoddessInari/rambox/wiki/Skype" target="_blank">Read more...</a>'
},
{
Expand Down Expand Up @@ -185,7 +182,6 @@ Ext.define('Rambox.store.ServicesList', {
,titleBlink: true
,js_unread: `let getAlertCount=badges=>{let alerts=0;for(const badge of badges)if(badge&&badge.childNodes&&badge.childNodes.length>0){const count=parseInt(badge.childNodes[0].nodeValue,10);alerts+=count.isNaN?1:count}else alerts++;return alerts},checkUnread=()=>{let direct=0,indirect=document.getElementsByClassName("container-2td-dC unread-2OHH1w").length;const guildDirect=document.getElementsByClassName("wrapper-232cHJ badge-3dItlm"),directMessages=document.getElementsByClassName("wrapper-232cHJ badge-2_fwUZ");direct+=getAlertCount(guildDirect),direct+=getAlertCount(directMessages),indirect+=document.getElementsByClassName("unread-1Dp-OI").length,rambox.updateBadge(direct,indirect)};setInterval(checkUnread,3e3);`
,note: 'To enable desktop notifications, you have to go to Options inside Discord.'
,userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3445.2 Safari/537.36'
},
{
id: 'outlook'
Expand Down Expand Up @@ -215,7 +211,6 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://mail.yahoo.com/'
,type: 'email'
,note: 'To enable desktop notifications, you have to go to Options inside Yahoo! Mail.'
,userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3445.2 Safari/537.36'
},
{
id: 'protonmail'
Expand Down Expand Up @@ -684,7 +679,6 @@ Ext.define('Rambox.store.ServicesList', {
,description: 'Microsoft Teams is the chat-based workspace in Office 365 that integrates all the people, content, and tools your team needs to be more engaged and effective.'
,url: 'https://teams.microsoft.com'
,type: 'messaging'
,userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3445.2 Safari/537.36'
},
{
id: 'kezmo'
Expand Down
126 changes: 121 additions & 5 deletions app/ux/WebView.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Ext.define('Rambox.ux.WebView',{
,autosize: 'on'
,webpreferences: '' //,nativeWindowOpen=true
//,disablewebsecurity: 'on' // Disabled because some services (Like Google Drive) dont work with this enabled
,useragent: Ext.getStore('ServicesList').getById(me.record.get('type')).get('userAgent')
,userAgent: me.getUserAgent()
,preload: './resources/js/rambox-service-api.js'
}
}];
Expand Down Expand Up @@ -286,7 +286,7 @@ Ext.define('Rambox.ux.WebView',{
,src: e.url
,style: 'width:100%;height:100%;'
,partition: me.getWebView().partition
,useragent: Ext.getStore('ServicesList').getById(me.record.get('type')).get('userAgent')
,useragent: me.getUserAgent()
}
}
}).show();
Expand Down Expand Up @@ -314,7 +314,7 @@ Ext.define('Rambox.ux.WebView',{
,src: e.url
,style: 'width:100%;height:100%;'
,partition: me.getWebView().partition
,useragent: Ext.getStore('ServicesList').getById(me.record.get('type')).get('userAgent')
,useragent: me.getUserAgent()
}
}
}).show();
Expand Down Expand Up @@ -344,7 +344,7 @@ Ext.define('Rambox.ux.WebView',{
,src: e.url
,style: 'width:100%;height:100%;'
,partition: me.getWebView().partition
,useragent: Ext.getStore('ServicesList').getById(me.record.get('type')).get('userAgent')
,useragent: me.getUserAgent()
,preload: './resources/js/rambox-modal-api.js'
}
}
Expand Down Expand Up @@ -817,7 +817,123 @@ Ext.define('Rambox.ux.WebView',{
return false;
}
}
,blur: function () {
,getUserAgent: function() {
const me = this;
// TODO: Keep just in case we need our own User Agent builder.
// const default_ua = `Mozilla/5.0` +
// ` (${me.getOSPlatform()})` +
// ` AppleWebKit/537.36 (KHTML, like Gecko)` +
// ` Chrome/${me.getChromeVersion()} Safari/537.36`;
const default_ua = window.navigator.userAgent
.replace(`Electron/${me.getElectronVersion()} `,'')
.replace(`Rambox/${me.getAppVersion()} `, '');
const service_ua = Ext.getStore('ServicesList').getById(me.record.get('type')).get('userAgent');
const ua = service_ua ? service_ua : default_ua;
return ua;
}
,getOSArch: function() {
const me = this;
let platform = require('os').platform();
let arch = require('os').arch();

switch (platform) {
case 'win32':
arch = me.is32bit() ? 'WOW64' : 'Win64; x64';
break;
case 'freebsd':
arch = me.is32bit ? 'i386' : 'amd64';
break;
case 'sunos':
arch = me.is32bit() ? 'i86pc' : 'x86_64';
break;
case 'linux':
default:
arch = me.is32bit() ? 'i686' : 'x86_64';
break;
}
return arch;
}
,getOSArchType: function() {
let arch = require('os').arch();

switch(arch) {
case 'x64':
case 'ia32':
case 'x32':
arch='Intel';
break;
case 'arm64':
case 'arm':
arch='ARM';
break;
case 'mips':
case 'mipsel':
arch='MIPS';
break;
case 'ppc64':
case 'ppc':
arch='PPC';
break;
case 's390x':
case 's390':
arch='S390';
break;
default:
arch='Unknown';
break;
}
return arch;
}
,getOSPlatform: function() {
const me = this;
let platform = require('os').platform();
switch (platform) {
case 'win32':
platform = `Windows NT ${me.getOSRelease()}; ${me.getOSArch()}`;
break;
case 'linux':
platform = `X11; Linux ${me.getOSArch()}`;
break;
case 'darwin':
platform = `${me.getOSArchType()} Mac OS X ${me.getOSRelease()}`;
break;
case 'freebsd':
platform = `X11; FreeBSD ${me.getOSArch()}`;
break;
case 'sunos':
platform = `X11; SunOS i86pc`;
break;
default:
platform = `X11; ${platform} ${me.getOSArch()}`;
}
return platform;
}
,isWindows: function() {
return require('os').platform() === 'win32';
}
,is32bit: function() {
const arch = require('os').arch();
if (arch === 'ia32' || arch === 'x32')
return true;
else
return false;
}
,getOSRelease: function() {
const me = this;
return me.isWindows() ?
require('os').release().match(/([0-9]+\.[0-9]+)/)[0]
: require('os').release();
}
,getChromeVersion: function() {
return require('process').versions['chrome'];
}
,getElectronVersion: function() {
return require('process').versions['electron'];
}
,getAppVersion: function() {
return require('electron').remote.app.getVersion();
}
,blur: function() {
this.getWebView().blur();
}
,focus: function()
Expand Down

0 comments on commit 4aab913

Please sign in to comment.