mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-27 04:26:44 -06:00
36 lines
937 B
TypeScript
36 lines
937 B
TypeScript
import MiOS from '../../mios';
|
|
import { version as current } from '../../config';
|
|
|
|
export default async function(mios: MiOS, force = false, silent = false) {
|
|
const meta = await mios.getMeta(force);
|
|
const newer = meta.clientVersion;
|
|
|
|
if (newer != current) {
|
|
localStorage.setItem('should-refresh', 'true');
|
|
localStorage.setItem('v', newer);
|
|
|
|
// Clear cache (service worker)
|
|
try {
|
|
if (navigator.serviceWorker.controller) {
|
|
navigator.serviceWorker.controller.postMessage('clear');
|
|
}
|
|
|
|
navigator.serviceWorker.getRegistrations().then(registrations => {
|
|
registrations.forEach(registration => registration.unregister());
|
|
});
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
|
|
if (!silent) {
|
|
mios.apis.dialog({
|
|
title: '%i18n:common.update-available-title%',
|
|
text: '%i18n:common.update-available%'.replace('{newer}', newer).replace('{current}', current)
|
|
});
|
|
}
|
|
|
|
return newer;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|