mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-28 18:14:08 +08:00
fix(autoload-images): Bar disappears when you choose to load images
This commit is contained in:
parent
9bb181ef3e
commit
6d43c9623c
3 changed files with 42 additions and 16 deletions
|
@ -10,10 +10,31 @@ export default class AutoloadImagesHeader extends React.Component {
|
||||||
message: React.PropTypes.instanceOf(Message).isRequired,
|
message: React.PropTypes.instanceOf(Message).isRequired,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
blocking: AutoloadImagesStore.shouldBlockImagesIn(this.props.message),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this._unlisten = AutoloadImagesStore.listen(() => {
|
||||||
|
const blocking = AutoloadImagesStore.shouldBlockImagesIn(this.props.message);
|
||||||
|
if (blocking !== this.state.blocking) {
|
||||||
|
this.setState({blocking});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
this._unlisten();
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {message} = this.props;
|
const {message} = this.props;
|
||||||
|
const {blocking} = this.state;
|
||||||
|
|
||||||
if (AutoloadImagesStore.shouldBlockImagesIn(message) === false) {
|
if (blocking === false) {
|
||||||
return (
|
return (
|
||||||
<div></div>
|
<div></div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -15,19 +15,21 @@ class AutoloadImagesStore extends NylasStore {
|
||||||
|
|
||||||
this._whitelistEmails = {}
|
this._whitelistEmails = {}
|
||||||
this._whitelistMessageIds = {}
|
this._whitelistMessageIds = {}
|
||||||
this._whitelistEmailsPath = path.join(NylasEnv.getConfigDirPath(), 'autoload-images-whitelist.txt');
|
|
||||||
|
const filename = 'autoload-images-whitelist.txt';
|
||||||
|
this._whitelistEmailsPath = path.join(NylasEnv.getConfigDirPath(), filename);
|
||||||
|
|
||||||
this._loadWhitelist();
|
this._loadWhitelist();
|
||||||
|
|
||||||
this.listenTo(AutoloadImagesActions.temporarilyEnableImages, this._onTemporarilyEnableImages);
|
this.listenTo(AutoloadImagesActions.temporarilyEnableImages, this._onTemporarilyEnableImages);
|
||||||
this.listenTo(AutoloadImagesActions.permanentlyEnableImages, this._onPermanentlyEnableImages);
|
this.listenTo(AutoloadImagesActions.permanentlyEnableImages, this._onPermanentlyEnableImages);
|
||||||
|
|
||||||
NylasEnv.config.onDidChange('core.reading.autoloadImages', ()=> {
|
NylasEnv.config.onDidChange('core.reading.autoloadImages', () => {
|
||||||
MessageBodyProcessor.resetCache()
|
MessageBodyProcessor.resetCache();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldBlockImagesIn = (message)=> {
|
shouldBlockImagesIn = (message) => {
|
||||||
if (NylasEnv.config.get('core.reading.autoloadImages') === true) {
|
if (NylasEnv.config.get('core.reading.autoloadImages') === true) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -41,22 +43,26 @@ class AutoloadImagesStore extends NylasStore {
|
||||||
return ImagesRegexp.test(message.body);
|
return ImagesRegexp.test(message.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
_loadWhitelist = ()=> {
|
_loadWhitelist = () => {
|
||||||
fs.exists(this._whitelistEmailsPath, (exists)=> {
|
fs.exists(this._whitelistEmailsPath, (exists) => {
|
||||||
if (!exists) { return; }
|
if (!exists) { return; }
|
||||||
|
|
||||||
fs.readFile(this._whitelistEmailsPath, (err, body)=> {
|
fs.readFile(this._whitelistEmailsPath, (err, body) => {
|
||||||
if (err || !body) { return console.log(err); }
|
if (err || !body) {
|
||||||
|
console.log(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this._whitelistEmails = {}
|
this._whitelistEmails = {}
|
||||||
body.toString().split(/[\n\r]+/).forEach((email)=> {
|
body.toString().split(/[\n\r]+/).forEach((email) => {
|
||||||
this._whitelistEmails[Utils.toEquivalentEmailForm(email)] = true;
|
this._whitelistEmails[Utils.toEquivalentEmailForm(email)] = true;
|
||||||
});
|
});
|
||||||
|
this.trigger();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_saveWhitelist = ()=> {
|
_saveWhitelist = () => {
|
||||||
const data = Object.keys(this._whitelistEmails).join('\n');
|
const data = Object.keys(this._whitelistEmails).join('\n');
|
||||||
fs.writeFile(this._whitelistEmailsPath, data, (err) => {
|
fs.writeFile(this._whitelistEmailsPath, data, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -65,16 +71,18 @@ class AutoloadImagesStore extends NylasStore {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTemporarilyEnableImages = (message)=> {
|
_onTemporarilyEnableImages = (message) => {
|
||||||
this._whitelistMessageIds[message.id] = true;
|
this._whitelistMessageIds[message.id] = true;
|
||||||
MessageBodyProcessor.resetCache();
|
MessageBodyProcessor.resetCache();
|
||||||
|
this.trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
_onPermanentlyEnableImages = (message)=> {
|
_onPermanentlyEnableImages = (message) => {
|
||||||
const email = Utils.toEquivalentEmailForm(message.fromContact().email);
|
const email = Utils.toEquivalentEmailForm(message.fromContact().email);
|
||||||
this._whitelistEmails[email] = true;
|
this._whitelistEmails[email] = true;
|
||||||
MessageBodyProcessor.resetCache();
|
MessageBodyProcessor.resetCache();
|
||||||
setTimeout(this._saveWhitelist, 1);
|
setTimeout(this._saveWhitelist, 1);
|
||||||
|
this.trigger();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,5 @@
|
||||||
"private": true,
|
"private": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"nylas": "*"
|
"nylas": "*"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"autolinker": "0.18.1"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue