Improved icon handling and download

This commit is contained in:
WolverinDEV 2019-06-26 14:06:20 +02:00
parent c74206dfb7
commit c5468b5e3b
4 changed files with 48 additions and 4 deletions

View file

@ -161,6 +161,8 @@
flex-direction: column; flex-direction: column;
.container-select { .container-select {
min-height: 130px;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: stretch; justify-content: stretch;
@ -171,7 +173,8 @@
width: min-content; width: min-content;
min-width: 150px; min-width: 150px;
min-height: 200px; min-height: 130px;
overflow-y: auto;
margin-right: 5px; margin-right: 5px;
@ -226,6 +229,9 @@
} }
.container-upload { .container-upload {
display: flex;
flex-direction: column;
margin-top: 5px; margin-top: 5px;
border-top: 1px solid darkgray; border-top: 1px solid darkgray;
padding-top: 5px; padding-top: 5px;
@ -247,6 +253,7 @@
.container-success { .container-success {
margin-top: 5px; margin-top: 5px;
min-height: 100px;
} }
.container-info { .container-info {
@ -259,6 +266,8 @@
width: 100%; width: 100%;
min-height: 100px; min-height: 100px;
overflow-y: auto;
border: gray solid 1px; border: gray solid 1px;
border-radius: 2px; border-radius: 2px;

View file

@ -84,8 +84,10 @@ class RequestFileDownload implements transfer.DownloadTransfer {
'Access-Control-Expose-Headers': '*' 'Access-Control-Expose-Headers': '*'
} }
}); });
if(!response.ok) if(!response.ok) {
debugger;
throw (response.type == 'opaque' || response.type == 'opaqueredirect' ? "invalid cross origin flag! May target isn't a TeaSpeak server?" : response.statusText || "response is not ok"); throw (response.type == 'opaque' || response.type == 'opaqueredirect' ? "invalid cross origin flag! May target isn't a TeaSpeak server?" : response.statusText || "response is not ok");
}
return response; return response;
} }
@ -449,6 +451,22 @@ class CacheManager {
setupped() : boolean { return !!this._cache_category; } setupped() : boolean { return !!this._cache_category; }
async reset() {
if(!window.caches)
return;
try {
await caches.delete(this.cache_name);
} catch(error) {
throw "Failed to delete cache: " + error;
}
try {
await this.setup();
} catch(error) {
throw "Failed to reinitialize cache!";
}
}
async setup() { async setup() {
if(!window.caches) if(!window.caches)
throw "Missing caches!"; throw "Missing caches!";
@ -503,6 +521,16 @@ class IconManager {
IconManager.cache = new CacheManager("icons"); IconManager.cache = new CacheManager("icons");
} }
async clear_cache() {
await IconManager.cache.reset();
if(URL.revokeObjectURL) {
for(const id of Object.keys(this._id_urls))
URL.revokeObjectURL(this._id_urls[id]);
}
this._id_urls = {};
this._loading_promises = {};
}
async delete_icon(id: number) : Promise<void> { async delete_icon(id: number) : Promise<void> {
if(id <= 1000) if(id <= 1000)
throw "invalid id!"; throw "invalid id!";

View file

@ -135,6 +135,11 @@ class StaticSettings extends SettingsBase {
} }
class Settings extends StaticSettings { class Settings extends StaticSettings {
static readonly KEY_DISABLE_COSMETIC_SLOWDOWN: SettingsKey<boolean> = {
key: 'disable_cosmetic_slowdown',
description: 'Disable the cosmetic slowdows in some processes, like icon upload.'
};
static readonly KEY_DISABLE_CONTEXT_MENU: SettingsKey<boolean> = { static readonly KEY_DISABLE_CONTEXT_MENU: SettingsKey<boolean> = {
key: 'disableContextMenu', key: 'disableContextMenu',
description: 'Disable the context menu for the channel tree which allows to debug the DOM easier' description: 'Disable the context menu for the channel tree which allows to debug the DOM easier'

View file

@ -384,6 +384,7 @@ namespace Modals {
}) })
} catch(error) { } catch(error) {
if(error instanceof CommandResult && error.id == ErrorID.FILE_ALREADY_EXISTS) { if(error instanceof CommandResult && error.id == ErrorID.FILE_ALREADY_EXISTS) {
if(!settings.static_global(Settings.KEY_DISABLE_COSMETIC_SLOWDOWN, false))
await new Promise(resolve => setTimeout(resolve, 500 + Math.floor(Math.random() * 500))); await new Promise(resolve => setTimeout(resolve, 500 + Math.floor(Math.random() * 500)));
bar.set_message(tr("icon already exists")); bar.set_message(tr("icon already exists"));
bar.set_value(100); bar.set_value(100);
@ -412,6 +413,7 @@ namespace Modals {
} }
const time_end = Date.now(); const time_end = Date.now();
if(!settings.static_global(Settings.KEY_DISABLE_COSMETIC_SLOWDOWN, false))
await new Promise(resolve => setTimeout(resolve, Math.max(0, 1000 - (time_end - time_begin)))); await new Promise(resolve => setTimeout(resolve, Math.max(0, 1000 - (time_end - time_begin))));
bar.set_value(100); bar.set_value(100);
bar.set_message(tr("upload completed")); bar.set_message(tr("upload completed"));