Browse Source

Format 87d48a6

pull/3163/head
prettifier[bot] 4 years ago committed by GitHub
parent
commit
c82d2e3bb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 645
      electron/main.js
  2. 7
      resources/css/screenselector.css
  3. 76
      resources/js/rambox-service-api.js
  4. 80
      resources/js/screenselector.js

645
electron/main.js

@ -1,87 +1,101 @@
'use strict'; "use strict";
const {app, BrowserWindow, shell, Menu, ipcMain, nativeImage, session} = require('electron'); const {
app,
BrowserWindow,
shell,
Menu,
ipcMain,
nativeImage,
session,
} = require("electron");
// Tray // Tray
const tray = require('./tray'); const tray = require("./tray");
// AutoLaunch // AutoLaunch
var AutoLaunch = require('auto-launch-patched'); var AutoLaunch = require("auto-launch-patched");
// Configuration // Configuration
const Config = require('electron-store'); const Config = require("electron-store");
// Development // Development
const isDev = require('electron-is-dev'); const isDev = require("electron-is-dev");
// Updater // Updater
const updater = require('./updater'); const updater = require("./updater");
// File System // File System
var fs = require("fs"); var fs = require("fs");
const path = require('path'); const path = require("path");
// Disk usage: // Disk usage:
// const disk = require('diskusage'); // const disk = require('diskusage');
if ( isDev ) app.getVersion = function() { return require('../package.json').version; }; // FOR DEV ONLY, BECAUSE IN DEV RETURNS ELECTRON'S VERSION if (isDev)
app.getVersion = function () {
return require("../package.json").version;
}; // FOR DEV ONLY, BECAUSE IN DEV RETURNS ELECTRON'S VERSION
// Initial Config // Initial Config
const config = new Config({ const config = new Config({
defaults: { defaults: {
always_on_top: false always_on_top: false,
,hide_menu_bar: false hide_menu_bar: false,
,tabbar_location: 'top' tabbar_location: "top",
,hide_tabbar_labels: false hide_tabbar_labels: false,
,window_display_behavior: 'taskbar_tray' window_display_behavior: "taskbar_tray",
,auto_launch: !isDev auto_launch: !isDev,
,flash_frame: true flash_frame: true,
,window_close_behavior: 'keep_in_tray' window_close_behavior: "keep_in_tray",
,start_minimized: false start_minimized: false,
,systemtray_indicator: true systemtray_indicator: true,
,master_password: false master_password: false,
,dont_disturb: false dont_disturb: false,
,disable_gpu: process.platform === 'linux' disable_gpu: process.platform === "linux",
,proxy: false proxy: false,
,proxyHost: '' proxyHost: "",
,proxyPort: '' proxyPort: "",
,proxyLogin: '' proxyLogin: "",
,proxyPassword: '' proxyPassword: "",
,locale: 'en' locale: "en",
,enable_hidpi_support: false enable_hidpi_support: false,
,user_agent: '' user_agent: "",
,default_service: 'ramboxTab' default_service: "ramboxTab",
,sendStatistics: false sendStatistics: false,
,x: undefined x: undefined,
,y: undefined y: undefined,
,width: 1000 width: 1000,
,height: 800 height: 800,
,maximized: false maximized: false,
} },
}); });
// Fix issues with HiDPI scaling on Windows platform // Fix issues with HiDPI scaling on Windows platform
if (config.get('enable_hidpi_support') && (process.platform === 'win32')) { if (config.get("enable_hidpi_support") && process.platform === "win32") {
app.commandLine.appendSwitch('high-dpi-support', 'true') app.commandLine.appendSwitch("high-dpi-support", "true");
app.commandLine.appendSwitch('force-device-scale-factor', '1') app.commandLine.appendSwitch("force-device-scale-factor", "1");
} }
app.commandLine.appendSwitch('lang', config.get('locale') === 'en' ? 'en-US' : config.get('locale')); app.commandLine.appendSwitch(
"lang",
config.get("locale") === "en" ? "en-US" : config.get("locale")
);
// Temporary fix to load Twitter and other websites inside webviews // Temporary fix to load Twitter and other websites inside webviews
// Bug related with Electron: https://github.com/electron/electron/issues/25469 // Bug related with Electron: https://github.com/electron/electron/issues/25469
app.commandLine.appendSwitch('disable-features', 'CrossOriginOpenerPolicy'); app.commandLine.appendSwitch("disable-features", "CrossOriginOpenerPolicy");
// Because we build it using Squirrel, it will assign UserModelId automatically, so we match it here to display notifications correctly. // Because we build it using Squirrel, it will assign UserModelId automatically, so we match it here to display notifications correctly.
// https://github.com/electron-userland/electron-builder/issues/362 // https://github.com/electron-userland/electron-builder/issues/362
app.setAppUserModelId('com.grupovrs.ramboxce'); app.setAppUserModelId("com.grupovrs.ramboxce");
// Menu // Menu
const appMenu = require('./menu')(config); const appMenu = require("./menu")(config);
// Configure AutoLaunch // Configure AutoLaunch
let appLauncher; let appLauncher;
if (!isDev) { if (!isDev) {
appLauncher = new AutoLaunch({ appLauncher = new AutoLaunch({
name: 'Rambox' name: "Rambox",
,isHidden: config.get('start_minimized') isHidden: config.get("start_minimized"),
}); });
config.get('auto_launch') ? appLauncher.enable() : appLauncher.disable(); config.get("auto_launch") ? appLauncher.enable() : appLauncher.disable();
} }
// Keep a global reference of the window object, if you don't, the window will // Keep a global reference of the window object, if you don't, the window will
@ -92,41 +106,50 @@ let isQuitting = false;
function createWindow() { function createWindow() {
// Create the browser window using the state information // Create the browser window using the state information
mainWindow = new BrowserWindow({ mainWindow = new BrowserWindow({
title: 'Rambox' title: "Rambox",
,icon: __dirname + '/../resources/Icon.' + (process.platform === 'linux' ? 'png' : 'ico') icon:
,backgroundColor: '#FFF' __dirname +
,x: config.get('x') "/../resources/Icon." +
,y: config.get('y') (process.platform === "linux" ? "png" : "ico"),
,width: config.get('width') backgroundColor: "#FFF",
,height: config.get('height') x: config.get("x"),
,alwaysOnTop: config.get('always_on_top') y: config.get("y"),
,autoHideMenuBar: config.get('hide_menu_bar') width: config.get("width"),
,skipTaskbar: config.get('window_display_behavior') === 'show_trayIcon' height: config.get("height"),
,show: !config.get('start_minimized') alwaysOnTop: config.get("always_on_top"),
,acceptFirstMouse: true autoHideMenuBar: config.get("hide_menu_bar"),
,webPreferences: { skipTaskbar: config.get("window_display_behavior") === "show_trayIcon",
enableRemoteModule: true show: !config.get("start_minimized"),
,plugins: true acceptFirstMouse: true,
,partition: 'persist:rambox' webPreferences: {
,nodeIntegration: true enableRemoteModule: true,
,webviewTag: true plugins: true,
,contextIsolation: false partition: "persist:rambox",
,spellcheck: false nodeIntegration: true,
} webviewTag: true,
contextIsolation: false,
spellcheck: false,
},
}); });
// Check if user has defined a custom User-Agent // Check if user has defined a custom User-Agent
if ( config.get('user_agent').length > 0 ) mainWindow.webContents.setUserAgent( config.get('user_agent') ); if (config.get("user_agent").length > 0)
mainWindow.webContents.setUserAgent(config.get("user_agent"));
// Wait for the mainWindow.loadURL(..) and the optional mainWindow.webContents.openDevTools() // Wait for the mainWindow.loadURL(..) and the optional mainWindow.webContents.openDevTools()
// to be finished before minimizing // to be finished before minimizing
config.get('start_minimized') && mainWindow.webContents.once('did-finish-load', () => config.get('window_display_behavior') === 'show_trayIcon' ? mainWindow.hide() : mainWindow.minimize()); config.get("start_minimized") &&
mainWindow.webContents.once("did-finish-load", () =>
config.get("window_display_behavior") === "show_trayIcon"
? mainWindow.hide()
: mainWindow.minimize()
);
// Check if the window its outside of the view (ex: multi monitor setup) // Check if the window its outside of the view (ex: multi monitor setup)
const { positionOnScreen } = require('./utils/positionOnScreen'); const { positionOnScreen } = require("./utils/positionOnScreen");
const inBounds = positionOnScreen([config.get('x'), config.get('y')]); const inBounds = positionOnScreen([config.get("x"), config.get("y")]);
if (inBounds) { if (inBounds) {
mainWindow.setPosition(config.get('x'), config.get('y')); mainWindow.setPosition(config.get("x"), config.get("y"));
} else { } else {
mainWindow.center(); mainWindow.center();
} }
@ -137,28 +160,36 @@ function createWindow () {
if (isDev) mainWindow.webContents.openDevTools(); if (isDev) mainWindow.webContents.openDevTools();
// and load the index.html of the app. // and load the index.html of the app.
mainWindow.loadURL('file://' + __dirname + '/../index.html'); mainWindow.loadURL("file://" + __dirname + "/../index.html");
Menu.setApplicationMenu(appMenu); Menu.setApplicationMenu(appMenu);
tray.create(mainWindow, config); tray.create(mainWindow, config);
if ( process.argv.indexOf('--without-update') === -1 ) updater.initialize(mainWindow); if (process.argv.indexOf("--without-update") === -1)
updater.initialize(mainWindow);
// Open links in default browser // Open links in default browser
mainWindow.webContents.on('new-window', function(e, url, frameName, disposition, options) { mainWindow.webContents.on(
const protocol = require('url').parse(url).protocol; "new-window",
function (e, url, frameName, disposition, options) {
const protocol = require("url").parse(url).protocol;
switch (disposition) { switch (disposition) {
case 'new-window': case "new-window":
e.preventDefault(); e.preventDefault();
const win = new BrowserWindow(options); const win = new BrowserWindow(options);
if ( config.get('user_agent').length > 0 ) win.webContents.setUserAgent( config.get('user_agent') ); if (config.get("user_agent").length > 0)
win.once('ready-to-show', () => win.show()); win.webContents.setUserAgent(config.get("user_agent"));
win.once("ready-to-show", () => win.show());
win.loadURL(url); win.loadURL(url);
e.newGuest = win; e.newGuest = win;
break; break;
case 'foreground-tab': case "foreground-tab":
if (protocol === 'http:' || protocol === 'https:' || protocol === 'mailto:') { if (
protocol === "http:" ||
protocol === "https:" ||
protocol === "mailto:"
) {
e.preventDefault(); e.preventDefault();
shell.openExternal(url); shell.openExternal(url);
} }
@ -166,45 +197,60 @@ function createWindow () {
default: default:
break; break;
} }
}); }
);
mainWindow.webContents.on('will-navigate', function(event, url) { mainWindow.webContents.on("will-navigate", function (event, url) {
event.preventDefault(); event.preventDefault();
}); });
// BrowserWindow events // BrowserWindow events
mainWindow.on('page-title-updated', (e, title) => updateBadge(title)); mainWindow.on("page-title-updated", (e, title) => updateBadge(title));
mainWindow.on('maximize', function(e) { config.set('maximized', true); }); mainWindow.on("maximize", function (e) {
mainWindow.on('unmaximize', function(e) { config.set('maximized', false); }); config.set("maximized", true);
mainWindow.on('resize', function(e) { if (!mainWindow.isMaximized()) config.set(mainWindow.getBounds()); }); });
mainWindow.on('move', function(e) { if (!mainWindow.isMaximized()) config.set(mainWindow.getBounds()); }); mainWindow.on("unmaximize", function (e) {
mainWindow.on('app-command', (e, cmd) => { config.set("maximized", false);
});
mainWindow.on("resize", function (e) {
if (!mainWindow.isMaximized()) config.set(mainWindow.getBounds());
});
mainWindow.on("move", function (e) {
if (!mainWindow.isMaximized()) config.set(mainWindow.getBounds());
});
mainWindow.on("app-command", (e, cmd) => {
// Navigate the window back when the user hits their mouse back button // Navigate the window back when the user hits their mouse back button
if ( cmd === 'browser-backward' ) mainWindow.webContents.executeJavaScript('if(Ext.cq1("app-main")) Ext.cq1("app-main").getActiveTab().goBack();'); if (cmd === "browser-backward")
mainWindow.webContents.executeJavaScript(
'if(Ext.cq1("app-main")) Ext.cq1("app-main").getActiveTab().goBack();'
);
// Navigate the window forward when the user hits their mouse forward button // Navigate the window forward when the user hits their mouse forward button
if ( cmd === 'browser-forward' ) mainWindow.webContents.executeJavaScript('if(Ext.cq1("app-main")) Ext.cq1("app-main").getActiveTab().goForward();'); if (cmd === "browser-forward")
mainWindow.webContents.executeJavaScript(
'if(Ext.cq1("app-main")) Ext.cq1("app-main").getActiveTab().goForward();'
);
}); });
// Emitted when the window is closed. // Emitted when the window is closed.
mainWindow.on('close', function(e) { mainWindow.on("close", function (e) {
if (!isQuitting) { if (!isQuitting) {
e.preventDefault(); e.preventDefault();
switch (process.platform) { switch (process.platform) {
case 'darwin': case "darwin":
app.hide(); app.hide();
break; break;
case 'linux': case "linux":
case 'win32': case "win32":
default: default:
switch (config.get('window_close_behavior')) { switch (config.get("window_close_behavior")) {
case 'keep_in_tray': case "keep_in_tray":
mainWindow.hide(); mainWindow.hide();
break; break;
case 'keep_in_tray_and_taskbar': case "keep_in_tray_and_taskbar":
mainWindow.minimize(); mainWindow.minimize();
break; break;
case 'quit': case "quit":
app.quit(); app.quit();
break; break;
} }
@ -212,65 +258,81 @@ function createWindow () {
} }
} }
}); });
mainWindow.on('minimize', function(e) { mainWindow.on("minimize", function (e) {
if ( config.get('window_display_behavior') === 'show_trayIcon' ) mainWindow.setSkipTaskbar(true); if (config.get("window_display_behavior") === "show_trayIcon")
mainWindow.setSkipTaskbar(true);
}); });
mainWindow.on('restore', function(e) { mainWindow.on("restore", function (e) {
if ( config.get('window_display_behavior') === 'show_taskbar' ) mainWindow.setSkipTaskbar(false); if (config.get("window_display_behavior") === "show_taskbar")
mainWindow.setSkipTaskbar(false);
}); });
mainWindow.on('show', function(e) { mainWindow.on("show", function (e) {
if ( config.get('window_display_behavior') !== 'show_trayIcon' ) mainWindow.setSkipTaskbar(false); if (config.get("window_display_behavior") !== "show_trayIcon")
mainWindow.setSkipTaskbar(false);
}); });
mainWindow.on('closed', function(e) { mainWindow.on("closed", function (e) {
mainWindow = null; mainWindow = null;
}); });
mainWindow.once('focus', () => mainWindow.flashFrame(false)); mainWindow.once("focus", () => mainWindow.flashFrame(false));
} }
let mainMasterPasswordWindow; let mainMasterPasswordWindow;
function createMasterPasswordWindow() { function createMasterPasswordWindow() {
mainMasterPasswordWindow = new BrowserWindow({ mainMasterPasswordWindow = new BrowserWindow({
backgroundColor: '#0675A0' backgroundColor: "#0675A0",
,frame: false frame: false,
,webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
,enableRemoteModule: true enableRemoteModule: true,
} },
}); });
// Open the DevTools. // Open the DevTools.
if (isDev) mainMasterPasswordWindow.webContents.openDevTools(); if (isDev) mainMasterPasswordWindow.webContents.openDevTools();
mainMasterPasswordWindow.loadURL('file://' + __dirname + '/../masterpassword.html'); mainMasterPasswordWindow.loadURL(
mainMasterPasswordWindow.on('close', function() { mainMasterPasswordWindow = null }); "file://" + __dirname + "/../masterpassword.html"
);
mainMasterPasswordWindow.on("close", function () {
mainMasterPasswordWindow = null;
});
} }
function updateBadge(title) { function updateBadge(title) {
title = title.split(" - ")[0]; //Discard service name if present, could also contain digits title = title.split(" - ")[0]; //Discard service name if present, could also contain digits
var messageCount = title.match(/\d+/g) ? parseInt(title.match(/\d+/g).join("")) : 0; var messageCount = title.match(/\d+/g)
? parseInt(title.match(/\d+/g).join(""))
: 0;
messageCount = isNaN(messageCount) ? 0 : messageCount; messageCount = isNaN(messageCount) ? 0 : messageCount;
tray.setBadge(messageCount, config.get('systemtray_indicator')); tray.setBadge(messageCount, config.get("systemtray_indicator"));
if (process.platform === 'win32') { if (process.platform === "win32") {
if (messageCount === 0) return mainWindow.setOverlayIcon(null, ''); if (messageCount === 0) return mainWindow.setOverlayIcon(null, "");
mainWindow.webContents.send('setBadge', messageCount); mainWindow.webContents.send("setBadge", messageCount);
} else { // macOS & Linux } else {
// macOS & Linux
app.setBadgeCount(messageCount); app.setBadgeCount(messageCount);
} }
if ( messageCount > 0 && !mainWindow.isFocused() && !config.get('dont_disturb') && config.get('flash_frame') ) mainWindow.flashFrame(true); if (
messageCount > 0 &&
!mainWindow.isFocused() &&
!config.get("dont_disturb") &&
config.get("flash_frame")
)
mainWindow.flashFrame(true);
} }
function formatBytes(bytes, decimals = 2) { function formatBytes(bytes, decimals = 2) {
if (bytes === 0) return '0 Bytes'; if (bytes === 0) return "0 Bytes";
const k = 1024; const k = 1024;
const dm = decimals < 0 ? 0 : decimals; const dm = decimals < 0 ? 0 : decimals;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
const i = Math.floor(Math.log(bytes) / Math.log(k)); const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
} }
/* async function availableSpaceWatchDog() { /* async function availableSpaceWatchDog() {
@ -295,18 +357,21 @@ function formatBytes(bytes, decimals = 2) {
} }
} */ } */
ipcMain.on('setBadge', function(event, messageCount, value) { ipcMain.on("setBadge", function (event, messageCount, value) {
mainWindow.setOverlayIcon(nativeImage.createFromDataURL(value), messageCount.toString()); mainWindow.setOverlayIcon(
nativeImage.createFromDataURL(value),
messageCount.toString()
);
}); });
ipcMain.on('getConfig', function(event, arg) { ipcMain.on("getConfig", function (event, arg) {
event.returnValue = config.store; event.returnValue = config.store;
}); });
ipcMain.on('sConfig', function(event, values) { ipcMain.on("sConfig", function (event, values) {
config.set(values); config.set(values);
event.returnValue = config; event.returnValue = config;
}); });
ipcMain.on('setConfig', function(event, values) { ipcMain.on("setConfig", function (event, values) {
config.set(values); config.set(values);
// hide_menu_bar // hide_menu_bar
@ -319,18 +384,20 @@ ipcMain.on('setConfig', function(event, values) {
// systemtray_indicator // systemtray_indicator
updateBadge(mainWindow.getTitle()); updateBadge(mainWindow.getTitle());
mainWindow.webContents.executeJavaScript('(function(a){if(a)a.controller.initialize(a)})(Ext.cq1("app-main"))'); mainWindow.webContents.executeJavaScript(
'(function(a){if(a)a.controller.initialize(a)})(Ext.cq1("app-main"))'
);
switch (values.window_display_behavior) { switch (values.window_display_behavior) {
case 'show_taskbar': case "show_taskbar":
mainWindow.setSkipTaskbar(false); mainWindow.setSkipTaskbar(false);
tray.destroy(); tray.destroy();
break; break;
case 'show_trayIcon': case "show_trayIcon":
mainWindow.setSkipTaskbar(true); mainWindow.setSkipTaskbar(true);
tray.create(mainWindow, config); tray.create(mainWindow, config);
break; break;
case 'taskbar_tray': case "taskbar_tray":
mainWindow.setSkipTaskbar(false); mainWindow.setSkipTaskbar(false);
tray.create(mainWindow, config); tray.create(mainWindow, config);
break; break;
@ -339,12 +406,15 @@ ipcMain.on('setConfig', function(event, values) {
} }
}); });
ipcMain.on('sendStatistics', function(event) { ipcMain.on("sendStatistics", function (event) {
event.returnValue = config.get('sendStatistics'); event.returnValue = config.get("sendStatistics");
}); });
ipcMain.on('validateMasterPassword', function(event, pass) { ipcMain.on("validateMasterPassword", function (event, pass) {
if ( config.get('master_password') === require('crypto').createHash('md5').update(pass).digest('hex') ) { if (
config.get("master_password") ===
require("crypto").createHash("md5").update(pass).digest("hex")
) {
createWindow(); createWindow();
mainMasterPasswordWindow.close(); mainMasterPasswordWindow.close();
event.returnValue = true; event.returnValue = true;
@ -353,25 +423,27 @@ ipcMain.on('validateMasterPassword', function(event, pass) {
}); });
// Handle Service Notifications // Handle Service Notifications
ipcMain.on('setServiceNotifications', function(event, partition, op) { ipcMain.on("setServiceNotifications", function (event, partition, op) {
if (partition === null) return; if (partition === null) return;
session.fromPartition(partition).setPermissionRequestHandler(function(webContents, permission, callback) { session
if (permission === 'notifications') return callback(op); .fromPartition(partition)
callback(true) .setPermissionRequestHandler(function (webContents, permission, callback) {
if (permission === "notifications") return callback(op);
callback(true);
}); });
}); });
ipcMain.on('setDontDisturb', function(event, arg) { ipcMain.on("setDontDisturb", function (event, arg) {
config.set('dont_disturb', arg); config.set("dont_disturb", arg);
}); });
// Reload app // Reload app
ipcMain.on('reloadApp', function(event) { ipcMain.on("reloadApp", function (event) {
mainWindow.reload(); mainWindow.reload();
}); });
// Relaunch app // Relaunch app
ipcMain.on('relaunchApp', function(event) { ipcMain.on("relaunchApp", function (event) {
app.relaunch(); app.relaunch();
app.exit(0); app.exit(0);
}); });
@ -381,7 +453,7 @@ if (!shouldQuit) {
app.quit(); app.quit();
return; return;
} }
app.on('second-instance', (event, commandLine, workingDirectory) => { app.on("second-instance", (event, commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window. // Someone tried to run a second instance, we should focus our window.
if (mainWindow) { if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore(); if (mainWindow.isMinimized()) mainWindow.restore();
@ -394,76 +466,95 @@ app.on('second-instance', (event, commandLine, workingDirectory) => {
// ALLOWED URLS POPUPS // ALLOWED URLS POPUPS
let allowPopUp = [ let allowPopUp = [
'feedly.com/v3/auth/', "feedly.com/v3/auth/",
'identity.linuxfoundation.org/cas/login', "identity.linuxfoundation.org/cas/login",
'auth.missiveapp.com', "auth.missiveapp.com",
'accounts.google.com/AccountChooser', "accounts.google.com/AccountChooser",
'facebook.com/v3.1/dialog/oauth?', "facebook.com/v3.1/dialog/oauth?",
'accounts.google.com/o/oauth2', "accounts.google.com/o/oauth2",
'app.slack.com/files/import/gdrive', "app.slack.com/files/import/gdrive",
'spikenow.com/s/account', "spikenow.com/s/account",
'app.mixmax.com/_oauth/google', "app.mixmax.com/_oauth/google",
'officeapps.live.com', "officeapps.live.com",
'dropbox.com/profile_services/start_auth_flow', "dropbox.com/profile_services/start_auth_flow",
'facebook.com/v3.2/dialog/oauth?', "facebook.com/v3.2/dialog/oauth?",
'notion.so/googlepopupredirect', "notion.so/googlepopupredirect",
'zoom.us/office365', "zoom.us/office365",
'figma.com/start_google_sso', "figma.com/start_google_sso",
'mail.google.com/mail', "mail.google.com/mail",
'app.slack.com/free-willy/', "app.slack.com/free-willy/",
'messenger.com/videocall', "messenger.com/videocall",
'api.moo.do', "api.moo.do",
'manychat.com/fb?popup', "manychat.com/fb?popup",
'=?print=true' // esta ultima checkea como anda imprimir un pedf desde gmail, si no va bie sacala "=?print=true", // esta ultima checkea como anda imprimir un pedf desde gmail, si no va bie sacala
]; ];
app.on('web-contents-created', (webContentsCreatedEvent, contents) => { app.on("web-contents-created", (webContentsCreatedEvent, contents) => {
if (contents.getType() !== 'webview') return; if (contents.getType() !== "webview") return;
// Block some Deep links to prevent that open its app (Ex: Slack) // Block some Deep links to prevent that open its app (Ex: Slack)
contents.on('will-navigate', (event, url) => url.substring(0, 8) === 'slack://' && event.preventDefault()); contents.on(
"will-navigate",
(event, url) => url.substring(0, 8) === "slack://" && event.preventDefault()
);
// New Window handler // New Window handler
contents.on('new-window', (event, url, frameName, disposition, options, additionalFeatures, referrer, postBody) => { contents.on(
"new-window",
(
event,
url,
frameName,
disposition,
options,
additionalFeatures,
referrer,
postBody
) => {
// If the url is about:blank we allow the window and handle it in 'did-create-window' // If the url is about:blank we allow the window and handle it in 'did-create-window'
if (['about:blank', 'about:blank#blocked'].includes(url)) { if (["about:blank", "about:blank#blocked"].includes(url)) {
event.preventDefault(); event.preventDefault();
Object.assign(options, { show: false }); Object.assign(options, { show: false });
const win = new BrowserWindow(options); const win = new BrowserWindow(options);
win.center(); win.center();
let once = false; let once = false;
win.webContents.on('will-navigate', (e, nextURL) => { win.webContents.on("will-navigate", (e, nextURL) => {
if (once) return; if (once) return;
if (['about:blank', 'about:blank#blocked'].includes(nextURL)) return; if (["about:blank", "about:blank#blocked"].includes(nextURL)) return;
once = true; once = true;
let allow = false; let allow = false;
allowPopUp.forEach(url => nextURL.indexOf(url) > -1 && (allow = true)); allowPopUp.forEach(
(url) => nextURL.indexOf(url) > -1 && (allow = true)
);
// If the url is in aboutBlankOnlyWindow we handle this as a popup window // If the url is in aboutBlankOnlyWindow we handle this as a popup window
if (allow) return win.show(); if (allow) return win.show();
shell.openExternal(nextURL); shell.openExternal(nextURL);
win.close() win.close();
}) });
event.newGuest = win; event.newGuest = win;
return; return;
} }
// We check if url is in the allowPopUpLoginURLs or allowForegroundTabURLs in Firebase to open a as a popup, // We check if url is in the allowPopUpLoginURLs or allowForegroundTabURLs in Firebase to open a as a popup,
// if it is not we send this to the app // if it is not we send this to the app
let allow = false; let allow = false;
allowPopUp.forEach(allowed => url.indexOf(allowed) > -1 && (allow = true)); allowPopUp.forEach(
(allowed) => url.indexOf(allowed) > -1 && (allow = true)
);
if (allow) return; if (allow) return;
shell.openExternal(url); shell.openExternal(url);
event.preventDefault(); event.preventDefault();
}); }
contents.on('did-create-window', (win, details) => { );
contents.on("did-create-window", (win, details) => {
// Here we center the new window. // Here we center the new window.
win.center(); win.center();
// The following code is for handling the about:blank cases only. // The following code is for handling the about:blank cases only.
if (!['about:blank', 'about:blank#blocked'].includes(details.url)) return; if (!["about:blank", "about:blank#blocked"].includes(details.url)) return;
let once = false; let once = false;
win.webContents.on('will-navigate', (e, nextURL) => { win.webContents.on("will-navigate", (e, nextURL) => {
if (once) return; if (once) return;
if (['about:blank', 'about:blank#blocked'].includes(nextURL)) return; if (["about:blank", "about:blank#blocked"].includes(nextURL)) return;
once = true; once = true;
let allow = false; let allow = false;
allowPopUp.forEach(url => nextURL.indexOf(url) > -1 && (allow = true)); allowPopUp.forEach((url) => nextURL.indexOf(url) > -1 && (allow = true));
// If the url is in aboutBlankOnlyWindow we handle this as a popup window // If the url is in aboutBlankOnlyWindow we handle this as a popup window
if (allow) return win.show(); if (allow) return win.show();
shell.openExternal(url); shell.openExternal(url);
@ -474,10 +565,10 @@ app.on('web-contents-created', (webContentsCreatedEvent, contents) => {
// Code for downloading images as temporal files // Code for downloading images as temporal files
// Credit: Ghetto Skype (https://github.com/stanfieldr/ghetto-skype) // Credit: Ghetto Skype (https://github.com/stanfieldr/ghetto-skype)
const tmp = require('tmp'); const tmp = require("tmp");
const mime = require('mime'); const mime = require("mime");
var imageCache = {}; var imageCache = {};
ipcMain.on('image:download', function(event, url, partition) { ipcMain.on("image:download", function (event, url, partition) {
let file = imageCache[url]; let file = imageCache[url];
if (file) { if (file) {
if (file.complete) { if (file.complete) {
@ -489,22 +580,24 @@ ipcMain.on('image:download', function(event, url, partition) {
} }
let tmpWindow = new BrowserWindow({ let tmpWindow = new BrowserWindow({
show: false show: false,
,webPreferences: { webPreferences: {
partition: partition partition: partition,
} },
}); });
if ( config.get('user_agent').length > 0 ) tmpWindow.webContents.setUserAgent( config.get('user_agent') ); if (config.get("user_agent").length > 0)
tmpWindow.webContents.setUserAgent(config.get("user_agent"));
tmpWindow.webContents.session.once('will-download', (event, downloadItem) => { tmpWindow.webContents.session.once("will-download", (event, downloadItem) => {
imageCache[url] = file = { imageCache[url] = file = {
path: tmp.tmpNameSync() + '.' + mime.extension(downloadItem.getMimeType()) path:
,complete: false tmp.tmpNameSync() + "." + mime.extension(downloadItem.getMimeType()),
complete: false,
}; };
downloadItem.setSavePath(file.path); downloadItem.setSavePath(file.path);
downloadItem.once('done', () => { downloadItem.once("done", () => {
tmpWindow.destroy(); tmpWindow.destroy();
tmpWindow = null; tmpWindow = null;
shell.openItem(file.path); shell.openItem(file.path);
@ -516,72 +609,109 @@ ipcMain.on('image:download', function(event, url, partition) {
}); });
// Hangouts // Hangouts
ipcMain.on('image:popup', function(event, url, partition) { ipcMain.on("image:popup", function (event, url, partition) {
let tmpWindow = new BrowserWindow({ let tmpWindow = new BrowserWindow({
width: mainWindow.getBounds().width width: mainWindow.getBounds().width,
,height: mainWindow.getBounds().height height: mainWindow.getBounds().height,
,parent: mainWindow parent: mainWindow,
,icon: __dirname + '/../resources/Icon.ico' icon: __dirname + "/../resources/Icon.ico",
,backgroundColor: '#FFF' backgroundColor: "#FFF",
,autoHideMenuBar: true autoHideMenuBar: true,
,skipTaskbar: true skipTaskbar: true,
,webPreferences: { webPreferences: {
partition: partition partition: partition,
} },
}); });
if ( config.get('user_agent').length > 0 ) tmpWindow.webContents.setUserAgent( config.get('user_agent') ); if (config.get("user_agent").length > 0)
tmpWindow.webContents.setUserAgent(config.get("user_agent"));
tmpWindow.maximize(); tmpWindow.maximize();
tmpWindow.loadURL(url); tmpWindow.loadURL(url);
}); });
ipcMain.on('toggleWin', function(event, allwaysShow) { ipcMain.on("toggleWin", function (event, allwaysShow) {
if ( config.get('window_display_behavior') !== 'show_trayIcon' ) mainWindow.setSkipTaskbar(false); if (config.get("window_display_behavior") !== "show_trayIcon")
if ( !mainWindow.isMinimized() && mainWindow.isMaximized() && mainWindow.isVisible() ) { // Maximized mainWindow.setSkipTaskbar(false);
if (
!mainWindow.isMinimized() &&
mainWindow.isMaximized() &&
mainWindow.isVisible()
) {
// Maximized
!allwaysShow ? mainWindow.close() : mainWindow.show(); !allwaysShow ? mainWindow.close() : mainWindow.show();
} else if ( mainWindow.isMinimized() && !mainWindow.isMaximized() && !mainWindow.isVisible() ) { // Minimized } else if (
if ( process.platform === 'linux' ) { mainWindow.isMinimized() &&
!mainWindow.isMaximized() &&
!mainWindow.isVisible()
) {
// Minimized
if (process.platform === "linux") {
mainWindow.minimize(); mainWindow.minimize();
mainWindow.restore(); mainWindow.restore();
mainWindow.focus(); mainWindow.focus();
return return;
} }
mainWindow.restore(); mainWindow.restore();
} else if ( !mainWindow.isMinimized() && !mainWindow.isMaximized() && mainWindow.isVisible() ) { // Windowed mode } else if (
!mainWindow.isMinimized() &&
!mainWindow.isMaximized() &&
mainWindow.isVisible()
) {
// Windowed mode
!allwaysShow ? mainWindow.close() : mainWindow.show(); !allwaysShow ? mainWindow.close() : mainWindow.show();
} else if ( mainWindow.isMinimized() && !mainWindow.isMaximized() && mainWindow.isVisible() ) { // Closed to taskbar } else if (
if ( process.platform === 'linux' ) { mainWindow.isMinimized() &&
!mainWindow.isMaximized() &&
mainWindow.isVisible()
) {
// Closed to taskbar
if (process.platform === "linux") {
mainWindow.minimize(); mainWindow.minimize();
mainWindow.restore(); mainWindow.restore();
mainWindow.focus(); mainWindow.focus();
return return;
} }
mainWindow.restore(); mainWindow.restore();
} else if ( !mainWindow.isMinimized() && mainWindow.isMaximized() && !mainWindow.isVisible() ) { // Closed maximized to tray } else if (
!mainWindow.isMinimized() &&
mainWindow.isMaximized() &&
!mainWindow.isVisible()
) {
// Closed maximized to tray
mainWindow.show(); mainWindow.show();
} else if ( !mainWindow.isMinimized() && !mainWindow.isMaximized() && !mainWindow.isVisible() ) { // Closed windowed to tray } else if (
!mainWindow.isMinimized() &&
!mainWindow.isMaximized() &&
!mainWindow.isVisible()
) {
// Closed windowed to tray
mainWindow.show(); mainWindow.show();
} else if ( mainWindow.isMinimized() && !mainWindow.isMaximized() && !mainWindow.isVisible() ) { // Closed minimized to tray } else if (
mainWindow.isMinimized() &&
!mainWindow.isMaximized() &&
!mainWindow.isVisible()
) {
// Closed minimized to tray
mainWindow.show(); mainWindow.show();
} else { } else {
if ( process.platform === 'linux' ) { if (process.platform === "linux") {
mainWindow.minimize(); mainWindow.minimize();
mainWindow.maximize(); mainWindow.maximize();
mainWindow.focus(); mainWindow.focus();
return return;
} }
mainWindow.restore(); mainWindow.restore();
} }
}); });
// ScreenShare // ScreenShare
ipcMain.on('screenShare:show', (event, screenList) => { ipcMain.on("screenShare:show", (event, screenList) => {
let tmpWindow = new BrowserWindow({ let tmpWindow = new BrowserWindow({
width: 600, width: 600,
height: 500, height: 500,
icon: __dirname + '/../resources/Icon.ico', icon: __dirname + "/../resources/Icon.ico",
autoHideMenuBar: true, autoHideMenuBar: true,
transparent: true, transparent: true,
show: true, show: true,
@ -598,67 +728,70 @@ ipcMain.on('screenShare:show', (event, screenList) => {
}; };
const onCancel = () => { const onCancel = () => {
event.sender.send('screenShare:cancel'); event.sender.send("screenShare:cancel");
close(); close();
}; };
const onShare = (_, shareId) => { const onShare = (_, shareId) => {
event.sender.send('screenShare:share', shareId); event.sender.send("screenShare:share", shareId);
close(); close();
}; };
ipcMain.handle('screenShare:getSources', () => screenList); ipcMain.handle("screenShare:getSources", () => screenList);
ipcMain.on('screenShare:cancelSelection', onCancel); ipcMain.on("screenShare:cancelSelection", onCancel);
ipcMain.on('screenShare:selectScreen', onShare); ipcMain.on("screenShare:selectScreen", onShare);
tmpWindow.on('closed', () => { tmpWindow.on("closed", () => {
ipcMain.removeHandler('screenShare:getSources'); ipcMain.removeHandler("screenShare:getSources");
ipcMain.removeAllListeners('screenShare:cancelSelection'); ipcMain.removeAllListeners("screenShare:cancelSelection");
ipcMain.removeAllListeners('screenShare:selectScreen'); ipcMain.removeAllListeners("screenShare:selectScreen");
}); });
tmpWindow.loadFile(__dirname + '/../screenselector.html'); tmpWindow.loadFile(__dirname + "/../screenselector.html");
}); });
// Proxy // Proxy
if ( config.get('proxy') ) { if (config.get("proxy")) {
app.commandLine.appendSwitch('proxy-server', config.get('proxyHost')+':'+config.get('proxyPort')); app.commandLine.appendSwitch(
app.on('login', (event, webContents, request, authInfo, callback) => { "proxy-server",
if(!authInfo.isProxy) config.get("proxyHost") + ":" + config.get("proxyPort")
return; );
app.on("login", (event, webContents, request, authInfo, callback) => {
if (!authInfo.isProxy) return;
event.preventDefault(); event.preventDefault();
callback(config.get('proxyLogin'), config.get('proxyPassword')) callback(config.get("proxyLogin"), config.get("proxyPassword"));
}) });
} }
// Disable GPU Acceleration for Linux // Disable GPU Acceleration for Linux
// to prevent White Page bug // to prevent White Page bug
// https://github.com/electron/electron/issues/6139 // https://github.com/electron/electron/issues/6139
// https://github.com/saenzramiro/rambox/issues/181 // https://github.com/saenzramiro/rambox/issues/181
if ( config.get('disable_gpu') ) app.disableHardwareAcceleration(); if (config.get("disable_gpu")) app.disableHardwareAcceleration();
// This method will be called when Electron has finished // This method will be called when Electron has finished
// initialization and is ready to create browser windows. // initialization and is ready to create browser windows.
app.on('ready', function() { app.on("ready", function () {
config.get('master_password') ? createMasterPasswordWindow() : createWindow(); config.get("master_password") ? createMasterPasswordWindow() : createWindow();
// setInterval(availableSpaceWatchDog, 1000 * 60); // setInterval(availableSpaceWatchDog, 1000 * 60);
}); });
// Quit when all windows are closed. // Quit when all windows are closed.
app.on('window-all-closed', function () { app.on("window-all-closed", function () {
// On OS X it is common for applications and their menu bar // On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q // to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') { if (process.platform !== "darwin") {
app.quit(); app.quit();
} }
}); });
// Only macOS: On OS X it's common to re-create a window in the app when the // Only macOS: On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open. // dock icon is clicked and there are no other windows open.
app.on('activate', function () { app.on("activate", function () {
if (mainWindow === null && mainMasterPasswordWindow === null) { if (mainWindow === null && mainMasterPasswordWindow === null) {
config.get('master_password') ? createMasterPasswordWindow() : createWindow(); config.get("master_password")
? createMasterPasswordWindow()
: createWindow();
} }
if (mainWindow) { if (mainWindow) {
@ -666,6 +799,6 @@ app.on('activate', function () {
} }
}); });
app.on('before-quit', function () { app.on("before-quit", function () {
isQuitting = true; isQuitting = true;
}); });

7
resources/css/screenselector.css

@ -1,4 +1,5 @@
html, body { html,
body {
width: 100%; width: 100%;
height: 100%; height: 100%;
margin: 0; margin: 0;
@ -36,7 +37,8 @@ html, body {
-webkit-app-region: no-drag; -webkit-app-region: no-drag;
} }
.screen-selector ul.type li.active, .screen-selector ul.type li:hover { .screen-selector ul.type li.active,
.screen-selector ul.type li:hover {
color: #426ba3; color: #426ba3;
border-color: #426ba3; border-color: #426ba3;
} }
@ -113,7 +115,6 @@ html, body {
display: inline-block; display: inline-block;
width: 100%; width: 100%;
border-top: solid 1px #cdcdcd; border-top: solid 1px #cdcdcd;
} }
.screen-selector .footer button { .screen-selector .footer button {

76
resources/js/rambox-service-api.js

@ -2,8 +2,11 @@
* This file is loaded in the service web views to provide a Rambox API. * This file is loaded in the service web views to provide a Rambox API.
*/ */
const { desktopCapturer, ipcRenderer } = require('electron'); const { desktopCapturer, ipcRenderer } = require("electron");
const { ContextMenuBuilder, ContextMenuListener } = require('electron-contextmenu-wrapper'); const {
ContextMenuBuilder,
ContextMenuListener,
} = require("electron-contextmenu-wrapper");
/** /**
* Make the Rambox API available via a global "rambox" variable. * Make the Rambox API available via a global "rambox" variable.
@ -18,15 +21,15 @@ window.rambox = {};
* @param {*} count The unread count * @param {*} count The unread count
*/ */
window.rambox.setUnreadCount = function (count) { window.rambox.setUnreadCount = function (count) {
ipcRenderer.sendToHost('rambox.setUnreadCount', count); ipcRenderer.sendToHost("rambox.setUnreadCount", count);
}; };
/** /**
* Clears the unread count. * Clears the unread count.
*/ */
window.rambox.clearUnreadCount = function () { window.rambox.clearUnreadCount = function () {
ipcRenderer.sendToHost('rambox.clearUnreadCount'); ipcRenderer.sendToHost("rambox.clearUnreadCount");
} };
/** /**
* Override to add notification click event to display Rambox window and activate service tab * Override to add notification click event to display Rambox window and activate service tab
@ -35,74 +38,89 @@ var NativeNotification = Notification;
Notification = function (title, options) { Notification = function (title, options) {
var notification = new NativeNotification(title, options); var notification = new NativeNotification(title, options);
notification.addEventListener('click', function() { notification.addEventListener("click", function () {
ipcRenderer.sendToHost('rambox.showWindowAndActivateTab'); ipcRenderer.sendToHost("rambox.showWindowAndActivateTab");
}); });
//It seems that gmail is checking if such event handler func are available. Just remplacing them by a void function that is always returning true is making the thing right! //It seems that gmail is checking if such event handler func are available. Just remplacing them by a void function that is always returning true is making the thing right!
notification.addEventListener = function() {return true}; notification.addEventListener = function () {
notification.attachEvent = function() {return true}; return true;
notification.addListener = function() {return true}; };
notification.attachEvent = function () {
return true;
};
notification.addListener = function () {
return true;
};
return notification; return notification;
} };
Notification.prototype = NativeNotification.prototype; Notification.prototype = NativeNotification.prototype;
Notification.permission = NativeNotification.permission; Notification.permission = NativeNotification.permission;
Notification.requestPermission = NativeNotification.requestPermission.bind(Notification); Notification.requestPermission = NativeNotification.requestPermission.bind(
Notification
);
window.rambox.contextMenuBuilder = new ContextMenuBuilder(); window.rambox.contextMenuBuilder = new ContextMenuBuilder();
window.rambox.contextMenuListener = new ContextMenuListener(function(event, info) { window.rambox.contextMenuListener = new ContextMenuListener(function (
event,
info
) {
window.rambox.contextMenuBuilder.showPopupMenu(info); window.rambox.contextMenuBuilder.showPopupMenu(info);
}); });
const mousetrap = require('mousetrap'); const mousetrap = require("mousetrap");
mousetrap.bind(process.platform === 'darwin' ? ['command+left', 'command+right'] : ['alt+left', 'alt+right'], e => { mousetrap.bind(
if (location.href.indexOf('slack.com') !== -1) return; process.platform === "darwin"
e.key === 'ArrowLeft' ? history.back() : history.forward(); ? ["command+left", "command+right"]
}); : ["alt+left", "alt+right"],
(e) => {
if (location.href.indexOf("slack.com") !== -1) return;
e.key === "ArrowLeft" ? history.back() : history.forward();
}
);
// ScreenShare // ScreenShare
window.navigator.mediaDevices.getDisplayMedia = () => window.navigator.mediaDevices.getDisplayMedia = () =>
new Promise(async (resolve, reject) => { new Promise(async (resolve, reject) => {
try { try {
const sources = await desktopCapturer.getSources({ const sources = await desktopCapturer.getSources({
types: ['screen', 'window'], types: ["screen", "window"],
}); });
const unlisten = () => { const unlisten = () => {
ipcRenderer.removeAllListeners('screenShare:cancel'); ipcRenderer.removeAllListeners("screenShare:cancel");
ipcRenderer.removeAllListeners('screenShare:share'); ipcRenderer.removeAllListeners("screenShare:share");
}; };
ipcRenderer.on('screenShare:cancel', () => { ipcRenderer.on("screenShare:cancel", () => {
unlisten(); unlisten();
reject(new Error('Cancelled by user')); reject(new Error("Cancelled by user"));
}); });
ipcRenderer.on('screenShare:share', (_, shareId) => { ipcRenderer.on("screenShare:share", (_, shareId) => {
unlisten(); unlisten();
window.navigator.mediaDevices window.navigator.mediaDevices
.getUserMedia({ .getUserMedia({
audio: false, audio: false,
video: { video: {
mandatory: { mandatory: {
chromeMediaSource: 'desktop', chromeMediaSource: "desktop",
chromeMediaSourceId: shareId, chromeMediaSourceId: shareId,
}, },
}, },
}) })
.then(stream => resolve(stream)); .then((stream) => resolve(stream));
}); });
const mappedSources = sources.map(it => ({ const mappedSources = sources.map((it) => ({
id: it.id, id: it.id,
name: it.name, name: it.name,
thumbnail: it.thumbnail.toDataURL(), thumbnail: it.thumbnail.toDataURL(),
})); }));
ipcRenderer.send('screenShare:show', mappedSources); ipcRenderer.send("screenShare:show", mappedSources);
} catch (err) { } catch (err) {
reject(err); reject(err);
} }

80
resources/js/screenselector.js

@ -1,77 +1,91 @@
const { ipcRenderer } = require('electron'); const { ipcRenderer } = require("electron");
let sourceList, contentList, typeButtons, shareButton, cancelButton, activeItem, activeTab = 'screen'; let sourceList,
contentList,
typeButtons,
shareButton,
cancelButton,
activeItem,
activeTab = "screen";
const getItemDOM = item => { const getItemDOM = (item) => {
const li = document.createElement('li'); const li = document.createElement("li");
li.setAttribute('data-id', item.id); li.setAttribute("data-id", item.id);
li.innerHTML = `<div class="content"><div class="img-wrapper"><img src="${item.thumbnail}" /></div><span>${item.name}</span></div>`; li.innerHTML = `<div class="content"><div class="img-wrapper"><img src="${item.thumbnail}" /></div><span>${item.name}</span></div>`;
li.addEventListener('click', onItemClick, false); li.addEventListener("click", onItemClick, false);
return li; return li;
}; };
const updateTab = () => { const updateTab = () => {
const sources = sourceList.filter(it => it.id.indexOf(activeTab) === 0); const sources = sourceList.filter((it) => it.id.indexOf(activeTab) === 0);
contentList.innerHTML = ''; contentList.innerHTML = "";
sources.forEach(source => contentList.appendChild(getItemDOM(source))); sources.forEach((source) => contentList.appendChild(getItemDOM(source)));
}; };
const bindTypeClick = () => { const bindTypeClick = () => {
typeButtons.forEach(it => it.addEventListener('click', onChangeType, false)); typeButtons.forEach((it) =>
it.addEventListener("click", onChangeType, false)
);
}; };
const bindActionsClick = () => { const bindActionsClick = () => {
shareButton.addEventListener('click', onShareClick, false); shareButton.addEventListener("click", onShareClick, false);
cancelButton.addEventListener('click', onCancelClick, false); cancelButton.addEventListener("click", onCancelClick, false);
}; };
const onChangeType = event => { const onChangeType = (event) => {
event.preventDefault(); event.preventDefault();
if (!event.target.classList.contains('active')) { if (!event.target.classList.contains("active")) {
activeTab = event.target.dataset.type; activeTab = event.target.dataset.type;
typeButtons.forEach(it => it.classList.remove('active')); typeButtons.forEach((it) => it.classList.remove("active"));
event.target.classList.add('active'); event.target.classList.add("active");
updateTab(); updateTab();
} }
}; };
const onItemClick = event => { const onItemClick = (event) => {
event.preventDefault(); event.preventDefault();
if (!event.currentTarget.classList.contains('active')) { if (!event.currentTarget.classList.contains("active")) {
activeItem = event.currentTarget.dataset.id; activeItem = event.currentTarget.dataset.id;
document.querySelectorAll('.preview li').forEach(it => it.classList.remove('active')); document
event.currentTarget.classList.add('active'); .querySelectorAll(".preview li")
.forEach((it) => it.classList.remove("active"));
event.currentTarget.classList.add("active");
changeShareState(); changeShareState();
} }
}; };
const onCancelClick = event => { const onCancelClick = (event) => {
event.preventDefault(); event.preventDefault();
ipcRenderer.send('screenShare:cancelSelection'); ipcRenderer.send("screenShare:cancelSelection");
}; };
const onShareClick = event => { const onShareClick = (event) => {
event.preventDefault(); event.preventDefault();
if (activeItem) { if (activeItem) {
ipcRenderer.send('screenShare:selectScreen', activeItem); ipcRenderer.send("screenShare:selectScreen", activeItem);
} }
}; };
const changeShareState = () => { const changeShareState = () => {
if (shareButton.getAttribute('disabled') !== null) { if (shareButton.getAttribute("disabled") !== null) {
shareButton.removeAttribute('disabled'); shareButton.removeAttribute("disabled");
} }
}; };
window.addEventListener('load', async () => { window.addEventListener(
sourceList = await ipcRenderer.invoke('screenShare:getSources'); "load",
async () => {
sourceList = await ipcRenderer.invoke("screenShare:getSources");
contentList = document.querySelector('.preview'); contentList = document.querySelector(".preview");
typeButtons = document.querySelectorAll('.type li'); typeButtons = document.querySelectorAll(".type li");
shareButton = document.querySelector('#share'); shareButton = document.querySelector("#share");
cancelButton = document.querySelector('#cancel'); cancelButton = document.querySelector("#cancel");
bindTypeClick(); bindTypeClick();
bindActionsClick(); bindActionsClick();
updateTab(); updateTab();
}, false); },
false
);

Loading…
Cancel
Save