mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-11-03 21:43:18 +00:00
Save server icon to a local folder.
This commit is contained in:
@@ -98,7 +98,9 @@ html, body {
|
|||||||
|
|
||||||
.tab .server-tab {
|
.tab .server-tab {
|
||||||
background: #a4d3c4;
|
background: #a4d3c4;
|
||||||
background-size: 100%;
|
background-size: 28px;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: center;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
width: 35px;
|
width: 35px;
|
||||||
height: 35px;
|
height: 35px;
|
||||||
|
|||||||
@@ -107,10 +107,10 @@ body {
|
|||||||
|
|
||||||
img.server-info-icon {
|
img.server-info-icon {
|
||||||
background: #a4d3c4;
|
background: #a4d3c4;
|
||||||
background-size: 100%;
|
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
width: 44px;
|
width: 28px;
|
||||||
height: 44px;
|
height: 28px;
|
||||||
|
padding: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.server-info-left {
|
.server-info-left {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class ServerTab extends Tab {
|
|||||||
template() {
|
template() {
|
||||||
return `<div class="tab">
|
return `<div class="tab">
|
||||||
<div class="server-tab-badge"></div>
|
<div class="server-tab-badge"></div>
|
||||||
<div class="server-tab" style="background-image: url(${this.props.icon});"></div>
|
<div class="server-tab" style="background-image: url('${this.props.icon}');"></div>
|
||||||
<div class="server-tab-shortcut">${this.generateShortcutText()}</div>
|
<div class="server-tab-shortcut">${this.generateShortcutText()}</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,9 +64,9 @@ class NewServerForm extends BaseComponent {
|
|||||||
url: domain,
|
url: domain,
|
||||||
icon: this.$newServerIcon.value
|
icon: this.$newServerIcon.value
|
||||||
};
|
};
|
||||||
DomainUtil.addDomain(server);
|
DomainUtil.addDomain(server).then(() => {
|
||||||
|
this.props.onChange(this.props.index);
|
||||||
this.props.onChange(this.props.index);
|
});
|
||||||
}, errorMessage => {
|
}, errorMessage => {
|
||||||
alert(errorMessage);
|
alert(errorMessage);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,10 +3,13 @@
|
|||||||
const {app} = require('electron').remote;
|
const {app} = require('electron').remote;
|
||||||
const JsonDB = require('node-json-db');
|
const JsonDB = require('node-json-db');
|
||||||
const request = require('request');
|
const request = require('request');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
let instance = null;
|
let instance = null;
|
||||||
|
|
||||||
const defaultIconUrl = __dirname + '../../../img/icon.png';
|
const defaultIconUrl = __dirname + '../../../img/icon.png';
|
||||||
|
|
||||||
class DomainUtil {
|
class DomainUtil {
|
||||||
constructor() {
|
constructor() {
|
||||||
if (instance) {
|
if (instance) {
|
||||||
@@ -41,8 +44,19 @@ class DomainUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addDomain(server) {
|
addDomain(server) {
|
||||||
server.icon = server.icon || defaultIconUrl;
|
return new Promise((res, rej) => {
|
||||||
this.db.push('/domains[]', server, true);
|
if (server.icon) {
|
||||||
|
this.saveServerIcon(server.icon).then((localIconUrl) => {
|
||||||
|
server.icon = localIconUrl;
|
||||||
|
this.db.push('/domains[]', server, true);
|
||||||
|
res();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
server.icon = defaultIconUrl;
|
||||||
|
this.db.push('/domains[]', server, true);
|
||||||
|
res();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
removeDomains() {
|
removeDomains() {
|
||||||
@@ -77,6 +91,31 @@ class DomainUtil {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
saveServerIcon(url) {
|
||||||
|
// The save will always succeed. If url is invalid, downgrade to default icon.
|
||||||
|
const dir = `${app.getPath('userData')}/server-icons`;
|
||||||
|
|
||||||
|
if (!fs.existsSync(dir)){
|
||||||
|
fs.mkdirSync(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise((res, rej) => {
|
||||||
|
const filePath = `${dir}/${new Date().getMilliseconds()}${path.extname(url)}`;
|
||||||
|
let file = fs.createWriteStream(filePath);
|
||||||
|
console.log(filePath);
|
||||||
|
try {
|
||||||
|
let req = request(url);
|
||||||
|
req.on('response', response => {
|
||||||
|
response.pipe(file);
|
||||||
|
res(filePath);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
res(defaultIconUrl);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = new DomainUtil();
|
module.exports = new DomainUtil();
|
||||||
|
|||||||
Reference in New Issue
Block a user