add update notifier

This commit is contained in:
dragonwocky 2020-07-09 21:31:17 +10:00
parent d1875ffc90
commit b5043508d9
Signed by: dragonwocky
GPG Key ID: C7A48B7846AA706D
2 changed files with 34 additions and 2 deletions

View File

@ -126,7 +126,8 @@ try:
f' ...linking to {os.path.join(".", "resources", "user.css")}')
with open(os.path.join(__dirname__, 'resources', 'preload.js'), 'r', encoding='UTF-8') as insert:
append.write(insert.read().replace(
'☃☃☃resources☃☃☃', os.path.join(enhancer_folder, 'resources').replace('\\', '/')))
'☃☃☃resources☃☃☃', os.path.join(enhancer_folder, 'resources').replace('\\', '/'))
.replace('☃☃☃version☃☃☃', enhancer_version))
else:
print(
f' * {os.path.join(filepath, "app","renderer","preload.js")} was not found: step skipped.')

View File

@ -167,9 +167,40 @@ require('electron').remote.getGlobal('setTimeout')(() => {
el.outerHTML = `<span>${el.getAttribute('alt')}</span>`;
});
});
observer.observe(document, { childList: true, subtree: true });
observer.observe(document, {
childList: true,
subtree: true,
});
}
/* update checker */
fetch(
`https://api.github.com/repos/dragonwocky/notion-enhancer/releases/latest`
)
.then((res) => res.json())
.then((res) => {
const local_version = '☃☃☃version☃☃☃'.split('~')[0],
repo_version = res.tag_name.slice(1);
// compare func from https://github.com/substack/semver-compare
if (
local_version != repo_version &&
[local_version, repo_version].sort((a, b) => {
var pa = a.split('.');
var pb = b.split('.');
for (var i = 0; i < 3; i++) {
var na = Number(pa[i]);
var nb = Number(pb[i]);
if (na > nb) return 1;
if (nb > na) return -1;
if (!isNaN(na) && isNaN(nb)) return 1;
if (isNaN(na) && !isNaN(nb)) return -1;
}
return 0;
})[0] == local_version
)
alert('notion-enhancer update available!');
});
/* hotkey: reload window */
document.defaultView.addEventListener(
'keyup',