mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-10-30 11:33:36 +00:00
Change the way utils load.
This commit is contained in:
@@ -23,9 +23,6 @@ class WebView extends BaseComponent {
|
||||
this.zoomFactor = 1.0;
|
||||
this.loading = false;
|
||||
this.isActive = isActive;
|
||||
this.domainUtil = new DomainUtil();
|
||||
this.systemUtil = new SystemUtil();
|
||||
this.linkUtil = new LinkUtil();
|
||||
this.badgeCount = 0;
|
||||
}
|
||||
|
||||
@@ -51,9 +48,9 @@ class WebView extends BaseComponent {
|
||||
registerListeners() {
|
||||
this.$el.addEventListener('new-window', event => {
|
||||
const {url} = event;
|
||||
const domainPrefix = this.domainUtil.getDomain(this.index).url;
|
||||
const domainPrefix = DomainUtil.getDomain(this.index).url;
|
||||
|
||||
if (this.linkUtil.isInternal(domainPrefix, url)) {
|
||||
if (LinkUtil.isInternal(domainPrefix, url)) {
|
||||
event.preventDefault();
|
||||
this.$el.loadURL(url);
|
||||
} else {
|
||||
@@ -72,7 +69,7 @@ class WebView extends BaseComponent {
|
||||
|
||||
this.$el.addEventListener('did-fail-load', event => {
|
||||
const {errorDescription} = event;
|
||||
const hasConnectivityErr = (this.systemUtil.connectivityERR.indexOf(errorDescription) >= 0);
|
||||
const hasConnectivityErr = (SystemUtil.connectivityERR.indexOf(errorDescription) >= 0);
|
||||
if (hasConnectivityErr) {
|
||||
console.error('error', errorDescription);
|
||||
this.checkConnectivity();
|
||||
@@ -80,10 +77,10 @@ class WebView extends BaseComponent {
|
||||
});
|
||||
|
||||
this.$el.addEventListener('did-start-loading', () => {
|
||||
let userAgent = this.systemUtil.getUserAgent();
|
||||
let userAgent = SystemUtil.getUserAgent();
|
||||
if (!userAgent) {
|
||||
this.systemUtil.setUserAgent(this.$el.getUserAgent());
|
||||
userAgent = this.systemUtil.getUserAgent();
|
||||
SystemUtil.setUserAgent(this.$el.getUserAgent());
|
||||
userAgent = SystemUtil.getUserAgent();
|
||||
}
|
||||
this.$el.setUserAgent(userAgent);
|
||||
});
|
||||
|
||||
@@ -24,14 +24,13 @@ class ServerManagerView {
|
||||
}
|
||||
|
||||
init() {
|
||||
this.domainUtil = new DomainUtil();
|
||||
this.initTabs();
|
||||
this.initActions();
|
||||
this.registerIpcs();
|
||||
}
|
||||
|
||||
initTabs() {
|
||||
const servers = this.domainUtil.getDomains();
|
||||
const servers = DomainUtil.getDomains();
|
||||
if (servers.length > 0) {
|
||||
for (let i = 0; i < servers.length; i++) {
|
||||
this.initServer(servers[i], i);
|
||||
|
||||
@@ -13,13 +13,12 @@ class PreferenceView {
|
||||
}
|
||||
|
||||
init() {
|
||||
this.domainUtil = new DomainUtil();
|
||||
this.initServers();
|
||||
this.initActions();
|
||||
}
|
||||
|
||||
initServers() {
|
||||
const servers = this.domainUtil.getDomains();
|
||||
const servers = DomainUtil.getDomains();
|
||||
this.$serverInfoContainer.innerHTML = servers.length ? '' : 'Add your first server to get started!';
|
||||
|
||||
this.initNewServerForm();
|
||||
@@ -64,7 +63,7 @@ class PreferenceView {
|
||||
</div>`;
|
||||
this.$serverInfoContainer.appendChild(this.insertNode(serverInfoTemplate));
|
||||
document.getElementById(`delete-server-action-${index}`).addEventListener('click', () => {
|
||||
this.domainUtil.removeDomain(index);
|
||||
DomainUtil.removeDomain(index);
|
||||
this.initServers();
|
||||
// alert('Success. Reload to apply changes.');
|
||||
ipcRenderer.send('reload-main');
|
||||
@@ -109,13 +108,13 @@ class PreferenceView {
|
||||
this.$newServerButton.classList.add('hidden');
|
||||
});
|
||||
this.$saveServerButton.addEventListener('click', () => {
|
||||
this.domainUtil.checkDomain(this.$newServerUrl.value).then(domain => {
|
||||
DomainUtil.checkDomain(this.$newServerUrl.value).then(domain => {
|
||||
const server = {
|
||||
alias: this.$newServerAlias.value,
|
||||
url: domain,
|
||||
icon: this.$newServerIcon.value
|
||||
};
|
||||
this.domainUtil.addDomain(server);
|
||||
DomainUtil.addDomain(server);
|
||||
this.$saveServerButton.classList.add('hidden');
|
||||
this.$newServerButton.classList.remove('hidden');
|
||||
this.$newServerForm.classList.add('hidden');
|
||||
|
||||
@@ -4,9 +4,17 @@ const {app} = require('electron').remote;
|
||||
const JsonDB = require('node-json-db');
|
||||
const request = require('request');
|
||||
|
||||
let instance = null;
|
||||
|
||||
const defaultIconUrl = 'https://chat.zulip.org/static/images/logo/zulip-icon-128x128.271d0f6a0ca2.png';
|
||||
class DomainUtil {
|
||||
constructor() {
|
||||
if (instance) {
|
||||
return instance;
|
||||
} else {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
this.db = new JsonDB(app.getPath('userData') + '/domain.json', true, true);
|
||||
// Migrate from old schema
|
||||
if (this.db.getData('/').domain) {
|
||||
@@ -16,6 +24,8 @@ class DomainUtil {
|
||||
});
|
||||
this.db.delete('/domain');
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
getDomains() {
|
||||
@@ -69,4 +79,4 @@ class DomainUtil {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DomainUtil;
|
||||
module.exports = new DomainUtil();
|
||||
|
||||
@@ -26,4 +26,4 @@ class LinkUtil {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LinkUtil;
|
||||
module.exports = new LinkUtil();
|
||||
|
||||
@@ -52,4 +52,4 @@ class SystemUtil {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SystemUtil;
|
||||
module.exports = new SystemUtil();
|
||||
|
||||
Reference in New Issue
Block a user