Skip to content

Commit 809d91b

Browse files
committed
chore: promises store resolved values
So make use of this!
1 parent 4cdae0d commit 809d91b

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# UnderScript App Changelog
22

33
## Version 1.4.0 (2020-03-06)
4-
1. Fixed UnderScript so it can actually update
4+
1. Can now update UnderScript without having to restart
55
1. URL's now open in browser
66
1. Remember Me now shows that it does something in the app
77

src/preload/plugin.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
const { ipcRenderer } = require('electron');
22

3-
const promise = new Promise((res) => {
3+
// Acts as a cache for the resulting plugin
4+
const plugin = new Promise((res) => {
45
document.addEventListener('DOMContentLoaded', () => {
5-
plugin = underscript.plugin('UnderScript App');
6-
res(plugin);
7-
}, { once: true });
6+
res(underscript.plugin('UnderScript App'));
7+
});
88
});
99

10-
let plugin;
1110
function getPlugin() {
12-
if (plugin) return Promise.resolve(plugin);
13-
return promise;
11+
return Promise.resolve(plugin); // Hand out a fresh promise
1412
}
1513

1614
ipcRenderer.on('toast', (_, data) => {
1715
getPlugin().then((plugin) => {
16+
if (!plugin) return; // Should never happen, but who knows
1817
if (data.refresh) {
1918
data.onClose = (...args) => {
2019
location.reload();
2120
};
2221
delete data.refresh;
2322
}
2423
plugin.toast(data);
25-
return plugin;
2624
});
2725
});
2826

0 commit comments

Comments
 (0)