2016-11-02 18:49:28 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
/*
|
|
|
|
Copyright 2016 Aviral Dasgupta
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
2018-12-18 17:42:55 +00:00
|
|
|
Copyright 2018 New Vector Ltd
|
2019-06-26 21:08:04 +01:00
|
|
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
2020-03-02 15:01:06 +00:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
2016-11-02 18:49:28 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-06-11 19:19:17 +01:00
|
|
|
import VectorBasePlatform, {updateCheckStatusEnum} from './VectorBasePlatform';
|
2019-12-19 18:47:40 -07:00
|
|
|
import BaseEventIndexManager from 'matrix-react-sdk/src/indexing/BaseEventIndexManager';
|
2020-05-13 21:15:30 -06:00
|
|
|
import dis from 'matrix-react-sdk/src/dispatcher/dispatcher';
|
2020-03-19 23:42:10 +00:00
|
|
|
import { _t, _td } from 'matrix-react-sdk/src/languageHandler';
|
2019-12-19 18:47:40 -07:00
|
|
|
import * as rageshake from 'matrix-react-sdk/src/rageshake/rageshake';
|
2020-03-02 14:59:55 +00:00
|
|
|
import {MatrixClient} from "matrix-js-sdk";
|
|
|
|
import Modal from "matrix-react-sdk/src/Modal";
|
|
|
|
import InfoDialog from "matrix-react-sdk/src/components/views/dialogs/InfoDialog";
|
|
|
|
import Spinner from "matrix-react-sdk/src/components/views/elements/Spinner";
|
2020-03-19 23:42:10 +00:00
|
|
|
import {Categories, Modifiers, registerShortcut} from "matrix-react-sdk/src/accessibility/KeyboardShortcuts";
|
|
|
|
import {Key} from "matrix-react-sdk/src/Keyboard";
|
2020-03-02 14:59:55 +00:00
|
|
|
import React from "react";
|
2020-04-09 21:17:37 +01:00
|
|
|
import {randomString} from "matrix-js-sdk/src/randomstring";
|
2020-05-13 21:15:30 -06:00
|
|
|
import {Action} from "matrix-react-sdk/src/dispatcher/actions";
|
2016-11-03 15:45:12 +00:00
|
|
|
|
2018-12-18 18:03:47 +00:00
|
|
|
const ipcRenderer = window.ipcRenderer;
|
2020-03-19 23:42:10 +00:00
|
|
|
const isMac = navigator.platform.toUpperCase().includes('MAC');
|
|
|
|
|
2017-05-02 21:29:19 +01:00
|
|
|
function platformFriendlyName(): string {
|
2018-12-18 17:42:55 +00:00
|
|
|
// used to use window.process but the same info is available here
|
2019-01-23 16:53:50 +00:00
|
|
|
if (navigator.userAgent.includes('Macintosh')) {
|
2018-12-18 17:42:55 +00:00
|
|
|
return 'macOS';
|
2019-01-23 16:53:50 +00:00
|
|
|
} else if (navigator.userAgent.includes('FreeBSD')) {
|
2018-12-18 17:42:55 +00:00
|
|
|
return 'FreeBSD';
|
2019-01-23 16:53:50 +00:00
|
|
|
} else if (navigator.userAgent.includes('OpenBSD')) {
|
2018-12-18 17:42:55 +00:00
|
|
|
return 'OpenBSD';
|
2019-01-23 16:53:50 +00:00
|
|
|
} else if (navigator.userAgent.includes('SunOS')) {
|
2018-12-18 17:42:55 +00:00
|
|
|
return 'SunOS';
|
2019-01-23 16:53:50 +00:00
|
|
|
} else if (navigator.userAgent.includes('Windows')) {
|
2018-12-18 17:42:55 +00:00
|
|
|
return 'Windows';
|
2019-01-23 16:53:50 +00:00
|
|
|
} else if (navigator.userAgent.includes('Linux')) {
|
2018-12-18 17:42:55 +00:00
|
|
|
return 'Linux';
|
|
|
|
} else {
|
|
|
|
return 'Unknown';
|
2016-11-24 16:46:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-22 18:30:45 +01:00
|
|
|
function _onAction(payload: Object) {
|
|
|
|
// Whitelist payload actions, no point sending most across
|
|
|
|
if (['call_state'].includes(payload.action)) {
|
|
|
|
ipcRenderer.send('app_onAction', payload);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-11 19:19:17 +01:00
|
|
|
function getUpdateCheckStatus(status) {
|
|
|
|
if (status === true) {
|
|
|
|
return { status: updateCheckStatusEnum.DOWNLOADING };
|
|
|
|
} else if (status === false) {
|
|
|
|
return { status: updateCheckStatusEnum.NOTAVAILABLE };
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
status: updateCheckStatusEnum.ERROR,
|
|
|
|
detail: status,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-19 12:43:01 +01:00
|
|
|
class SeshatIndexManager extends BaseEventIndexManager {
|
2019-11-13 12:15:26 +01:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this._pendingIpcCalls = {};
|
|
|
|
this._nextIpcCallId = 0;
|
|
|
|
ipcRenderer.on('seshatReply', this._onIpcReply.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
async _ipcCall(name: string, ...args: []): Promise<{}> {
|
|
|
|
// TODO this should be moved into the preload.js file.
|
|
|
|
const ipcCallId = ++this._nextIpcCallId;
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
this._pendingIpcCalls[ipcCallId] = {resolve, reject};
|
|
|
|
window.ipcRenderer.send('seshat', {id: ipcCallId, name, args});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_onIpcReply(ev: {}, payload: {}) {
|
|
|
|
if (payload.id === undefined) {
|
|
|
|
console.warn("Ignoring IPC reply with no ID");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._pendingIpcCalls[payload.id] === undefined) {
|
|
|
|
console.warn("Unknown IPC payload ID: " + payload.id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const callbacks = this._pendingIpcCalls[payload.id];
|
|
|
|
delete this._pendingIpcCalls[payload.id];
|
|
|
|
if (payload.error) {
|
|
|
|
callbacks.reject(payload.error);
|
|
|
|
} else {
|
|
|
|
callbacks.resolve(payload.reply);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async supportsEventIndexing(): Promise<boolean> {
|
|
|
|
return this._ipcCall('supportsEventIndexing');
|
|
|
|
}
|
|
|
|
|
2019-11-14 14:14:59 +01:00
|
|
|
async initEventIndex(): Promise<> {
|
|
|
|
return this._ipcCall('initEventIndex');
|
2019-11-13 12:15:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async addEventToIndex(ev: MatrixEvent, profile: MatrixProfile): Promise<> {
|
|
|
|
return this._ipcCall('addEventToIndex', ev, profile);
|
|
|
|
}
|
|
|
|
|
2020-03-12 11:50:49 +01:00
|
|
|
async deleteEvent(eventId: string): Promise<boolean> {
|
|
|
|
return this._ipcCall('deleteEvent', eventId);
|
|
|
|
}
|
|
|
|
|
2019-11-13 12:15:26 +01:00
|
|
|
async isEventIndexEmpty(): Promise<boolean> {
|
|
|
|
return this._ipcCall('isEventIndexEmpty');
|
|
|
|
}
|
|
|
|
|
|
|
|
async commitLiveEvents(): Promise<> {
|
|
|
|
return this._ipcCall('commitLiveEvents');
|
|
|
|
}
|
|
|
|
|
|
|
|
async searchEventIndex(searchConfig: SearchConfig): Promise<SearchResult> {
|
|
|
|
return this._ipcCall('searchEventIndex', searchConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
async addHistoricEvents(
|
|
|
|
events: [HistoricEvent],
|
2019-11-19 12:43:43 +01:00
|
|
|
checkpoint: CrawlerCheckpoint | null,
|
|
|
|
oldCheckpoint: CrawlerCheckpoint | null,
|
2019-11-13 12:15:26 +01:00
|
|
|
): Promise<> {
|
|
|
|
return this._ipcCall('addHistoricEvents', events, checkpoint, oldCheckpoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
async addCrawlerCheckpoint(checkpoint: CrawlerCheckpoint): Promise<> {
|
|
|
|
return this._ipcCall('addCrawlerCheckpoint', checkpoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
async removeCrawlerCheckpoint(checkpoint: CrawlerCheckpoint): Promise<> {
|
|
|
|
return this._ipcCall('removeCrawlerCheckpoint', checkpoint);
|
|
|
|
}
|
|
|
|
|
2020-01-17 10:06:54 +01:00
|
|
|
async loadFileEvents(args): Promise<[EventAndProfile]> {
|
|
|
|
return this._ipcCall('loadFileEvents', args);
|
|
|
|
}
|
|
|
|
|
2019-11-13 12:15:26 +01:00
|
|
|
async loadCheckpoints(): Promise<[CrawlerCheckpoint]> {
|
|
|
|
return this._ipcCall('loadCheckpoints');
|
|
|
|
}
|
|
|
|
|
2019-11-14 16:14:48 +01:00
|
|
|
async closeEventIndex(): Promise<> {
|
|
|
|
return this._ipcCall('closeEventIndex');
|
|
|
|
}
|
|
|
|
|
2020-01-21 13:33:20 +01:00
|
|
|
async getStats(): Promise<> {
|
|
|
|
return this._ipcCall('getStats');
|
2019-11-13 12:15:26 +01:00
|
|
|
}
|
2019-11-22 11:02:52 +01:00
|
|
|
|
2019-11-13 12:15:26 +01:00
|
|
|
async deleteEventIndex(): Promise<> {
|
|
|
|
return this._ipcCall('deleteEventIndex');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 18:49:28 +00:00
|
|
|
export default class ElectronPlatform extends VectorBasePlatform {
|
2017-05-22 18:30:45 +01:00
|
|
|
constructor() {
|
|
|
|
super();
|
2017-06-11 19:19:17 +01:00
|
|
|
|
2018-12-18 17:42:55 +00:00
|
|
|
this._pendingIpcCalls = {};
|
|
|
|
this._nextIpcCallId = 0;
|
2019-11-19 12:43:01 +01:00
|
|
|
this.eventIndexManager = new SeshatIndexManager();
|
2018-12-18 17:42:55 +00:00
|
|
|
|
|
|
|
dis.register(_onAction);
|
2017-06-11 19:19:17 +01:00
|
|
|
/*
|
|
|
|
IPC Call `check_updates` returns:
|
|
|
|
true if there is an update available
|
|
|
|
false if there is not
|
|
|
|
or the error if one is encountered
|
|
|
|
*/
|
|
|
|
ipcRenderer.on('check_updates', (event, status) => {
|
|
|
|
if (!this.showUpdateCheck) return;
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'check_updates',
|
|
|
|
value: getUpdateCheckStatus(status),
|
|
|
|
});
|
|
|
|
this.showUpdateCheck = false;
|
|
|
|
});
|
|
|
|
|
2018-12-18 17:42:55 +00:00
|
|
|
// try to flush the rageshake logs to indexeddb before quit.
|
|
|
|
ipcRenderer.on('before-quit', function() {
|
|
|
|
console.log('riot-desktop closing');
|
|
|
|
rageshake.flush();
|
|
|
|
});
|
|
|
|
|
|
|
|
ipcRenderer.on('ipcReply', this._onIpcReply.bind(this));
|
|
|
|
ipcRenderer.on('update-downloaded', this.onUpdateDownloaded.bind(this));
|
|
|
|
|
2020-03-19 23:42:10 +00:00
|
|
|
ipcRenderer.on('preferences', () => {
|
2020-05-13 21:15:30 -06:00
|
|
|
dis.fire(Action.ViewUserSettings);
|
2020-03-19 23:42:10 +00:00
|
|
|
});
|
|
|
|
|
2017-06-11 19:19:17 +01:00
|
|
|
this.startUpdateCheck = this.startUpdateCheck.bind(this);
|
|
|
|
this.stopUpdateCheck = this.stopUpdateCheck.bind(this);
|
2020-04-03 13:01:28 +01:00
|
|
|
|
2020-04-11 18:58:00 +01:00
|
|
|
// register OS-specific shortcuts
|
2020-04-03 13:01:28 +01:00
|
|
|
if (isMac) {
|
|
|
|
registerShortcut(Categories.NAVIGATION, {
|
|
|
|
keybinds: [{
|
|
|
|
modifiers: [Modifiers.COMMAND],
|
|
|
|
key: Key.COMMA,
|
|
|
|
}],
|
|
|
|
description: _td("Open user settings"),
|
|
|
|
});
|
2020-04-11 18:58:00 +01:00
|
|
|
|
|
|
|
registerShortcut(Categories.NAVIGATION, {
|
|
|
|
keybinds: [{
|
|
|
|
modifiers: [Modifiers.COMMAND],
|
|
|
|
key: Key.SQUARE_BRACKET_LEFT,
|
|
|
|
}, {
|
|
|
|
modifiers: [Modifiers.COMMAND],
|
|
|
|
key: Key.SQUARE_BRACKET_RIGHT,
|
|
|
|
}],
|
|
|
|
description: _td("Previous/next recently visited room or community"),
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
registerShortcut(Categories.NAVIGATION, {
|
|
|
|
keybinds: [{
|
|
|
|
modifiers: [Modifiers.ALT],
|
|
|
|
key: Key.ARROW_LEFT,
|
|
|
|
}, {
|
|
|
|
modifiers: [Modifiers.ALT],
|
|
|
|
key: Key.ARROW_RIGHT,
|
|
|
|
}],
|
|
|
|
description: _td("Previous/next recently visited room or community"),
|
|
|
|
});
|
2020-04-03 13:01:28 +01:00
|
|
|
}
|
2020-04-04 00:22:15 +01:00
|
|
|
|
2020-04-09 21:17:37 +01:00
|
|
|
// this is the opaque token we pass to the HS which when we get it in our callback we can resolve to a profile
|
|
|
|
this.ssoID = randomString(32);
|
|
|
|
this._ipcCall("startSSOFlow", this.ssoID);
|
2017-05-22 18:30:45 +01:00
|
|
|
}
|
|
|
|
|
2019-06-26 21:08:04 +01:00
|
|
|
async getConfig(): Promise<{}> {
|
|
|
|
return this._ipcCall('getConfig');
|
|
|
|
}
|
|
|
|
|
2018-12-18 17:42:55 +00:00
|
|
|
async onUpdateDownloaded(ev, updateInfo) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'new_version',
|
|
|
|
currentVersion: await this.getAppVersion(),
|
|
|
|
newVersion: updateInfo,
|
|
|
|
releaseNotes: updateInfo.releaseNotes,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-29 20:03:21 +01:00
|
|
|
getHumanReadableName(): string {
|
2017-05-31 14:51:08 +01:00
|
|
|
return 'Electron Platform'; // no translation required: only used for analytics
|
2017-05-29 19:51:28 +01:00
|
|
|
}
|
|
|
|
|
2016-11-02 18:49:28 +00:00
|
|
|
setNotificationCount(count: number) {
|
2017-01-26 12:58:29 +00:00
|
|
|
if (this.notificationCount === count) return;
|
2016-11-02 18:49:28 +00:00
|
|
|
super.setNotificationCount(count);
|
2017-05-17 10:39:43 +01:00
|
|
|
|
|
|
|
ipcRenderer.send('setBadgeCount', count);
|
2016-11-02 18:49:28 +00:00
|
|
|
}
|
|
|
|
|
2017-05-02 21:29:19 +01:00
|
|
|
supportsNotifications(): boolean {
|
2016-11-02 18:49:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-02 21:29:19 +01:00
|
|
|
maySendNotifications(): boolean {
|
2016-11-02 18:49:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-06 13:28:59 +00:00
|
|
|
displayNotification(title: string, msg: string, avatarUrl: string, room: Object): Notification {
|
2017-04-03 20:30:05 +01:00
|
|
|
// GNOME notification spec parses HTML tags for styling...
|
|
|
|
// Electron Docs state all supported linux notification systems follow this markup spec
|
|
|
|
// https://github.com/electron/electron/blob/master/docs/tutorial/desktop-environment-integration.md#linux
|
|
|
|
// maybe we should pass basic styling (italics, bold, underline) through from MD
|
2017-04-22 16:05:08 +01:00
|
|
|
// we only have to strip out < and > as the spec doesn't include anything about things like &
|
|
|
|
// so we shouldn't assume that all implementations will treat those properly. Very basic tag parsing is done.
|
2019-01-23 14:47:31 +00:00
|
|
|
if (navigator.userAgent.includes('Linux')) {
|
2017-04-23 09:59:00 +01:00
|
|
|
msg = msg.replace(/</g, '<').replace(/>/g, '>');
|
2017-04-03 20:30:05 +01:00
|
|
|
}
|
|
|
|
|
2016-11-02 18:49:28 +00:00
|
|
|
// Notifications in Electron use the HTML5 notification API
|
2019-05-30 20:04:16 -06:00
|
|
|
const notifBody = {
|
|
|
|
body: msg,
|
|
|
|
silent: true, // we play our own sounds
|
|
|
|
};
|
|
|
|
if (avatarUrl) notifBody['icon'] = avatarUrl;
|
|
|
|
const notification = new global.Notification(title, notifBody);
|
2016-11-02 18:49:28 +00:00
|
|
|
|
2018-12-18 17:42:55 +00:00
|
|
|
notification.onclick = () => {
|
2016-11-02 18:49:28 +00:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
2017-04-23 09:56:43 +01:00
|
|
|
room_id: room.roomId,
|
2016-11-02 18:49:28 +00:00
|
|
|
});
|
|
|
|
global.focus();
|
2018-12-18 17:42:55 +00:00
|
|
|
this._ipcCall('focusWindow');
|
2016-11-02 18:49:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return notification;
|
|
|
|
}
|
|
|
|
|
2017-06-01 00:00:00 +01:00
|
|
|
loudNotification(ev: Event, room: Object) {
|
|
|
|
ipcRenderer.send('loudNotification');
|
|
|
|
}
|
|
|
|
|
2016-11-02 18:49:28 +00:00
|
|
|
clearNotification(notif: Notification) {
|
|
|
|
notif.close();
|
|
|
|
}
|
|
|
|
|
2018-12-18 17:42:55 +00:00
|
|
|
async getAppVersion(): Promise<string> {
|
2019-08-05 11:58:16 +01:00
|
|
|
return this._ipcCall('getAppVersion');
|
2018-12-18 17:42:55 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 01:21:18 +00:00
|
|
|
supportsAutoLaunch(): boolean {
|
2018-12-18 17:42:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-02-24 01:21:18 +00:00
|
|
|
async getAutoLaunchEnabled(): boolean {
|
2019-08-05 11:58:16 +01:00
|
|
|
return this._ipcCall('getAutoLaunchEnabled');
|
2018-12-18 17:42:55 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 01:38:21 +00:00
|
|
|
async setAutoLaunchEnabled(enabled: boolean): void {
|
2019-08-05 11:58:16 +01:00
|
|
|
return this._ipcCall('setAutoLaunchEnabled', enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
supportsAutoHideMenuBar(): boolean {
|
2019-11-05 20:31:08 +00:00
|
|
|
// This is irelevant on Mac as Menu bars don't live in the app window
|
2020-03-19 23:42:10 +00:00
|
|
|
return !isMac;
|
2019-08-05 11:58:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async getAutoHideMenuBarEnabled(): boolean {
|
|
|
|
return this._ipcCall('getAutoHideMenuBarEnabled');
|
|
|
|
}
|
|
|
|
|
|
|
|
async setAutoHideMenuBarEnabled(enabled: boolean): void {
|
|
|
|
return this._ipcCall('setAutoHideMenuBarEnabled', enabled);
|
2018-12-18 17:42:55 +00:00
|
|
|
}
|
|
|
|
|
2019-10-30 14:32:28 +00:00
|
|
|
supportsMinimizeToTray(): boolean {
|
2019-10-29 11:37:42 +00:00
|
|
|
// Things other than Mac support tray icons
|
2020-03-19 23:42:10 +00:00
|
|
|
return !isMac;
|
2019-10-29 11:37:42 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 01:21:18 +00:00
|
|
|
async getMinimizeToTrayEnabled(): boolean {
|
2019-08-05 11:58:16 +01:00
|
|
|
return this._ipcCall('getMinimizeToTrayEnabled');
|
2019-02-24 01:08:01 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 01:38:21 +00:00
|
|
|
async setMinimizeToTrayEnabled(enabled: boolean): void {
|
2019-08-05 11:58:16 +01:00
|
|
|
return this._ipcCall('setMinimizeToTrayEnabled', enabled);
|
2019-02-24 01:08:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-18 17:42:55 +00:00
|
|
|
async canSelfUpdate(): boolean {
|
|
|
|
const feedUrl = await this._ipcCall('getUpdateFeedUrl');
|
|
|
|
return Boolean(feedUrl);
|
2016-11-08 10:47:01 +00:00
|
|
|
}
|
|
|
|
|
2017-06-11 19:19:17 +01:00
|
|
|
startUpdateCheck() {
|
|
|
|
if (this.showUpdateCheck) return;
|
|
|
|
super.startUpdateCheck();
|
2017-06-03 15:12:46 +01:00
|
|
|
|
2017-06-11 19:19:17 +01:00
|
|
|
ipcRenderer.send('check_updates');
|
2016-11-02 18:49:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
installUpdate() {
|
|
|
|
// IPC to the main process to install the update, since quitAndInstall
|
|
|
|
// doesn't fire the before-quit event so the main process needs to know
|
|
|
|
// it should exit.
|
2017-06-11 19:19:17 +01:00
|
|
|
ipcRenderer.send('install_update');
|
2016-11-02 18:49:28 +00:00
|
|
|
}
|
2016-11-24 16:46:15 +00:00
|
|
|
|
2017-05-02 21:29:19 +01:00
|
|
|
getDefaultDeviceDisplayName(): string {
|
2020-04-30 16:50:01 +01:00
|
|
|
return _t('Riot Desktop (%(platformName)s)', { platformName: platformFriendlyName() });
|
2016-11-24 16:46:15 +00:00
|
|
|
}
|
2017-01-10 18:39:21 +00:00
|
|
|
|
2017-05-02 21:29:19 +01:00
|
|
|
screenCaptureErrorString(): ?string {
|
2017-01-10 18:39:21 +00:00
|
|
|
return null;
|
|
|
|
}
|
2017-01-19 13:25:56 +00:00
|
|
|
|
2017-05-02 21:29:19 +01:00
|
|
|
requestNotificationPermission(): Promise<string> {
|
2017-07-13 00:32:07 +01:00
|
|
|
return Promise.resolve('granted');
|
2017-01-19 13:25:56 +00:00
|
|
|
}
|
2017-04-10 17:40:09 +01:00
|
|
|
|
|
|
|
reload() {
|
2018-12-18 17:42:55 +00:00
|
|
|
// we used to remote to the main process to get it to
|
|
|
|
// reload the webcontents, but in practice this is unnecessary:
|
|
|
|
// the normal way works fine.
|
|
|
|
window.location.reload(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
async _ipcCall(name, ...args) {
|
|
|
|
const ipcCallId = ++this._nextIpcCallId;
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
this._pendingIpcCalls[ipcCallId] = {resolve, reject};
|
|
|
|
window.ipcRenderer.send('ipcCall', {id: ipcCallId, name, args});
|
|
|
|
// Maybe add a timeout to these? Probably not necessary.
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_onIpcReply(ev, payload) {
|
|
|
|
if (payload.id === undefined) {
|
|
|
|
console.warn("Ignoring IPC reply with no ID");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._pendingIpcCalls[payload.id] === undefined) {
|
|
|
|
console.warn("Unknown IPC payload ID: " + payload.id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const callbacks = this._pendingIpcCalls[payload.id];
|
|
|
|
delete this._pendingIpcCalls[payload.id];
|
|
|
|
if (payload.error) {
|
|
|
|
callbacks.reject(payload.error);
|
|
|
|
} else {
|
|
|
|
callbacks.resolve(payload.reply);
|
|
|
|
}
|
2017-09-04 09:33:08 +02:00
|
|
|
}
|
2019-10-11 16:05:14 +02:00
|
|
|
|
2019-11-13 12:15:26 +01:00
|
|
|
getEventIndexingManager(): BaseEventIndexManager | null {
|
|
|
|
return this.eventIndexManager;
|
2019-10-11 16:05:14 +02:00
|
|
|
}
|
2020-02-24 17:14:23 +00:00
|
|
|
|
2020-02-25 10:57:41 +00:00
|
|
|
setLanguage(preferredLangs: string[]) {
|
|
|
|
this._ipcCall('setLanguage', preferredLangs).catch(error => {
|
|
|
|
console.log("Failed to send setLanguage IPC to Electron");
|
|
|
|
console.error(error);
|
|
|
|
});
|
2020-02-24 17:14:23 +00:00
|
|
|
}
|
2020-03-02 14:59:55 +00:00
|
|
|
|
2020-05-13 06:24:05 +01:00
|
|
|
getSSOCallbackUrl(hsUrl: string, isUrl: string, fragmentAfterLogin: string): URL {
|
|
|
|
const url = super.getSSOCallbackUrl(hsUrl, isUrl, fragmentAfterLogin);
|
2020-03-02 14:59:55 +00:00
|
|
|
url.protocol = "riot";
|
2020-04-09 21:17:37 +01:00
|
|
|
url.searchParams.set("riot-desktop-ssoid", this.ssoID);
|
2020-03-02 14:59:55 +00:00
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2020-05-13 06:24:05 +01:00
|
|
|
startSingleSignOn(mxClient: MatrixClient, loginType: "sso" | "cas", fragmentAfterLogin: string) {
|
|
|
|
// this will get intercepted by electron-main will-navigate
|
|
|
|
super.startSingleSignOn(mxClient, loginType, fragmentAfterLogin);
|
2020-03-02 14:59:55 +00:00
|
|
|
Modal.createTrackedDialog('Electron', 'SSO', InfoDialog, {
|
2020-03-02 20:04:31 +00:00
|
|
|
title: _t("Go to your browser to complete Sign In"),
|
|
|
|
description: <Spinner />,
|
2020-03-02 14:59:55 +00:00
|
|
|
});
|
|
|
|
}
|
2020-04-11 18:58:00 +01:00
|
|
|
|
|
|
|
_navigateForwardBack(back: boolean) {
|
|
|
|
this._ipcCall(back ? "navigateBack" : "navigateForward");
|
|
|
|
}
|
|
|
|
|
|
|
|
onKeyDown(ev: KeyboardEvent): boolean {
|
|
|
|
let handled = false;
|
|
|
|
|
|
|
|
switch (ev.key) {
|
|
|
|
case Key.SQUARE_BRACKET_LEFT:
|
|
|
|
case Key.SQUARE_BRACKET_RIGHT:
|
|
|
|
if (isMac && ev.metaKey && !ev.altKey && !ev.ctrlKey && !ev.shiftKey) {
|
|
|
|
this._navigateForwardBack(ev.key === Key.SQUARE_BRACKET_LEFT);
|
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Key.ARROW_LEFT:
|
|
|
|
case Key.ARROW_RIGHT:
|
|
|
|
if (!isMac && ev.altKey && !ev.metaKey && !ev.ctrlKey && !ev.shiftKey) {
|
|
|
|
this._navigateForwardBack(ev.key === Key.ARROW_LEFT);
|
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return handled;
|
|
|
|
}
|
2016-11-02 18:49:28 +00:00
|
|
|
}
|