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