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

Commit

Permalink
Switch back to '@electron/remote' and switch back to 'electron-contex…
Browse files Browse the repository at this point in the history
…t-menu'.
  • Loading branch information
TheGoddessInari committed Dec 8, 2021
1 parent 87e9e61 commit c6dabde
Show file tree
Hide file tree
Showing 10 changed files with 293 additions and 79 deletions.
6 changes: 3 additions & 3 deletions app/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ Ext.define('Hamsket.Application', {


// Set cookies to help Tooltip.io messages segmentation
Ext.util.Cookies.set('version', require('electron').remote.app.getVersion());
Ext.util.Cookies.set('version', require('@electron/remote').app.getVersion());

// Check for updates
if ( require('electron').remote.process.argv.indexOf('--without-update') === -1 ) Hamsket.app.checkUpdate(true);
if ( require('@electron/remote').process.argv.indexOf('--without-update') === -1 ) Hamsket.app.checkUpdate(true);

// Mouse Wheel zooming
document.addEventListener('mousewheel', function(e) {
Expand Down Expand Up @@ -85,7 +85,7 @@ Ext.define('Hamsket.Application', {
,method: 'GET'
,success(response) {
const json = JSON.parse(response.responseText);
const appVersion = new Ext.Version(require('electron').remote.app.getVersion());
const appVersion = new Ext.Version(require('@electron/remote').app.getVersion());
const updateVersion = new Ext.Version(json.tag_name);
if ( appVersion.isLessThan(updateVersion) ) {
console.info('New version is available', updateVersion);
Expand Down
2 changes: 1 addition & 1 deletion app/ux/FileBackup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Ext.define('Hamsket.ux.FileBackup', {
constructor() {
const me = this;
me.callParent(arguments);
me.remote = require('electron').remote;
me.remote = require('@electron/remote');
me.path = me.remote.require('path');
me.fs = me.remote.require('fs');
me.userPath = me.remote.app.getPath('userData');
Expand Down
31 changes: 16 additions & 15 deletions app/ux/WebView.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Ext.define('Hamsket.ux.WebView',{
,partition: 'persist:' + me.record.get('type') + '_' + me.id.replace('tab_', '')
,allowtransparency: 'on'
,autosize: 'on'
,webpreferences: 'nativeWindowOpen=yes,enableRemoteModule=yes,spellcheck=yes,contextIsolation=no' //,nativeWindowOpen=true
,webpreferences: 'nativeWindowOpen=yes,spellcheck=yes,contextIsolation=no' //,nativeWindowOpen=true
,allowpopups: 'on'
//,disablewebsecurity: 'on' // Disabled because some services (Like Google Drive) dont work with this enabled
,userAgent: me.getUserAgent()
Expand Down Expand Up @@ -265,7 +265,7 @@ Ext.define('Hamsket.ux.WebView',{
// Block some Deep links to prevent that open its app (Ex: Slack)
if (['slack:'].includes(protocol)) return;
// Allow Deep links
if (!['http:', 'https:', 'about:'].includes(protocol)) return require('electron').shell.openExternal(url.href);
if (!['http:', 'https:', 'about:'].includes(protocol)) return require('@electron/remote').shell.openExternal(url.href);
});

webview.addEventListener('will-navigate', function(e, url) {
Expand Down Expand Up @@ -437,7 +437,7 @@ Ext.define('Hamsket.ux.WebView',{
}

function showWindowAndActivateTab(event) {
const currentWindow = require('electron').remote.getCurrentWindow();
const currentWindow = require('@electron/remote').getCurrentWindow();
currentWindow.show();
currentWindow.focus();
const tabPanel = Ext.cq1('app-main');
Expand Down Expand Up @@ -700,10 +700,11 @@ Ext.define('Hamsket.ux.WebView',{
}
,getWebContents() {
if ( this.record.get('enabled') ) {
const remote = require('electron').remote;
const remote = require('@electron/remote');
const webview = this.getWebView();
const id = webview.getWebContentsId();
return remote.webContents.fromId(id);
const webContents = remote.webContents.fromId(id);
return webContents;
} else {
return false;
}
Expand Down Expand Up @@ -743,7 +744,7 @@ Ext.define('Hamsket.ux.WebView',{
}
,getOSArch(platform) {
const me = this;
const remote = require('electron').remote;
const remote = require('@electron/remote');
platform = platform ? platform : remote.require('os').platform();
let arch = remote.require('os').arch();

Expand All @@ -765,7 +766,7 @@ Ext.define('Hamsket.ux.WebView',{
return arch;
}
,getOSArchType() {
let arch = require('electron').remote.require('os').arch();
let arch = require('@electron/remote').require('os').arch();

switch(arch) {
case 'x64':
Expand Down Expand Up @@ -797,7 +798,7 @@ Ext.define('Hamsket.ux.WebView',{
}
,getOSPlatform(platform) {
const me = this;
platform = platform ? platform : require('electron').remote.require('os').platform();
platform = platform ? platform : require('@electron/remote').require('os').platform();
switch (platform) {
case 'win32':
platform = `${me.getOSRelease(platform)}; ${me.getOSArch(platform)}`;
Expand All @@ -820,23 +821,23 @@ Ext.define('Hamsket.ux.WebView',{
return platform;
}
,isWindows(platform) {
platform = platform ? platform : require('electron').remote.require('os').platform();
platform = platform ? platform : require('@electron/remote').require('os').platform();
return platform === 'win32';
}
,isMac(platform) {
platform = platform ? platform : require('electron').remote.require('os').platform();
platform = platform ? platform : require('@electron/remote').require('os').platform();
return platform === 'darwin';
}
,is32bit() {
const arch = require('electron').remote.require('os').arch();
const arch = require('@electron/remote').require('os').arch();
if (arch === 'ia32' || arch === 'x32')
return true;
else
return false;
}
,getOSRelease(platform) {
const me = this;
const remote = require('electron').remote;
const remote = require('@electron/remote');
if (me.isWindows(platform)) {
if (platform)
{
Expand All @@ -852,13 +853,13 @@ Ext.define('Hamsket.ux.WebView',{
}
}
,getChromeVersion(version) {
return version || require('electron').remote.require('process').versions['chrome'];
return version || require('@electron/remote').process.versions['chrome'];
}
,getElectronVersion() {
return require('electron').require('process').versions['electron'];
return require('@electron/remote').process.versions['electron'];
}
,getAppVersion() {
return require('electron').remote.app.getVersion();
return require('@electron/remote').app.getVersion();
}
,blur() {
this.getWebView().blur();
Expand Down
2 changes: 1 addition & 1 deletion app/view/main/About.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Ext.define('Hamsket.view.main.About', {
me.data.buildversion = require('fs').readFileSync( __dirname + '/BUILDVERSION', 'utf8');
}
,data: {
version: require('electron').remote.app.getVersion()
version: require('@electron/remote').app.getVersion()
,platform: process.platform
,arch: process.arch
,electron: process.versions.electron
Expand Down
2 changes: 1 addition & 1 deletion app/view/main/MainController.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Ext.define('Hamsket.view.main.MainController', {

// Get Record
const rec = Ext.getStore('Services').getById(serviceId);
const {session: rsession} = require('electron').remote;
const {session: rsession} = require('@electron/remote');

if ( !rec.get('enabled') ) {
const session = rsession.fromPartition(`persist:${rec.get('type')}_${serviceId}`);
Expand Down
19 changes: 16 additions & 3 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const updater = require('./updater');
// File System
const fs = require("fs");
const path = require('path');
const contextMenu = require('electron-context-menu');

// If 'data' folder exists in Hamsket's folder, set userdata, logs, and usercache path to there
var basepath = app.getAppPath();
Expand Down Expand Up @@ -117,11 +118,12 @@ function createWindow () {
partition: 'persist:hamsket',
nodeIntegration: true,
webviewTag: true,
enableRemoteModule: true,
contextIsolation: false
contextIsolation: false,
}
});

require("@electron/remote/main").enable(mainWindow.webContents);

if ( !config.get('start_minimized') && config.get('maximized') ) mainWindow.maximize();
if (config.get('start_minimized')){
if (config.get('window_display_behavior') == 'show_taskbar') {
Expand Down Expand Up @@ -235,11 +237,11 @@ function createMasterPasswordWindow() {
,frame: false
,webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
contextIsolation: false
}

});
require("@electron/remote/main").enable(mainMasterPasswordWindow.webContents);

mainMasterPasswordWindow.loadURL('file://' + __dirname + '/../masterpassword.html');
mainMasterPasswordWindow.on('close', function() { mainMasterPasswordWindow = null; });
Expand Down Expand Up @@ -585,6 +587,7 @@ if ( config.get('disable_gpu') ) app.disableHardwareAcceleration();
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', function() {
require('@electron/remote/main').initialize();
if (config.get('master_password')) {
createMasterPasswordWindow();
} else {
Expand Down Expand Up @@ -621,8 +624,18 @@ app.on('before-quit', function () {

// Prevent the ability to create webview with nodeIntegration.
app.on('web-contents-created', (event, contents) => {
const contextMenuWebContentsDispose = contextMenu({
window: contents,
showCopyImageAddress: true,
showSaveImage: false,
showSaveImageAs: true,
});
contents.on('will-attach-webview', (event, webPreferences, params) => {
// Always prevent node integration
webPreferences.nodeIntegration = false;

});
contents.on('destroyed', function() {
contextMenuWebContentsDispose();
})
});
2 changes: 1 addition & 1 deletion masterpassword.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
}

function exit() {
require('electron').remote.app.quit();
require('@electron/remote').app.quit();
}

</script>
Expand Down

0 comments on commit c6dabde

Please sign in to comment.