mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-11-21 15:08:09 +00:00
Fix npm-test (xo code style)
This commit is contained in:
@@ -1,27 +1,28 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
const {app, shell} = require('electron');
|
const {app} = require('electron');
|
||||||
const electronLocalshortcut = require('electron-localshortcut');
|
const electronLocalshortcut = require('electron-localshortcut');
|
||||||
const ipc = require('electron').ipcMain;
|
const ipc = require('electron').ipcMain;
|
||||||
const Configstore = require('configstore');
|
const Configstore = require('configstore');
|
||||||
const JsonDB = require('node-json-db');
|
const JsonDB = require('node-json-db');
|
||||||
|
const SpellChecker = require('simple-spellchecker');
|
||||||
const tray = require('./tray');
|
const tray = require('./tray');
|
||||||
const appMenu = require('./menu');
|
const appMenu = require('./menu');
|
||||||
const link = require ('./link_helper');
|
const link = require('./link-helper');
|
||||||
|
|
||||||
const {linkIsInternal} = link;
|
const {linkIsInternal} = link;
|
||||||
|
|
||||||
const db = new JsonDB("domain", true, true);
|
const db = new JsonDB('domain', true, true);
|
||||||
const data = db.getData("/");
|
const data = db.getData('/');
|
||||||
|
|
||||||
// adds debug features like hotkeys for triggering dev tools and reload
|
// adds debug features like hotkeys for triggering dev tools and reload
|
||||||
require('electron-debug')();
|
require('electron-debug')();
|
||||||
require('electron-context-menu')();
|
require('electron-context-menu')();
|
||||||
|
|
||||||
const conf = new Configstore("Zulip-Desktop");
|
const conf = new Configstore('Zulip-Desktop');
|
||||||
|
|
||||||
// spellchecker enabled
|
// spellchecker enabled
|
||||||
const SpellChecker = require('simple-spellchecker');
|
|
||||||
let myDictionary = null;
|
let myDictionary = null;
|
||||||
|
|
||||||
// prevent window being garbage collected
|
// prevent window being garbage collected
|
||||||
@@ -32,18 +33,16 @@ let targetLink;
|
|||||||
const targetUrl = 'file://' + path.join(__dirname, '../renderer', 'index.html');
|
const targetUrl = 'file://' + path.join(__dirname, '../renderer', 'index.html');
|
||||||
|
|
||||||
function checkWindowURL() {
|
function checkWindowURL() {
|
||||||
if (data["domain"] !== undefined) {
|
if (data.domain !== undefined) {
|
||||||
return data["domain"]
|
return data.domain;
|
||||||
}
|
}
|
||||||
return targetLink
|
return targetLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
const APP_ICON = path.join(__dirname, '../resources', 'Icon');
|
const APP_ICON = path.join(__dirname, '../resources', 'Icon');
|
||||||
|
|
||||||
const iconPath = () => {
|
const iconPath = () => {
|
||||||
return process.platform === 'win32'
|
return APP_ICON + (process.platform === 'win32' ? '.ico' : '.png');
|
||||||
? APP_ICON + '.ico'
|
|
||||||
: APP_ICON + '.png'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function onClosed() {
|
function onClosed() {
|
||||||
@@ -53,7 +52,6 @@ function onClosed() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateDockBadge(title) {
|
function updateDockBadge(title) {
|
||||||
|
|
||||||
if (title.indexOf('Zulip') === -1) {
|
if (title.indexOf('Zulip') === -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -62,7 +60,7 @@ function updateDockBadge(title) {
|
|||||||
messageCount = messageCount ? Number(messageCount[1]) : 0;
|
messageCount = messageCount ? Number(messageCount[1]) : 0;
|
||||||
|
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
app.setBadgeCount(messageCount)
|
app.setBadgeCount(messageCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,16 +94,16 @@ function createMainWindow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle sizing events so we can persist them.
|
// Handle sizing events so we can persist them.
|
||||||
win.on('maximize', function (event) {
|
win.on('maximize', () => {
|
||||||
conf.set('maximize', true);
|
conf.set('maximize', true);
|
||||||
});
|
});
|
||||||
|
|
||||||
win.on('unmaximize', function (event) {
|
win.on('unmaximize', () => {
|
||||||
conf.set('maximize', false);
|
conf.set('maximize', false);
|
||||||
});
|
});
|
||||||
|
|
||||||
win.on('resize', function (event) {
|
win.on('resize', () => {
|
||||||
var size = this.getSize();
|
const size = this.getSize();
|
||||||
conf.set({
|
conf.set({
|
||||||
width: size[0],
|
width: size[0],
|
||||||
height: size[1]
|
height: size[1]
|
||||||
@@ -113,8 +111,8 @@ function createMainWindow() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// on osx it's 'moved'
|
// on osx it's 'moved'
|
||||||
win.on('move', function (event) {
|
win.on('move', () => {
|
||||||
var pos = this.getPosition();
|
const pos = this.getPosition();
|
||||||
conf.set({
|
conf.set({
|
||||||
x: pos[0],
|
x: pos[0],
|
||||||
y: pos[1]
|
y: pos[1]
|
||||||
@@ -122,7 +120,7 @@ function createMainWindow() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// stop page to update it's title
|
// stop page to update it's title
|
||||||
win.on('page-title-updated', (e,title) => {
|
win.on('page-title-updated', (e, title) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
updateDockBadge(title);
|
updateDockBadge(title);
|
||||||
});
|
});
|
||||||
@@ -130,7 +128,7 @@ function createMainWindow() {
|
|||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO: fix certificate errors
|
||||||
app.commandLine.appendSwitch('ignore-certificate-errors', 'true');
|
app.commandLine.appendSwitch('ignore-certificate-errors', 'true');
|
||||||
|
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
@@ -153,19 +151,17 @@ app.on('ready', () => {
|
|||||||
const page = mainWindow.webContents;
|
const page = mainWindow.webContents;
|
||||||
|
|
||||||
// Add spellcheck dictionary
|
// Add spellcheck dictionary
|
||||||
SpellChecker.getDictionary("en-US", "./node_modules/simple-spellchecker/dict", function(err, result) {
|
SpellChecker.getDictionary('en-US', './node_modules/simple-spellchecker/dict', (err, result) => {
|
||||||
if(!err) {
|
if (!err) {
|
||||||
myDictionary = result;
|
myDictionary = result;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Define function for consult the dictionary.
|
// Define function for consult the dictionary.
|
||||||
ipc.on('checkspell', function(event, word) {
|
ipc.on('checkspell', (event, word) => {
|
||||||
var res = null;
|
if (myDictionary !== null && word !== null) {
|
||||||
if(myDictionary != null && word != null) {
|
event.returnValue = myDictionary.spellCheck(word);
|
||||||
res = myDictionary.spellCheck(word);
|
|
||||||
}
|
}
|
||||||
event.returnValue = res;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO - use global shortcut instead
|
// TODO - use global shortcut instead
|
||||||
@@ -205,7 +201,7 @@ app.on('ready', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
ipc.on('new-domain', function (e, domain) {
|
ipc.on('new-domain', (e, domain) => {
|
||||||
mainWindow.loadURL(domain);
|
mainWindow.loadURL(domain);
|
||||||
targetLink = domain;
|
targetLink = domain;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ const wurl = require('wurl');
|
|||||||
|
|
||||||
// Check link if it's internal/external
|
// Check link if it's internal/external
|
||||||
function linkIsInternal(currentUrl, newUrl) {
|
function linkIsInternal(currentUrl, newUrl) {
|
||||||
var currentDomain = wurl('domain', currentUrl);
|
const currentDomain = wurl('domain', currentUrl);
|
||||||
var newDomain = wurl('domain', newUrl);
|
const newDomain = wurl('domain', newUrl);
|
||||||
return currentDomain === newDomain;
|
return currentDomain === newDomain;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const path = require('path');
|
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
|
|
||||||
const app = electron.app;
|
const app = electron.app;
|
||||||
const BrowserWindow = electron.BrowserWindow;
|
const BrowserWindow = electron.BrowserWindow;
|
||||||
const shell = electron.shell;
|
const shell = electron.shell;
|
||||||
const appName = app.getName();
|
const appName = app.getName();
|
||||||
|
|
||||||
const { addDomain, About } = require('./windowmanager');
|
const {addDomain, about} = require('./windowmanager');
|
||||||
|
|
||||||
function sendAction(action) {
|
function sendAction(action) {
|
||||||
const win = BrowserWindow.getAllWindows()[0];
|
const win = BrowserWindow.getAllWindows()[0];
|
||||||
@@ -20,26 +20,30 @@ function sendAction(action) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const viewSubmenu = [
|
const viewSubmenu = [
|
||||||
{
|
{
|
||||||
label: 'Reload',
|
label: 'Reload',
|
||||||
accelerator: 'CmdOrCtrl+R',
|
accelerator: 'CmdOrCtrl+R',
|
||||||
click (item, focusedWindow) {
|
click(item, focusedWindow) {
|
||||||
if (focusedWindow) focusedWindow.reload()
|
if (focusedWindow) {
|
||||||
|
focusedWindow.reload();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
{
|
},
|
||||||
|
{
|
||||||
label: 'Toggle Developer Tools',
|
label: 'Toggle Developer Tools',
|
||||||
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
|
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
|
||||||
click (item, focusedWindow) {
|
click(item, focusedWindow) {
|
||||||
if (focusedWindow) focusedWindow.webContents.toggleDevTools()
|
if (focusedWindow) {
|
||||||
|
focusedWindow.webContents.toggleDevTools();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
{
|
},
|
||||||
|
{
|
||||||
type: 'separator'
|
type: 'separator'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
role: 'togglefullscreen'
|
role: 'togglefullscreen'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const helpSubmenu = [
|
const helpSubmenu = [
|
||||||
@@ -50,7 +54,7 @@ const helpSubmenu = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: `${app.getName()} - ${app.getVersion()}`,
|
label: `${app.getName()} - ${app.getVersion()}`
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Report an Issue...',
|
label: 'Report an Issue...',
|
||||||
@@ -75,7 +79,7 @@ const darwinTpl = [
|
|||||||
{
|
{
|
||||||
label: 'Zulip desktop',
|
label: 'Zulip desktop',
|
||||||
click() {
|
click() {
|
||||||
About();
|
about();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -85,14 +89,18 @@ const darwinTpl = [
|
|||||||
label: 'Change Zulip Server',
|
label: 'Change Zulip Server',
|
||||||
accelerator: 'Cmd+,',
|
accelerator: 'Cmd+,',
|
||||||
click(item, focusedWindow) {
|
click(item, focusedWindow) {
|
||||||
if(focusedWindow) addDomain();
|
if (focusedWindow) {
|
||||||
|
addDomain();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Keyboard shortcuts',
|
label: 'Keyboard shortcuts',
|
||||||
accelerator: 'Cmd+K',
|
accelerator: 'Cmd+K',
|
||||||
click(item, focusedWindow) {
|
click(item, focusedWindow) {
|
||||||
if(focusedWindow) sendAction('shortcut');
|
if (focusedWindow) {
|
||||||
|
sendAction('shortcut');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -101,7 +109,9 @@ const darwinTpl = [
|
|||||||
{
|
{
|
||||||
label: 'Log Out',
|
label: 'Log Out',
|
||||||
click(item, focusedWindow) {
|
click(item, focusedWindow) {
|
||||||
if(focusedWindow) sendAction('log-out');
|
if (focusedWindow) {
|
||||||
|
sendAction('log-out');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -197,7 +207,7 @@ const otherTpl = [
|
|||||||
{
|
{
|
||||||
label: 'Zulip desktop',
|
label: 'Zulip desktop',
|
||||||
click() {
|
click() {
|
||||||
About();
|
about();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -207,7 +217,9 @@ const otherTpl = [
|
|||||||
label: 'Change Zulip Server',
|
label: 'Change Zulip Server',
|
||||||
accelerator: 'Ctrl+,',
|
accelerator: 'Ctrl+,',
|
||||||
click(item, focusedWindow) {
|
click(item, focusedWindow) {
|
||||||
if(focusedWindow) addDomain();
|
if (focusedWindow) {
|
||||||
|
addDomain();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -217,7 +229,9 @@ const otherTpl = [
|
|||||||
label: 'Keyboard shortcuts',
|
label: 'Keyboard shortcuts',
|
||||||
accelerator: 'Ctrl+K',
|
accelerator: 'Ctrl+K',
|
||||||
click(item, focusedWindow) {
|
click(item, focusedWindow) {
|
||||||
if(focusedWindow) sendAction('shortcut');
|
if (focusedWindow) {
|
||||||
|
sendAction('shortcut');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -226,7 +240,9 @@ const otherTpl = [
|
|||||||
{
|
{
|
||||||
label: 'Log Out',
|
label: 'Log Out',
|
||||||
click(item, focusedWindow) {
|
click(item, focusedWindow) {
|
||||||
if(focusedWindow) sendAction('log-out');
|
if (focusedWindow) {
|
||||||
|
sendAction('log-out');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
const electron = require('electron');
|
|
||||||
const ipcRenderer = require('electron').ipcRenderer;
|
const ipcRenderer = require('electron').ipcRenderer;
|
||||||
const webFrame = require('electron').webFrame;
|
const webFrame = require('electron').webFrame;
|
||||||
|
|
||||||
// Implement spellcheck using electron api
|
// Implement spellcheck using electron api
|
||||||
|
|
||||||
webFrame.setSpellCheckProvider("en-US", false, {
|
webFrame.setSpellCheckProvider('en-US', false, {
|
||||||
spellCheck: function(text) {
|
spellCheck: text => {
|
||||||
var res = ipcRenderer.sendSync('checkspell', text);
|
const res = ipcRenderer.sendSync('checkspell', text);
|
||||||
return res != null? res : true;
|
return res === null ? true : res;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2,22 +2,17 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
const app = require('electron').app;
|
const app = require('electron').app;
|
||||||
const {shell} = require('electron');
|
const {addDomain, about} = require('./windowmanager');
|
||||||
const { addDomain, About } = require('./windowmanager');
|
|
||||||
const BrowserWindow = electron.BrowserWindow;
|
|
||||||
|
|
||||||
let tray = null;
|
let tray = null;
|
||||||
|
|
||||||
const APP_ICON = path.join(__dirname, '../resources', 'Icon');
|
const APP_ICON = path.join(__dirname, '../resources', 'Icon');
|
||||||
|
|
||||||
const iconPath = () => {
|
const iconPath = () => {
|
||||||
return process.platform === 'win32'
|
return APP_ICON + (process.platform === 'win32' ? '.ico' : '.png');
|
||||||
? APP_ICON + '.ico'
|
|
||||||
: APP_ICON + '.png'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.create = win => {
|
exports.create = () => {
|
||||||
|
|
||||||
// Noone is using this feature. so let's hide it for now.
|
// Noone is using this feature. so let's hide it for now.
|
||||||
// const toggleWin = () => {
|
// const toggleWin = () => {
|
||||||
// if (win.isVisible()) {
|
// if (win.isVisible()) {
|
||||||
@@ -26,12 +21,11 @@ exports.create = win => {
|
|||||||
// win.show();
|
// win.show();
|
||||||
// }
|
// }
|
||||||
// };
|
// };
|
||||||
|
|
||||||
const contextMenu = electron.Menu.buildFromTemplate([
|
const contextMenu = electron.Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
label: 'About',
|
label: 'About',
|
||||||
click() {
|
click() {
|
||||||
About();
|
about();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -40,7 +34,9 @@ exports.create = win => {
|
|||||||
{
|
{
|
||||||
label: 'Change Zulip server',
|
label: 'Change Zulip server',
|
||||||
click(item, focusedWindow) {
|
click(item, focusedWindow) {
|
||||||
if(focusedWindow) addDomain();
|
if (focusedWindow) {
|
||||||
|
addDomain();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -48,8 +44,10 @@ exports.create = win => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Reload',
|
label: 'Reload',
|
||||||
click (item, focusedWindow) {
|
click(item, focusedWindow) {
|
||||||
if (focusedWindow) focusedWindow.reload()
|
if (focusedWindow) {
|
||||||
|
focusedWindow.reload();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
const electron = require('electron');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const electron = require('electron');
|
||||||
|
|
||||||
let domainWindow;
|
let domainWindow;
|
||||||
let aboutWindow;
|
let aboutWindow;
|
||||||
@@ -18,7 +18,7 @@ function createdomainWindow() {
|
|||||||
height: 300,
|
height: 300,
|
||||||
resizable: false,
|
resizable: false,
|
||||||
width: 400
|
width: 400
|
||||||
})
|
});
|
||||||
const domainURL = 'file://' + path.join(__dirname, '../renderer', 'pref.html');
|
const domainURL = 'file://' + path.join(__dirname, '../renderer', 'pref.html');
|
||||||
domainwin.loadURL(domainURL);
|
domainwin.loadURL(domainURL);
|
||||||
domainwin.on('closed', onClosed);
|
domainwin.on('closed', onClosed);
|
||||||
@@ -27,10 +27,10 @@ function createdomainWindow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call this window onClick addDomain in tray
|
// Call this window onClick addDomain in tray
|
||||||
function addDomain(){
|
function addDomain() {
|
||||||
domainWindow = createdomainWindow();
|
domainWindow = createdomainWindow();
|
||||||
domainWindow.show();
|
domainWindow.show();
|
||||||
};
|
}
|
||||||
|
|
||||||
// About window
|
// About window
|
||||||
function createAboutWindow() {
|
function createAboutWindow() {
|
||||||
@@ -43,13 +43,13 @@ function createAboutWindow() {
|
|||||||
fullscreen: false,
|
fullscreen: false,
|
||||||
fullscreenable: false,
|
fullscreenable: false,
|
||||||
resizable: false
|
resizable: false
|
||||||
})
|
});
|
||||||
const aboutURL = 'file://' + path.join(__dirname, '../renderer', 'about.html');
|
const aboutURL = 'file://' + path.join(__dirname, '../renderer', 'about.html');
|
||||||
aboutwin.loadURL(aboutURL);
|
aboutwin.loadURL(aboutURL);
|
||||||
aboutwin.on('closed', onClosed);
|
aboutwin.on('closed', onClosed);
|
||||||
|
|
||||||
// stop page to update it's title
|
// stop page to update it's title
|
||||||
aboutwin.on('page-title-updated', (e) => {
|
aboutwin.on('page-title-updated', e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -59,11 +59,11 @@ function createAboutWindow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call this onClick About in tray
|
// Call this onClick About in tray
|
||||||
function About() {
|
function about() {
|
||||||
aboutWindow = createAboutWindow();
|
aboutWindow = createAboutWindow();
|
||||||
aboutWindow.show();
|
aboutWindow.show();
|
||||||
};
|
}
|
||||||
|
|
||||||
exports = module.exports = {
|
exports = module.exports = {
|
||||||
addDomain,About
|
addDomain, about
|
||||||
};
|
};
|
||||||
@@ -2,36 +2,33 @@ window.onload = function getURL() {
|
|||||||
const request = require('request');
|
const request = require('request');
|
||||||
const JsonDB = require('node-json-db');
|
const JsonDB = require('node-json-db');
|
||||||
const ipcRenderer = require('electron').ipcRenderer;
|
const ipcRenderer = require('electron').ipcRenderer;
|
||||||
const dialogs = require('dialogs')()
|
const dialogs = require('dialogs')();
|
||||||
const db = new JsonDB("domain", true, true);
|
|
||||||
const data = db.getData("/");
|
|
||||||
|
|
||||||
if (data["domain"] !== undefined) {
|
const db = new JsonDB('domain', true, true);
|
||||||
window.location.href = data["domain"];
|
const data = db.getData('/');
|
||||||
|
|
||||||
|
if (data.domain) {
|
||||||
|
window.location.href = data.domain;
|
||||||
} else {
|
} else {
|
||||||
|
dialogs.prompt('Enter the URL for your Zulip server', url => {
|
||||||
|
const newurl = 'https://' + url.replace(/^https?:\/\//, '');
|
||||||
|
const checkURL = newurl + '/static/audio/zulip.ogg';
|
||||||
|
|
||||||
dialogs.prompt('Enter the URL for your Zulip server', function(url) {
|
request(checkURL, (error, response) => {
|
||||||
|
|
||||||
let newurl = 'https://' + url.replace(/^https?:\/\//,'')
|
|
||||||
let checkURL = newurl + '/static/audio/zulip.ogg';
|
|
||||||
|
|
||||||
request(checkURL, function (error, response, body) {
|
|
||||||
if (!error && response.statusCode !== 404) {
|
if (!error && response.statusCode !== 404) {
|
||||||
db.push("/domain", newurl);
|
db.push('/domain', newurl);
|
||||||
ipcRenderer.send('new-domain', newurl);
|
ipcRenderer.send('new-domain', newurl);
|
||||||
window.location.href = newurl ;
|
window.location.href = newurl;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
dialogs.alert('Not valid url');
|
dialogs.alert('Not valid url');
|
||||||
console.log("Not valid url");
|
console.log('Not valid url');
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const getInput = document.getElementsByTagName('input')[0];
|
const getInput = document.getElementsByTagName('input')[0];
|
||||||
|
|
||||||
getInput.setAttribute('placeholder', 'zulip.example.com'); // add placeholder
|
getInput.setAttribute('placeholder', 'zulip.example.com'); // add placeholder
|
||||||
getInput.setAttribute('spellcheck', 'false'); // no spellcheck for form
|
getInput.setAttribute('spellcheck', 'false'); // no spellcheck for form
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,40 +1,40 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
const {remote} = require('electron');
|
const {remote} = require('electron');
|
||||||
|
|
||||||
document.getElementById('close-button').addEventListener('click', function (e) {
|
document.getElementById('close-bu on').addEventListener('click', () => {
|
||||||
let window = remote.getCurrentWindow();
|
const window = remote.getCurrentWindow();
|
||||||
window.close();
|
window.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
// document.getElementById('pic').style.display ='block';
|
// document.getElementById('pic').style.display ='block';
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function addDomain() {
|
function addDomain() {
|
||||||
|
|
||||||
const request = require('request');
|
const request = require('request');
|
||||||
const ipcRenderer = require('electron').ipcRenderer;
|
const ipcRenderer = require('electron').ipcRenderer;
|
||||||
const JsonDB = require('node-json-db');
|
const JsonDB = require('node-json-db');
|
||||||
|
|
||||||
const db = new JsonDB('domain', true, true);
|
const db = new JsonDB('domain', true, true);
|
||||||
document.getElementById('main').innerHTML = 'checking...'
|
document.getElementById('main').innerHTML = 'checking...';
|
||||||
document.getElementById('pic').style.display ='block';
|
document.getElementById('pic').style.display = 'block';
|
||||||
|
|
||||||
let newDomain = document.getElementById('url').value;
|
let newDomain = document.getElementById('url').value;
|
||||||
newDomain = newDomain.replace(/^https?:\/\//,'')
|
newDomain = newDomain.replace(/^https?:\/\//, '');
|
||||||
|
|
||||||
const domain = 'https://' + newDomain;
|
const domain = 'https://' + newDomain;
|
||||||
const checkDomain = domain + '/static/audio/zulip.ogg';
|
const checkDomain = domain + '/static/audio/zulip.ogg';
|
||||||
|
|
||||||
request(checkDomain, function (error, response, body) {
|
request(checkDomain, (error, response) => {
|
||||||
if (!error && response.statusCode !== 404) {
|
if (!error && response.statusCode !== 404) {
|
||||||
document.getElementById('pic').style.display ='none';
|
document.getElementById('pic').style.display = 'none';
|
||||||
document.getElementById('main').innerHTML = 'Add'
|
document.getElementById('main').innerHTML = 'Add';
|
||||||
document.getElementById('urladded').innerHTML = newDomain + ' Added';
|
document.getElementById('urladded').innerHTML = newDomain + ' Added';
|
||||||
db.push('/domain', domain);
|
db.push('/domain', domain);
|
||||||
ipcRenderer.send('new-domain', domain);
|
ipcRenderer.send('new-domain', domain);
|
||||||
|
} else {
|
||||||
|
document.getElementById('pic').style.display = 'none';
|
||||||
|
document.getElementById('main').innerHTML = 'Add';
|
||||||
|
document.getElementById('urladded').innerHTML = 'Not a vaild Zulip server';
|
||||||
}
|
}
|
||||||
else {
|
});
|
||||||
document.getElementById('pic').style.display ='none';
|
|
||||||
document.getElementById('main').innerHTML = 'Add'
|
|
||||||
document.getElementById('urladded').innerHTML = "Not a vaild Zulip server";
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"configstore": "^2.0.0",
|
"configstore": "^2.0.0",
|
||||||
"dialogs": "1.1.14",
|
"dialogs": "1.1.14",
|
||||||
|
"electron": "^1.3.3",
|
||||||
"electron-context-menu": "0.4.0",
|
"electron-context-menu": "0.4.0",
|
||||||
"electron-debug": "^1.0.0",
|
"electron-debug": "^1.0.0",
|
||||||
"electron-dl": "^0.2.0",
|
"electron-dl": "^0.2.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user