Storage-Info hinzugefügt
This commit is contained in:
@@ -20,7 +20,13 @@ import "./lib/pwa-contact"
|
||||
|
||||
import {SettingsManager, SettingsSite} from "./lib/pwa-core";
|
||||
|
||||
import {InstallManager, Matomo, MatomoShareButton, SoundManager} from "./lib/pwa-assets";
|
||||
import {
|
||||
InstallManager,
|
||||
Matomo,
|
||||
MatomoShareButton,
|
||||
MyStorageManager,
|
||||
SoundManager
|
||||
} from "./lib/pwa-assets";
|
||||
import {MenuSite} from "../module/Application/pwa/js/site/MenuSite";
|
||||
import {WordRotatorSettingFragment} from "../module/Application/pwa/js/Fragment/WordRotatorSettingFragment";
|
||||
|
||||
@@ -83,5 +89,7 @@ InitPromise.resolve(app).then(async function () {
|
||||
InstallManager.setCanInstallListener(e => {
|
||||
});
|
||||
|
||||
MyStorageManager.getInstance().persist();
|
||||
|
||||
window["applyAndroidBridge"] = AndroidBridge.applyDefinitions;
|
||||
});
|
||||
|
||||
@@ -8,6 +8,55 @@ class DelayPromise extends Promise {
|
||||
}
|
||||
}
|
||||
|
||||
class MyStorageManager {
|
||||
static getInstance() {
|
||||
if (Helper.isNull(MyStorageManager.instance)) {
|
||||
MyStorageManager.instance = new MyStorageManager();
|
||||
}
|
||||
return MyStorageManager.instance;
|
||||
}
|
||||
|
||||
async estimate() {
|
||||
if ('storage' in navigator && 'estimate' in navigator.storage) {
|
||||
// We've got the real thing! Return its response.
|
||||
return navigator.storage.estimate();
|
||||
}
|
||||
|
||||
if ('webkitTemporaryStorage' in navigator &&
|
||||
'queryUsageAndQuota' in navigator.webkitTemporaryStorage) {
|
||||
// Return a promise-based wrapper that will follow the expected interface.
|
||||
return new Promise(function (resolve, reject) {
|
||||
navigator.webkitTemporaryStorage.queryUsageAndQuota(
|
||||
function (usage, quota) {
|
||||
resolve({usage: usage, quota: quota});
|
||||
},
|
||||
reject
|
||||
);
|
||||
});
|
||||
}
|
||||
// If we can't estimate the values, return a Promise that resolves with NaN.
|
||||
return Promise.resolve({usage: NaN, quota: NaN});
|
||||
}
|
||||
|
||||
canEstimateStorage() {
|
||||
return ('storage' in navigator && 'estimate' in navigator.storage || 'webkitTemporaryStorage' in navigator &&
|
||||
'queryUsageAndQuota' in navigator.webkitTemporaryStorage);
|
||||
}
|
||||
|
||||
canPersist() {
|
||||
return (navigator.storage && navigator.storage.persist);
|
||||
}
|
||||
|
||||
persist(){
|
||||
if (this.canPersist()){
|
||||
return navigator.storage.persist();
|
||||
}
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
}
|
||||
|
||||
MyStorageManager.instance = null;
|
||||
|
||||
class InstallManager {
|
||||
static init() {
|
||||
window.addEventListener('beforeinstallprompt', e => {
|
||||
@@ -26,7 +75,10 @@ class InstallManager {
|
||||
static async prompt(){
|
||||
if (Helper.isNotNull(this.deferredPromt)){
|
||||
this.deferredPromt["prompt"]();
|
||||
return this.deferredPromt["userChoice"];
|
||||
return this.deferredPromt["userChoice"].then(r => {
|
||||
MyStorageManager.getInstance().persist();
|
||||
return r;
|
||||
});
|
||||
}
|
||||
return Promise.resolve({
|
||||
"outcome":"dismissed",
|
||||
@@ -535,44 +587,6 @@ InitPromise.addPromise(() => {
|
||||
// window["soundManagerInstance"]["resumeAllIfNotMuted"] = window["soundManagerInstance"].resumeAllIfNotMuted;
|
||||
// });
|
||||
|
||||
class StorageManager {
|
||||
static getInstance() {
|
||||
if (Helper.isNull(StorageManager.instance)) {
|
||||
StorageManager.instance = new StorageManager();
|
||||
}
|
||||
return StorageManager.instance;
|
||||
}
|
||||
|
||||
async estimate() {
|
||||
if ('storage' in navigator && 'estimate' in navigator.storage) {
|
||||
// We've got the real thing! Return its response.
|
||||
return navigator.storage.estimate();
|
||||
}
|
||||
|
||||
if ('webkitTemporaryStorage' in navigator &&
|
||||
'queryUsageAndQuota' in navigator.webkitTemporaryStorage) {
|
||||
// Return a promise-based wrapper that will follow the expected interface.
|
||||
return new Promise(function (resolve, reject) {
|
||||
navigator.webkitTemporaryStorage.queryUsageAndQuota(
|
||||
function (usage, quota) {
|
||||
resolve({usage: usage, quota: quota});
|
||||
},
|
||||
reject
|
||||
);
|
||||
});
|
||||
}
|
||||
// If we can't estimate the values, return a Promise that resolves with NaN.
|
||||
return Promise.resolve({usage: NaN, quota: NaN});
|
||||
}
|
||||
|
||||
canEstimateStorage() {
|
||||
return ('storage' in navigator && 'estimate' in navigator.storage || 'webkitTemporaryStorage' in navigator &&
|
||||
'queryUsageAndQuota' in navigator.webkitTemporaryStorage);
|
||||
}
|
||||
}
|
||||
|
||||
StorageManager.instance = null;
|
||||
|
||||
class TabbedFragment extends Fragment {
|
||||
constructor(site) {
|
||||
super(site, 'pwaAssets/html/fragment/tabbedFragment.html');
|
||||
@@ -638,4 +652,4 @@ class TabbedFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
export { DelayPromise, InstallManager, Matomo, MatomoShareButton, RotateHelper, ScaleHelper, AudioChain, SoundManager, StorageManager, TabbedFragment };
|
||||
export { DelayPromise, InstallManager, Matomo, MatomoShareButton, MyStorageManager, RotateHelper, ScaleHelper, AudioChain, SoundManager, TabbedFragment };
|
||||
|
||||
Reference in New Issue
Block a user