mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-10-28 18:43:50 +00:00
js: Explode more singleton classes to modules.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
1104
app/main/menu.ts
1104
app/main/menu.ts
File diff suppressed because it is too large
Load Diff
@@ -1050,4 +1050,4 @@ window.addEventListener('load', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export = new ServerManagerView();
|
export {};
|
||||||
|
|||||||
@@ -2,15 +2,11 @@
|
|||||||
|
|
||||||
import { ipcRenderer } from 'electron';
|
import { ipcRenderer } from 'electron';
|
||||||
|
|
||||||
class NetworkTroubleshootingView {
|
export function init($reconnectButton: Element, $settingsButton: Element): void {
|
||||||
init($reconnectButton: Element, $settingsButton: Element): void {
|
$reconnectButton.addEventListener('click', () => {
|
||||||
$reconnectButton.addEventListener('click', () => {
|
ipcRenderer.send('forward-message', 'reload-viewer');
|
||||||
ipcRenderer.send('forward-message', 'reload-viewer');
|
});
|
||||||
});
|
$settingsButton.addEventListener('click', () => {
|
||||||
$settingsButton.addEventListener('click', () => {
|
ipcRenderer.send('forward-message', 'open-settings');
|
||||||
ipcRenderer.send('forward-message', 'open-settings');
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export = new NetworkTroubleshootingView();
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import { ipcRenderer, shell } from 'electron';
|
import { ipcRenderer, shell } from 'electron';
|
||||||
import SetupSpellChecker from './spellchecker';
|
import * as SetupSpellChecker from './spellchecker';
|
||||||
|
|
||||||
import isDev = require('electron-is-dev');
|
import isDev = require('electron-is-dev');
|
||||||
import LinkUtil = require('./utils/link-util');
|
import LinkUtil = require('./utils/link-util');
|
||||||
|
|||||||
@@ -18,47 +18,44 @@ const logger = new Logger({
|
|||||||
timestamp: true
|
timestamp: true
|
||||||
});
|
});
|
||||||
|
|
||||||
class SetupSpellChecker {
|
let spellCheckHandler: SpellCheckHandler;
|
||||||
SpellCheckHandler: SpellCheckHandler;
|
let contextMenuListener: ContextMenuListener;
|
||||||
contextMenuListener: ContextMenuListener;
|
|
||||||
init(serverLanguage: string): void {
|
export function init(serverLanguage: string): void {
|
||||||
if (ConfigUtil.getConfigItem('enableSpellchecker')) {
|
if (ConfigUtil.getConfigItem('enableSpellchecker')) {
|
||||||
this.enableSpellChecker();
|
enableSpellChecker();
|
||||||
}
|
|
||||||
this.enableContextMenu(serverLanguage);
|
|
||||||
}
|
}
|
||||||
|
enableContextMenu(serverLanguage);
|
||||||
|
}
|
||||||
|
|
||||||
enableSpellChecker(): void {
|
function enableSpellChecker(): void {
|
||||||
try {
|
try {
|
||||||
this.SpellCheckHandler = new SpellCheckHandler();
|
spellCheckHandler = new SpellCheckHandler();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enableContextMenu(serverLanguage: string): void {
|
|
||||||
if (this.SpellCheckHandler) {
|
|
||||||
this.SpellCheckHandler.attachToInput();
|
|
||||||
this.SpellCheckHandler.switchLanguage(serverLanguage);
|
|
||||||
this.SpellCheckHandler.currentSpellcheckerChanged.subscribe(() => {
|
|
||||||
this.SpellCheckHandler.switchLanguage(this.SpellCheckHandler.currentSpellcheckerLanguage);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const contextMenuBuilder = new ContextMenuBuilder(this.SpellCheckHandler);
|
|
||||||
this.contextMenuListener = new ContextMenuListener(info => {
|
|
||||||
contextMenuBuilder.showPopupMenu(info);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
unsubscribeSpellChecker(): void {
|
|
||||||
if (this.SpellCheckHandler) {
|
|
||||||
this.SpellCheckHandler.unsubscribe();
|
|
||||||
}
|
|
||||||
if (this.contextMenuListener) {
|
|
||||||
this.contextMenuListener.unsubscribe();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export = new SetupSpellChecker();
|
function enableContextMenu(serverLanguage: string): void {
|
||||||
|
if (spellCheckHandler) {
|
||||||
|
spellCheckHandler.attachToInput();
|
||||||
|
spellCheckHandler.switchLanguage(serverLanguage);
|
||||||
|
spellCheckHandler.currentSpellcheckerChanged.subscribe(() => {
|
||||||
|
spellCheckHandler.switchLanguage(spellCheckHandler.currentSpellcheckerLanguage);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const contextMenuBuilder = new ContextMenuBuilder(spellCheckHandler);
|
||||||
|
contextMenuListener = new ContextMenuListener(info => {
|
||||||
|
contextMenuBuilder.showPopupMenu(info);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function unsubscribeSpellChecker(): void {
|
||||||
|
if (spellCheckHandler) {
|
||||||
|
spellCheckHandler.unsubscribe();
|
||||||
|
}
|
||||||
|
if (contextMenuListener) {
|
||||||
|
contextMenuListener.unsubscribe();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,32 +5,28 @@ import ConfigUtil = require('./config-util');
|
|||||||
|
|
||||||
const { shell } = remote;
|
const { shell } = remote;
|
||||||
|
|
||||||
class AuthUtil {
|
export const openInBrowser = (link: string): void => {
|
||||||
openInBrowser = (link: string): void => {
|
const otp = cryptoRandomString({length: 64});
|
||||||
const otp = cryptoRandomString({length: 64});
|
ConfigUtil.setConfigItem('desktopOtp', otp);
|
||||||
ConfigUtil.setConfigItem('desktopOtp', otp);
|
shell.openExternal(`${link}?desktop_flow_otp=${otp}`);
|
||||||
shell.openExternal(`${link}?desktop_flow_otp=${otp}`);
|
};
|
||||||
};
|
|
||||||
|
|
||||||
xorStrings = (a: string, b: string): string => {
|
export const xorStrings = (a: string, b: string): string => {
|
||||||
if (a.length === b.length) {
|
if (a.length === b.length) {
|
||||||
return a
|
return a
|
||||||
.split('')
|
.split('')
|
||||||
.map((char, i) => (parseInt(a[i], 16) ^ parseInt(b[i], 16)).toString(16))
|
.map((char, i) => (parseInt(a[i], 16) ^ parseInt(b[i], 16)).toString(16))
|
||||||
.join('')
|
.join('')
|
||||||
.toUpperCase();
|
.toUpperCase();
|
||||||
} else {
|
} else {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
hexToAscii = (hex: string): string => {
|
export const hexToAscii = (hex: string): string => {
|
||||||
let ascii = '';
|
let ascii = '';
|
||||||
for (let i = 0; i < hex.length; i += 2) {
|
for (let i = 0; i < hex.length; i += 2) {
|
||||||
ascii += String.fromCharCode(parseInt(hex.slice(i, i + 2), 16));
|
ascii += String.fromCharCode(parseInt(hex.slice(i, i + 2), 16));
|
||||||
}
|
}
|
||||||
return ascii;
|
return ascii;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
export = new AuthUtil();
|
|
||||||
|
|||||||
@@ -3,50 +3,46 @@ interface DialogBoxError {
|
|||||||
content: string;
|
content: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Messages {
|
export function invalidZulipServerError(domain: string): string {
|
||||||
invalidZulipServerError(domain: string): string {
|
return `${domain} does not appear to be a valid Zulip server. Make sure that
|
||||||
return `${domain} does not appear to be a valid Zulip server. Make sure that
|
\n • You can connect to that URL in a web browser.\
|
||||||
\n • You can connect to that URL in a web browser.\
|
\n • If you need a proxy to connect to the Internet, that you've configured your proxy in the Network settings.\
|
||||||
\n • If you need a proxy to connect to the Internet, that you've configured your proxy in the Network settings.\
|
\n • It's a Zulip server. (The oldest supported version is 1.6).\
|
||||||
\n • It's a Zulip server. (The oldest supported version is 1.6).\
|
\n • The server has a valid certificate. (You can add custom certificates in Settings > Organizations). \
|
||||||
\n • The server has a valid certificate. (You can add custom certificates in Settings > Organizations). \
|
\n • The SSL is correctly configured for the certificate. Check out the SSL troubleshooting guide -
|
||||||
\n • The SSL is correctly configured for the certificate. Check out the SSL troubleshooting guide -
|
\n https://zulip.readthedocs.io/en/stable/production/ssl-certificates.html`;
|
||||||
\n https://zulip.readthedocs.io/en/stable/production/ssl-certificates.html`;
|
|
||||||
}
|
|
||||||
|
|
||||||
noOrgsError(domain: string): string {
|
|
||||||
return `${domain} does not have any organizations added.\
|
|
||||||
\nPlease contact your server administrator.`;
|
|
||||||
}
|
|
||||||
|
|
||||||
certErrorMessage(domain: string, error: string): string {
|
|
||||||
return `Do you trust certificate from ${domain}? \n ${error}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
certErrorDetail(): string {
|
|
||||||
return `The organization you're connecting to is either someone impersonating the Zulip server you entered, or the server you're trying to connect to is configured in an insecure way.
|
|
||||||
\nIf you have a valid certificate please add it from Settings>Organizations and try to add the organization again.
|
|
||||||
\nUnless you have a good reason to believe otherwise, you should not proceed.
|
|
||||||
\nYou can click here if you'd like to proceed with the connection.`;
|
|
||||||
}
|
|
||||||
|
|
||||||
enterpriseOrgError(length: number, domains: string[]): DialogBoxError {
|
|
||||||
let domainList = '';
|
|
||||||
for (const domain of domains) {
|
|
||||||
domainList += `• ${domain}\n`;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
title: `Could not add the following ${length === 1 ? 'organization' : 'organizations'}`,
|
|
||||||
content: `${domainList}\nPlease contact your system administrator.`
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
orgRemovalError(url: string): DialogBoxError {
|
|
||||||
return {
|
|
||||||
title: `Removing ${url} is a restricted operation.`,
|
|
||||||
content: 'Please contact your system administrator.'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export = new Messages();
|
export function noOrgsError(domain: string): string {
|
||||||
|
return `${domain} does not have any organizations added.\
|
||||||
|
\nPlease contact your server administrator.`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function certErrorMessage(domain: string, error: string): string {
|
||||||
|
return `Do you trust certificate from ${domain}? \n ${error}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function certErrorDetail(): string {
|
||||||
|
return `The organization you're connecting to is either someone impersonating the Zulip server you entered, or the server you're trying to connect to is configured in an insecure way.
|
||||||
|
\nIf you have a valid certificate please add it from Settings>Organizations and try to add the organization again.
|
||||||
|
\nUnless you have a good reason to believe otherwise, you should not proceed.
|
||||||
|
\nYou can click here if you'd like to proceed with the connection.`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function enterpriseOrgError(length: number, domains: string[]): DialogBoxError {
|
||||||
|
let domainList = '';
|
||||||
|
for (const domain of domains) {
|
||||||
|
domainList += `• ${domain}\n`;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
title: `Could not add the following ${length === 1 ? 'organization' : 'organizations'}`,
|
||||||
|
content: `${domainList}\nPlease contact your system administrator.`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function orgRemovalError(url: string): DialogBoxError {
|
||||||
|
return {
|
||||||
|
title: `Removing ${url} is a restricted operation.`,
|
||||||
|
content: 'Please contact your system administrator.'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user