Merge and migrate locally-trusted preload scripts to contextBridge API (#2553)

* Migrate intl_provider to contextBridge

* Migrate modalPreload to contextBridge

* Migrate loadingScreenPreload to contextBridge

* Migrate downloadDropdown preloads to contextBridge

* Migrate server dropdown preload to contextBridge

* Migrate urlView preload to contextBridge

* Merge all desktop API scripts into one

* Remove unused communication channel constants
This commit is contained in:
Devin Binnie
2023-02-15 13:42:53 -05:00
committed by GitHub
parent 1c0aeae118
commit 5cc2e98a1d
44 changed files with 438 additions and 821 deletions

View File

@@ -151,13 +151,13 @@ export function handleNewServerModal() {
const html = getLocalURLString('newServer.html');
const modalPreload = getLocalPreload('modalPreload.js');
const preload = getLocalPreload('desktopAPI.js');
const mainWindow = WindowManager.getMainWindow();
if (!mainWindow) {
return;
}
const modalPromise = ModalManager.addModal<TeamWithIndex[], Team>('newServer', html, modalPreload, Config.teams.map((team, index) => ({...team, index})), mainWindow, Config.teams.length === 0);
const modalPromise = ModalManager.addModal<TeamWithIndex[], Team>('newServer', html, preload, Config.teams.map((team, index) => ({...team, index})), mainWindow, Config.teams.length === 0);
if (modalPromise) {
modalPromise.then((data) => {
const teams = Config.teams;
@@ -183,7 +183,7 @@ export function handleEditServerModal(e: IpcMainEvent, name: string) {
const html = getLocalURLString('editServer.html');
const modalPreload = getLocalPreload('modalPreload.js');
const preload = getLocalPreload('desktopAPI.js');
const mainWindow = WindowManager.getMainWindow();
if (!mainWindow) {
@@ -196,7 +196,7 @@ export function handleEditServerModal(e: IpcMainEvent, name: string) {
const modalPromise = ModalManager.addModal<{currentTeams: TeamWithIndex[]; team: TeamWithIndex}, Team>(
'editServer',
html,
modalPreload,
preload,
{
currentTeams: Config.teams.map((team, index) => ({...team, index})),
team: {...Config.teams[serverIndex], index: serverIndex},
@@ -225,13 +225,13 @@ export function handleRemoveServerModal(e: IpcMainEvent, name: string) {
const html = getLocalURLString('removeServer.html');
const modalPreload = getLocalPreload('modalPreload.js');
const preload = getLocalPreload('desktopAPI.js');
const mainWindow = WindowManager.getMainWindow();
if (!mainWindow) {
return;
}
const modalPromise = ModalManager.addModal<string, boolean>('removeServer', html, modalPreload, name, mainWindow);
const modalPromise = ModalManager.addModal<string, boolean>('removeServer', html, preload, name, mainWindow);
if (modalPromise) {
modalPromise.then((remove) => {
if (remove) {
@@ -265,13 +265,13 @@ export function handleWelcomeScreenModal() {
const html = getLocalURLString('welcomeScreen.html');
const modalPreload = getLocalPreload('modalPreload.js');
const preload = getLocalPreload('desktopAPI.js');
const mainWindow = WindowManager.getMainWindow();
if (!mainWindow) {
return;
}
const modalPromise = ModalManager.addModal<TeamWithIndex[], Team>('welcomeScreen', html, modalPreload, Config.teams.map((team, index) => ({...team, index})), mainWindow, Config.teams.length === 0);
const modalPromise = ModalManager.addModal<TeamWithIndex[], Team>('welcomeScreen', html, preload, Config.teams.map((team, index) => ({...team, index})), mainWindow, Config.teams.length === 0);
if (modalPromise) {
modalPromise.then((data) => {
const teams = Config.teams;

View File

@@ -14,7 +14,7 @@ import TrustedOriginsStore from 'main/trustedOrigins';
import {getLocalURLString, getLocalPreload} from 'main/utils';
import WindowManager from 'main/windows/windowManager';
const modalPreload = getLocalPreload('modalPreload.js');
const preload = getLocalPreload('desktopAPI.js');
const loginModalHtml = getLocalURLString('loginModal.html');
const permissionModalHtml = getLocalURLString('permissionModal.html');
@@ -56,7 +56,7 @@ export class AuthManager {
if (!mainWindow) {
return;
}
const modalPromise = modalManager.addModal<LoginModalData, LoginModalResult>(authInfo.isProxy ? `proxy-${authInfo.host}` : `login-${request.url}`, loginModalHtml, modalPreload, {request, authInfo}, mainWindow);
const modalPromise = modalManager.addModal<LoginModalData, LoginModalResult>(authInfo.isProxy ? `proxy-${authInfo.host}` : `login-${request.url}`, loginModalHtml, preload, {request, authInfo}, mainWindow);
if (modalPromise) {
modalPromise.then((data) => {
const {username, password} = data;
@@ -75,7 +75,7 @@ export class AuthManager {
if (!mainWindow) {
return;
}
const modalPromise = modalManager.addModal(`permission-${request.url}`, permissionModalHtml, modalPreload, {url: request.url, permission}, mainWindow);
const modalPromise = modalManager.addModal(`permission-${request.url}`, permissionModalHtml, preload, {url: request.url, permission}, mainWindow);
if (modalPromise) {
modalPromise.then(() => {
this.handlePermissionGranted(request.url, permission);

View File

@@ -10,7 +10,7 @@ import WindowManager from './windows/windowManager';
import modalManager from './views/modalManager';
import {getLocalURLString, getLocalPreload} from './utils';
const modalPreload = getLocalPreload('modalPreload.js');
const preload = getLocalPreload('desktopAPI.js');
const html = getLocalURLString('certificateModal.html');
type CertificateModalResult = {
@@ -43,7 +43,7 @@ export class CertificateManager {
if (!mainWindow) {
return;
}
const modalPromise = modalManager.addModal<CertificateModalData, CertificateModalResult>(`certificate-${url}`, html, modalPreload, {url, list}, mainWindow);
const modalPromise = modalManager.addModal<CertificateModalData, CertificateModalResult>(`certificate-${url}`, html, preload, {url, list}, mainWindow);
if (modalPromise) {
modalPromise.then((data) => {
const {cert} = data;

View File

@@ -8,7 +8,6 @@ import {ipcRenderer, contextBridge} from 'electron';
import {
GET_LANGUAGE_INFORMATION,
RETRIEVED_LANGUAGE_INFORMATION,
QUIT,
GET_VIEW_NAME,
GET_VIEW_WEBCONTENTS_ID,
@@ -56,6 +55,36 @@ import {
UPDATE_DOWNLOADS_DROPDOWN,
APP_MENU_WILL_CLOSE,
FOCUS_THREE_DOT_MENU,
UPDATE_URL_VIEW_WIDTH,
DOWNLOADS_DROPDOWN_MENU_CLEAR_FILE,
DOWNLOADS_DROPDOWN_MENU_SHOW_FILE_IN_FOLDER,
DOWNLOADS_DROPDOWN_MENU_CANCEL_DOWNLOAD,
DOWNLOADS_DROPDOWN_MENU_OPEN_FILE,
UPDATE_DOWNLOADS_DROPDOWN_MENU,
REQUEST_DOWNLOADS_DROPDOWN_MENU_INFO,
UPDATE_TEAMS_DROPDOWN,
REQUEST_TEAMS_DROPDOWN_INFO,
RECEIVE_DROPDOWN_MENU_SIZE,
SWITCH_SERVER,
SHOW_NEW_SERVER_MODAL,
SHOW_EDIT_SERVER_MODAL,
SHOW_REMOVE_SERVER_MODAL,
RECEIVE_DOWNLOADS_DROPDOWN_SIZE,
REQUEST_CLEAR_DOWNLOADS_DROPDOWN,
REQUEST_DOWNLOADS_DROPDOWN_INFO,
START_UPDATE_DOWNLOAD,
START_UPGRADE,
TOGGLE_DOWNLOADS_DROPDOWN_MENU,
GET_DOWNLOADED_IMAGE_THUMBNAIL_LOCATION,
DOWNLOADS_DROPDOWN_OPEN_FILE,
MODAL_CANCEL,
MODAL_RESULT,
RETRIEVE_MODAL_INFO,
GET_MODAL_UNCLOSEABLE,
PING_DOMAIN,
LOADING_SCREEN_ANIMATION_FINISHED,
TOGGLE_LOADING_SCREEN_VISIBILITY,
DOWNLOADS_DROPDOWN_FOCUSED,
} from 'common/communication';
console.log('Preload initialized');
@@ -79,6 +108,10 @@ contextBridge.exposeInMainWorld('timers', {
setImmediate,
});
contextBridge.exposeInMainWorld('mas', {
getThumbnailLocation: (location) => ipcRenderer.invoke(GET_DOWNLOADED_IMAGE_THUMBNAIL_LOCATION, location),
});
contextBridge.exposeInMainWorld('desktop', {
quit: (reason, stack) => ipcRenderer.send(QUIT, reason, stack),
openAppMenu: () => ipcRenderer.send(OPEN_APP_MENU),
@@ -110,6 +143,7 @@ contextBridge.exposeInMainWorld('desktop', {
getAvailableLanguages: () => ipcRenderer.invoke(GET_AVAILABLE_LANGUAGES),
getLocalConfiguration: (option) => ipcRenderer.invoke(GET_LOCAL_CONFIGURATION, option),
getDownloadLocation: (downloadLocation) => ipcRenderer.invoke(GET_DOWNLOAD_LOCATION, downloadLocation),
getLanguageInformation: () => ipcRenderer.invoke(GET_LANGUAGE_INFORMATION),
onSynchronizeConfig: (listener) => ipcRenderer.on('synchronize-config', () => listener()),
onReloadConfiguration: (listener) => ipcRenderer.on(RELOAD_CONFIGURATION, () => listener()),
@@ -132,15 +166,86 @@ contextBridge.exposeInMainWorld('desktop', {
onOpenDownloadsDropdown: (listener) => ipcRenderer.on(OPEN_DOWNLOADS_DROPDOWN, () => listener()),
onShowDownloadsDropdownButtonBadge: (listener) => ipcRenderer.on(SHOW_DOWNLOADS_DROPDOWN_BUTTON_BADGE, () => listener()),
onHideDownloadsDropdownButtonBadge: (listener) => ipcRenderer.on(HIDE_DOWNLOADS_DROPDOWN_BUTTON_BADGE, () => listener()),
onUpdateDownloadsDropdown: (listener) => ipcRenderer.on(UPDATE_DOWNLOADS_DROPDOWN, (_, downloads) => listener(downloads)),
onUpdateDownloadsDropdown: (listener) => ipcRenderer.on(UPDATE_DOWNLOADS_DROPDOWN, (_, downloads, darkMode, windowBounds, item) => listener(downloads, darkMode, windowBounds, item)),
onAppMenuWillClose: (listener) => ipcRenderer.on(APP_MENU_WILL_CLOSE, () => listener()),
onFocusThreeDotMenu: (listener) => ipcRenderer.on(FOCUS_THREE_DOT_MENU, () => listener()),
updateURLViewWidth: (width) => ipcRenderer.send(UPDATE_URL_VIEW_WIDTH, width),
downloadsDropdown: {
toggleDownloadsDropdownMenu: (payload) => ipcRenderer.send(TOGGLE_DOWNLOADS_DROPDOWN_MENU, payload),
requestInfo: () => ipcRenderer.send(REQUEST_DOWNLOADS_DROPDOWN_INFO),
sendSize: (width, height) => ipcRenderer.send(RECEIVE_DOWNLOADS_DROPDOWN_SIZE, width, height),
requestClearDownloadsDropdown: () => ipcRenderer.send(REQUEST_CLEAR_DOWNLOADS_DROPDOWN),
openFile: (item) => ipcRenderer.send(DOWNLOADS_DROPDOWN_OPEN_FILE, item),
startUpdateDownload: () => ipcRenderer.send(START_UPDATE_DOWNLOAD),
startUpgrade: () => ipcRenderer.send(START_UPGRADE),
focus: () => ipcRenderer.send(DOWNLOADS_DROPDOWN_FOCUSED),
},
downloadsDropdownMenu: {
requestInfo: () => ipcRenderer.send(REQUEST_DOWNLOADS_DROPDOWN_MENU_INFO),
showInFolder: (item) => ipcRenderer.send(DOWNLOADS_DROPDOWN_MENU_SHOW_FILE_IN_FOLDER, item),
cancelDownload: (item) => ipcRenderer.send(DOWNLOADS_DROPDOWN_MENU_CANCEL_DOWNLOAD, item),
clearFile: (item) => ipcRenderer.send(DOWNLOADS_DROPDOWN_MENU_CLEAR_FILE, item),
openFile: (item) => ipcRenderer.send(DOWNLOADS_DROPDOWN_MENU_OPEN_FILE, item),
onUpdateDownloadsDropdownMenu: (listener) => ipcRenderer.on(UPDATE_DOWNLOADS_DROPDOWN_MENU, (_, item, darkMode) => listener(item, darkMode)),
},
serverDropdown: {
requestInfo: () => ipcRenderer.send(REQUEST_TEAMS_DROPDOWN_INFO),
sendSize: (width, height) => ipcRenderer.send(RECEIVE_DROPDOWN_MENU_SIZE, width, height),
switchServer: (server) => ipcRenderer.send(SWITCH_SERVER, server),
showNewServerModal: () => ipcRenderer.send(SHOW_NEW_SERVER_MODAL),
showEditServerModal: (serverName) => ipcRenderer.send(SHOW_EDIT_SERVER_MODAL, serverName),
showRemoveServerModal: (serverName) => ipcRenderer.send(SHOW_REMOVE_SERVER_MODAL, serverName),
onUpdateServerDropdown: (listener) => ipcRenderer.on(UPDATE_TEAMS_DROPDOWN, (_,
teams,
activeTeam,
darkMode,
enableServerManagement,
hasGPOTeams,
expired,
mentions,
unreads,
windowBounds,
) => listener(
teams,
activeTeam,
darkMode,
enableServerManagement,
hasGPOTeams,
expired,
mentions,
unreads,
windowBounds,
)),
},
loadingScreen: {
loadingScreenAnimationFinished: () => ipcRenderer.send(LOADING_SCREEN_ANIMATION_FINISHED),
onToggleLoadingScreenVisibility: (listener) => ipcRenderer.on(TOGGLE_LOADING_SCREEN_VISIBILITY, (_, toggle) => listener(toggle)),
},
modals: {
cancelModal: (data) => ipcRenderer.send(MODAL_CANCEL, data),
finishModal: (data) => ipcRenderer.send(MODAL_RESULT, data),
getModalInfo: () => ipcRenderer.invoke(RETRIEVE_MODAL_INFO),
isModalUncloseable: () => ipcRenderer.invoke(GET_MODAL_UNCLOSEABLE),
confirmProtocol: (protocol, url) => ipcRenderer.send('confirm-protocol', protocol, url),
pingDomain: (url) => ipcRenderer.invoke(PING_DOMAIN, url),
},
});
window.addEventListener('message', async (event) => {
switch (event.data.type) {
case GET_LANGUAGE_INFORMATION:
window.postMessage({type: RETRIEVED_LANGUAGE_INFORMATION, data: await ipcRenderer.invoke(GET_LANGUAGE_INFORMATION)});
break;
}
});
// TODO: This is for modals only, should probably move this out for them
const createKeyDownListener = () => {
ipcRenderer.invoke(GET_MODAL_UNCLOSEABLE).then((uncloseable) => {
window.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && !uncloseable) {
ipcRenderer.send(MODAL_CANCEL);
}
});
});
};
createKeyDownListener();

View File

@@ -1,90 +0,0 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
'use strict';
import {ipcRenderer, contextBridge} from 'electron';
import {
CLOSE_DOWNLOADS_DROPDOWN,
CLOSE_DOWNLOADS_DROPDOWN_MENU,
DOWNLOADS_DROPDOWN_FOCUSED,
DOWNLOADS_DROPDOWN_SHOW_FILE_IN_FOLDER,
GET_LANGUAGE_INFORMATION,
RECEIVE_DOWNLOADS_DROPDOWN_SIZE,
REQUEST_CLEAR_DOWNLOADS_DROPDOWN,
REQUEST_DOWNLOADS_DROPDOWN_INFO,
RETRIEVED_LANGUAGE_INFORMATION,
SEND_DOWNLOADS_DROPDOWN_SIZE,
START_UPDATE_DOWNLOAD,
START_UPGRADE,
TOGGLE_DOWNLOADS_DROPDOWN_MENU,
UPDATE_DOWNLOADS_DROPDOWN,
GET_DOWNLOADED_IMAGE_THUMBNAIL_LOCATION,
DOWNLOADS_DROPDOWN_OPEN_FILE,
} from 'common/communication';
console.log('preloaded for the downloadsDropdown!');
contextBridge.exposeInMainWorld('process', {
platform: process.platform,
});
contextBridge.exposeInMainWorld('mas', {
getThumbnailLocation: (location) => ipcRenderer.invoke(GET_DOWNLOADED_IMAGE_THUMBNAIL_LOCATION, location),
});
window.addEventListener('click', () => {
ipcRenderer.send(CLOSE_DOWNLOADS_DROPDOWN_MENU);
});
window.addEventListener('mousemove', () => {
ipcRenderer.send(DOWNLOADS_DROPDOWN_FOCUSED);
});
/**
* renderer => main
*/
window.addEventListener('message', async (event) => {
switch (event.data.type) {
case CLOSE_DOWNLOADS_DROPDOWN:
ipcRenderer.send(CLOSE_DOWNLOADS_DROPDOWN);
break;
case TOGGLE_DOWNLOADS_DROPDOWN_MENU:
ipcRenderer.send(TOGGLE_DOWNLOADS_DROPDOWN_MENU, event.data.payload);
break;
case REQUEST_DOWNLOADS_DROPDOWN_INFO:
ipcRenderer.send(REQUEST_DOWNLOADS_DROPDOWN_INFO);
break;
case SEND_DOWNLOADS_DROPDOWN_SIZE:
ipcRenderer.send(RECEIVE_DOWNLOADS_DROPDOWN_SIZE, event.data.data.width, event.data.data.height);
break;
case REQUEST_CLEAR_DOWNLOADS_DROPDOWN:
ipcRenderer.send(REQUEST_CLEAR_DOWNLOADS_DROPDOWN);
break;
case DOWNLOADS_DROPDOWN_OPEN_FILE:
ipcRenderer.send(DOWNLOADS_DROPDOWN_OPEN_FILE, event.data.payload.item);
break;
case DOWNLOADS_DROPDOWN_SHOW_FILE_IN_FOLDER:
ipcRenderer.send(DOWNLOADS_DROPDOWN_SHOW_FILE_IN_FOLDER, event.data.payload.item);
break;
case START_UPDATE_DOWNLOAD:
ipcRenderer.send(START_UPDATE_DOWNLOAD);
break;
case START_UPGRADE:
ipcRenderer.send(START_UPGRADE);
break;
case GET_LANGUAGE_INFORMATION:
window.postMessage({type: RETRIEVED_LANGUAGE_INFORMATION, data: await ipcRenderer.invoke(GET_LANGUAGE_INFORMATION)});
break;
default:
console.log('Got an unknown message. Unknown messages are ignored');
}
});
/**
* main => renderer
*/
ipcRenderer.on(UPDATE_DOWNLOADS_DROPDOWN, (event, downloads, darkMode, windowBounds, item) => {
window.postMessage({type: UPDATE_DOWNLOADS_DROPDOWN, data: {downloads, darkMode, windowBounds, item}}, window.location.href);
});

View File

@@ -1,58 +0,0 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
'use strict';
import {ipcRenderer, contextBridge} from 'electron';
import {
GET_LANGUAGE_INFORMATION,
DOWNLOADS_DROPDOWN_MENU_CLEAR_FILE,
RETRIEVED_LANGUAGE_INFORMATION,
DOWNLOADS_DROPDOWN_MENU_SHOW_FILE_IN_FOLDER,
DOWNLOADS_DROPDOWN_MENU_CANCEL_DOWNLOAD,
DOWNLOADS_DROPDOWN_MENU_OPEN_FILE,
UPDATE_DOWNLOADS_DROPDOWN_MENU,
REQUEST_DOWNLOADS_DROPDOWN_MENU_INFO,
} from 'common/communication';
console.log('preloaded for the downloadsDropdownMenu!');
contextBridge.exposeInMainWorld('process', {
platform: process.platform,
});
/**
* renderer => main
*/
window.addEventListener('message', async (event) => {
switch (event.data.type) {
case REQUEST_DOWNLOADS_DROPDOWN_MENU_INFO:
ipcRenderer.send(REQUEST_DOWNLOADS_DROPDOWN_MENU_INFO);
break;
case DOWNLOADS_DROPDOWN_MENU_SHOW_FILE_IN_FOLDER:
ipcRenderer.send(DOWNLOADS_DROPDOWN_MENU_SHOW_FILE_IN_FOLDER, event.data.payload.item);
break;
case DOWNLOADS_DROPDOWN_MENU_CANCEL_DOWNLOAD:
ipcRenderer.send(DOWNLOADS_DROPDOWN_MENU_CANCEL_DOWNLOAD, event.data.payload.item);
break;
case DOWNLOADS_DROPDOWN_MENU_CLEAR_FILE:
ipcRenderer.send(DOWNLOADS_DROPDOWN_MENU_CLEAR_FILE, event.data.payload.item);
break;
case DOWNLOADS_DROPDOWN_MENU_OPEN_FILE:
ipcRenderer.send(DOWNLOADS_DROPDOWN_MENU_OPEN_FILE, event.data.payload.item);
break;
case GET_LANGUAGE_INFORMATION:
window.postMessage({type: RETRIEVED_LANGUAGE_INFORMATION, data: await ipcRenderer.invoke(GET_LANGUAGE_INFORMATION)});
break;
default:
console.log('Got an unknown message. Unknown messages are ignored');
}
});
/**
* main => renderer
*/
ipcRenderer.on(UPDATE_DOWNLOADS_DROPDOWN_MENU, (event, item, darkMode) => {
window.postMessage({type: UPDATE_DOWNLOADS_DROPDOWN_MENU, data: {item, darkMode}}, window.location.href);
});

View File

@@ -1,66 +0,0 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
'use strict';
import {ipcRenderer, contextBridge} from 'electron';
import {
UPDATE_TEAMS_DROPDOWN,
REQUEST_TEAMS_DROPDOWN_INFO,
RECEIVE_DROPDOWN_MENU_SIZE,
SEND_DROPDOWN_MENU_SIZE,
SWITCH_SERVER,
CLOSE_TEAMS_DROPDOWN,
SHOW_NEW_SERVER_MODAL,
SHOW_EDIT_SERVER_MODAL,
SHOW_REMOVE_SERVER_MODAL,
UPDATE_TEAMS,
GET_LANGUAGE_INFORMATION,
RETRIEVED_LANGUAGE_INFORMATION,
} from 'common/communication';
console.log('preloaded for the dropdown!');
contextBridge.exposeInMainWorld('process', {
platform: process.platform,
});
window.addEventListener('message', async (event) => {
switch (event.data.type) {
case REQUEST_TEAMS_DROPDOWN_INFO:
ipcRenderer.send(REQUEST_TEAMS_DROPDOWN_INFO);
break;
case SEND_DROPDOWN_MENU_SIZE:
ipcRenderer.send(RECEIVE_DROPDOWN_MENU_SIZE, event.data.data.width, event.data.data.height);
break;
case SWITCH_SERVER:
ipcRenderer.send(SWITCH_SERVER, event.data.data);
break;
case SHOW_NEW_SERVER_MODAL:
ipcRenderer.send(SHOW_NEW_SERVER_MODAL);
break;
case SHOW_EDIT_SERVER_MODAL:
ipcRenderer.send(SHOW_EDIT_SERVER_MODAL, event.data.data.name);
break;
case SHOW_REMOVE_SERVER_MODAL:
ipcRenderer.send(SHOW_REMOVE_SERVER_MODAL, event.data.data.name);
break;
case CLOSE_TEAMS_DROPDOWN:
ipcRenderer.send(CLOSE_TEAMS_DROPDOWN);
break;
case UPDATE_TEAMS:
ipcRenderer.invoke(UPDATE_TEAMS, event.data.data);
break;
case GET_LANGUAGE_INFORMATION:
window.postMessage({type: RETRIEVED_LANGUAGE_INFORMATION, data: await ipcRenderer.invoke(GET_LANGUAGE_INFORMATION)});
break;
default:
console.log(`got a message: ${event}`);
console.log(event);
}
});
ipcRenderer.on(UPDATE_TEAMS_DROPDOWN, (event, teams, activeTeam, darkMode, enableServerManagement, hasGPOTeams, expired, mentions, unreads, windowBounds) => {
window.postMessage({type: UPDATE_TEAMS_DROPDOWN, data: {teams, activeTeam, darkMode, enableServerManagement, hasGPOTeams, expired, mentions, unreads, windowBounds}}, window.location.href);
});

View File

@@ -1,45 +0,0 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
// Copyright (c) 2015-2016 Yuya Ochiai
'use strict';
import {ipcRenderer} from 'electron';
import {
RECEIVED_LOADING_SCREEN_DATA,
GET_LOADING_SCREEN_DATA,
LOADING_SCREEN_ANIMATION_FINISHED,
TOGGLE_LOADING_SCREEN_VISIBILITY,
CLOSE_TEAMS_DROPDOWN,
CLOSE_DOWNLOADS_DROPDOWN,
} from 'common/communication';
console.log('preloaded for the loading screen!');
window.addEventListener('message', async (event) => {
switch (event.data.type) {
case GET_LOADING_SCREEN_DATA:
window.postMessage({type: RECEIVED_LOADING_SCREEN_DATA, data: await ipcRenderer.invoke(GET_LOADING_SCREEN_DATA)}, window.location.href);
break;
case LOADING_SCREEN_ANIMATION_FINISHED:
ipcRenderer.send(LOADING_SCREEN_ANIMATION_FINISHED);
break;
default:
console.log(`got a message: ${event}`);
console.log(event);
}
});
ipcRenderer.on(GET_LOADING_SCREEN_DATA, (_, result) => {
window.postMessage({type: RECEIVED_LOADING_SCREEN_DATA, data: result}, window.location.href);
});
ipcRenderer.on(TOGGLE_LOADING_SCREEN_VISIBILITY, (_, toggle) => {
window.postMessage({type: TOGGLE_LOADING_SCREEN_VISIBILITY, data: toggle}, window.location.href);
});
window.addEventListener('click', () => {
ipcRenderer.send(CLOSE_TEAMS_DROPDOWN);
ipcRenderer.send(CLOSE_DOWNLOADS_DROPDOWN);
});

View File

@@ -1,88 +0,0 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
// Copyright (c) 2015-2016 Yuya Ochiai
'use strict';
import {ipcRenderer} from 'electron';
import {
MODAL_CANCEL,
MODAL_RESULT,
MODAL_INFO,
RETRIEVE_MODAL_INFO,
MODAL_SEND_IPC_MESSAGE,
GET_DARK_MODE,
DARK_MODE_CHANGE,
GET_MODAL_UNCLOSEABLE,
MODAL_UNCLOSEABLE,
PING_DOMAIN,
PING_DOMAIN_RESPONSE,
GET_LANGUAGE_INFORMATION,
RETRIEVED_LANGUAGE_INFORMATION,
} from 'common/communication';
console.log('preloaded for the modal!');
let uncloseable = false;
const createKeyDownListener = () => {
window.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && !uncloseable) {
ipcRenderer.send(MODAL_CANCEL);
}
});
};
window.addEventListener('message', async (event) => {
switch (event.data.type) {
case MODAL_CANCEL: {
console.log('canceling modal');
ipcRenderer.send(MODAL_CANCEL, event.data.data);
break;
}
case MODAL_RESULT: {
console.log(`accepting modal with ${event.data.data}`);
ipcRenderer.send(MODAL_RESULT, event.data.data);
break;
}
case RETRIEVE_MODAL_INFO:
console.log('getting modal data');
window.postMessage({type: MODAL_INFO, data: await ipcRenderer.invoke(RETRIEVE_MODAL_INFO)}, window.location.href);
break;
case GET_MODAL_UNCLOSEABLE:
console.log('get modal uncloseable');
uncloseable = await ipcRenderer.invoke(GET_MODAL_UNCLOSEABLE);
createKeyDownListener();
window.postMessage({type: MODAL_UNCLOSEABLE, data: uncloseable}, window.location.href);
break;
case MODAL_SEND_IPC_MESSAGE:
console.log('sending custom ipc message');
ipcRenderer.send(event.data.data.type, ...event.data.data.args);
break;
case GET_DARK_MODE:
console.log('getting dark mode value');
window.postMessage({type: DARK_MODE_CHANGE, data: await ipcRenderer.invoke(GET_DARK_MODE)}, window.location.href);
break;
case PING_DOMAIN:
console.log('pinging domain: ' + event.data.data);
try {
const protocol = await ipcRenderer.invoke(PING_DOMAIN, event.data.data);
window.postMessage({type: PING_DOMAIN_RESPONSE, data: protocol}, window.location.href);
} catch (error) {
window.postMessage({type: PING_DOMAIN_RESPONSE, data: error}, window.location.href);
}
break;
case GET_LANGUAGE_INFORMATION:
window.postMessage({type: RETRIEVED_LANGUAGE_INFORMATION, data: await ipcRenderer.invoke(GET_LANGUAGE_INFORMATION)});
break;
default:
console.log(`got a message: ${event}`);
console.log(event);
}
});
createKeyDownListener();
ipcRenderer.on(DARK_MODE_CHANGE, (event, darkMode) => {
window.postMessage({type: DARK_MODE_CHANGE, data: darkMode}, window.location.href);
});

View File

@@ -1,22 +0,0 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
// Copyright (c) 2015-2016 Yuya Ochiai
'use strict';
import {ipcRenderer} from 'electron';
import {UPDATE_URL_VIEW_WIDTH} from 'common/communication';
console.log('preloaded for the url view');
window.addEventListener('message', async (event) => {
switch (event.data.type) {
case UPDATE_URL_VIEW_WIDTH:
ipcRenderer.send(UPDATE_URL_VIEW_WIDTH, event.data.data);
break;
default:
console.log(`got a message: ${event}`);
console.log(event);
}
});

View File

@@ -51,7 +51,7 @@ export default class DownloadsDropdownMenuView {
this.windowBounds = this.window.getContentBounds();
this.bounds = this.getBounds(DOWNLOADS_DROPDOWN_MENU_FULL_WIDTH, DOWNLOADS_DROPDOWN_MENU_FULL_HEIGHT);
const preload = getLocalPreload('downloadsDropdownMenu.js');
const preload = getLocalPreload('desktopAPI.js');
this.view = new BrowserView({webPreferences: {
preload,

View File

@@ -10,7 +10,6 @@ import {DownloadedItem, DownloadedItems} from 'types/downloads';
import {
CLOSE_DOWNLOADS_DROPDOWN,
DOWNLOADS_DROPDOWN_SHOW_FILE_IN_FOLDER,
EMIT_CONFIGURATION,
OPEN_DOWNLOADS_DROPDOWN,
RECEIVE_DOWNLOADS_DROPDOWN_SIZE,
@@ -45,7 +44,7 @@ export default class DownloadsDropdownView {
this.windowBounds = this.window.getContentBounds();
this.bounds = this.getBounds(DOWNLOADS_DROPDOWN_FULL_WIDTH, DOWNLOADS_DROPDOWN_HEIGHT);
const preload = getLocalPreload('downloadsDropdown.js');
const preload = getLocalPreload('desktopAPI.js');
this.view = new BrowserView({webPreferences: {
preload,
@@ -67,7 +66,6 @@ export default class DownloadsDropdownView {
ipcMain.on(REQUEST_CLEAR_DOWNLOADS_DROPDOWN, this.clearDownloads);
ipcMain.on(RECEIVE_DOWNLOADS_DROPDOWN_SIZE, this.handleReceivedDownloadsDropdownSize);
ipcMain.on(DOWNLOADS_DROPDOWN_OPEN_FILE, this.openFile);
ipcMain.on(DOWNLOADS_DROPDOWN_SHOW_FILE_IN_FOLDER, this.showFileInFolder);
ipcMain.on(UPDATE_DOWNLOADS_DROPDOWN, this.updateDownloads);
ipcMain.on(UPDATE_DOWNLOADS_DROPDOWN_MENU_ITEM, this.updateDownloadsDropdownMenuItem);
ipcMain.handle(GET_DOWNLOADED_IMAGE_THUMBNAIL_LOCATION, this.getDownloadImageThumbnailLocation);
@@ -151,12 +149,6 @@ export default class DownloadsDropdownView {
downloadsManager.openFile(item);
}
showFileInFolder = (e: IpcMainEvent, item: DownloadedItem) => {
log.debug('DownloadsDropdownView.showFileInFolder', {item});
downloadsManager.showFileInFolder(item);
}
getBounds = (width: number, height: number) => {
// Must always use integers
return {

View File

@@ -46,7 +46,7 @@ export default class TeamDropdownView {
this.windowBounds = this.window.getContentBounds();
const preload = getLocalPreload('dropdown.js');
const preload = getLocalPreload('desktopAPI.js');
this.view = new BrowserView({webPreferences: {
preload,
@@ -105,14 +105,14 @@ export default class TeamDropdownView {
this.view.webContents.send(
UPDATE_TEAMS_DROPDOWN,
this.teams,
this.activeTeam,
this.darkMode,
this.windowBounds,
this.activeTeam,
this.enableServerManagement,
this.hasGPOTeams,
this.expired,
this.mentions,
this.unreads,
this.windowBounds,
);
}

View File

@@ -13,7 +13,6 @@ import {
LOAD_SUCCESS,
LOAD_FAILED,
TOGGLE_LOADING_SCREEN_VISIBILITY,
GET_LOADING_SCREEN_DATA,
LOADSCREEN_END,
SET_ACTIVE_VIEW,
OPEN_TAB,
@@ -21,6 +20,7 @@ import {
UPDATE_LAST_ACTIVE,
UPDATE_URL_VIEW_WIDTH,
MAIN_WINDOW_SHOWN,
DARK_MODE_CHANGE,
} from 'common/communication';
import Config from 'common/config';
import urlUtils, {equalUrlsIgnoringSubpath} from 'common/utils/url';
@@ -362,7 +362,7 @@ export class ViewManager {
}
if (url && url !== '') {
const urlString = typeof url === 'string' ? url : url.toString();
const preload = getLocalPreload('urlView.js');
const preload = getLocalPreload('desktopAPI.js');
const urlView = new BrowserView({
webPreferences: {
preload,
@@ -427,7 +427,7 @@ export class ViewManager {
}
createLoadingScreen = () => {
const preload = getLocalPreload('loadingScreenPreload.js');
const preload = getLocalPreload('desktopAPI.js');
this.loadingScreen = new BrowserView({webPreferences: {
preload,
@@ -490,7 +490,7 @@ export class ViewManager {
updateLoadingScreenDarkMode = (darkMode: boolean) => {
if (this.loadingScreen) {
this.loadingScreen.webContents.send(GET_LOADING_SCREEN_DATA, {darkMode});
this.loadingScreen.webContents.send(DARK_MODE_CHANGE, darkMode);
}
}

View File

@@ -46,7 +46,7 @@ function isFramelessWindow() {
function createMainWindow(options: {linuxAppIcon: string; fullscreen?: boolean}) {
// Create the browser window.
const preload = getLocalPreload('mainWindow.js');
const preload = getLocalPreload('desktopAPI.js');
let savedWindowState: any;
try {
savedWindowState = JSON.parse(fs.readFileSync(boundsInfoPath, 'utf-8'));

View File

@@ -10,7 +10,7 @@ import ContextMenu from '../contextMenu';
import {getLocalPreload, getLocalURLString} from '../utils';
export function createSettingsWindow(mainWindow: BrowserWindow, withDevTools: boolean) {
const preload = getLocalPreload('mainWindow.js');
const preload = getLocalPreload('desktopAPI.js');
const spellcheck = (typeof Config.useSpellChecker === 'undefined' ? true : Config.useSpellChecker);
const settingsWindow = new BrowserWindow({
parent: mainWindow,

View File

@@ -14,7 +14,6 @@ import {
import {
MAXIMIZE_CHANGE,
HISTORY,
GET_LOADING_SCREEN_DATA,
REACT_APP_INITIALIZED,
LOADING_SCREEN_ANIMATION_FINISHED,
FOCUS_THREE_DOT_MENU,
@@ -79,7 +78,6 @@ export class WindowManager {
this.assetsDir = path.resolve(app.getAppPath(), 'assets');
ipcMain.on(HISTORY, this.handleHistory);
ipcMain.handle(GET_LOADING_SCREEN_DATA, this.handleLoadingScreenDataRequest);
ipcMain.handle(GET_DARK_MODE, this.handleGetDarkMode);
ipcMain.on(REACT_APP_INITIALIZED, this.handleReactAppInitialized);
ipcMain.on(LOADING_SCREEN_ANIMATION_FINISHED, this.handleLoadingScreenAnimationFinished);