Browse Source

Fix rendering dark background preview

Add document download byte progress
Fix going back to first folder
master
Eduard Kuzmenko 2 years ago
parent
commit
60afd4f748
  1. 2
      src/components/sidebarLeft/tabs/background.ts
  2. 32
      src/components/wrappers/document.ts
  3. 4
      src/lib/appManagers/appDialogsManager.ts

2
src/components/sidebarLeft/tabs/background.ts

@ -256,7 +256,7 @@ export default class AppBackgroundTab extends SliderSuperTab {
loadPromises.full.then(async() => { loadPromises.full.then(async() => {
const cacheContext = await this.managers.thumbsStorage.getCacheContext(doc, size.type); const cacheContext = await this.managers.thumbsStorage.getCacheContext(doc, size.type);
canvas.style.webkitMaskImage = `url(${cacheContext.url})`; canvas.style.webkitMaskImage = `url(${cacheContext.url})`;
canvas.style.opacity = '' + Math.abs(wallPaper.settings.intensity) / 100; canvas.style.opacity = '' + (wallPaper.pFlags.dark ? 100 + wallPaper.settings.intensity : wallPaper.settings.intensity) / 100;
media.append(canvas); media.append(canvas);
}); });
}); });

32
src/components/wrappers/document.ts

@ -5,15 +5,17 @@
*/ */
import MEDIA_MIME_TYPES_SUPPORTED from "../../environment/mediaMimeTypesSupport"; import MEDIA_MIME_TYPES_SUPPORTED from "../../environment/mediaMimeTypesSupport";
import { CancellablePromise } from "../../helpers/cancellablePromise";
import { clearBadCharsAndTrim } from "../../helpers/cleanSearchText"; import { clearBadCharsAndTrim } from "../../helpers/cleanSearchText";
import { formatFullSentTime } from "../../helpers/date"; import { formatFullSentTime } from "../../helpers/date";
import { simulateClickEvent, attachClickEvent } from "../../helpers/dom/clickEvent"; import { simulateClickEvent, attachClickEvent } from "../../helpers/dom/clickEvent";
import replaceContent from "../../helpers/dom/replaceContent";
import formatBytes from "../../helpers/formatBytes"; import formatBytes from "../../helpers/formatBytes";
import { MediaSizeType } from "../../helpers/mediaSizes"; import { MediaSizeType } from "../../helpers/mediaSizes";
import noop from "../../helpers/noop"; import noop from "../../helpers/noop";
import { Message, MessageMedia, WebPage } from "../../layer"; import { Message, MessageMedia, WebPage } from "../../layer";
import { MyDocument } from "../../lib/appManagers/appDocsManager"; import { MyDocument } from "../../lib/appManagers/appDocsManager";
import appDownloadManager from "../../lib/appManagers/appDownloadManager"; import appDownloadManager, { Progress } from "../../lib/appManagers/appDownloadManager";
import appImManager from "../../lib/appManagers/appImManager"; import appImManager from "../../lib/appManagers/appImManager";
import { AppManagers } from "../../lib/appManagers/managers"; import { AppManagers } from "../../lib/appManagers/managers";
import getDownloadMediaDetails from "../../lib/appManagers/utils/download/getDownloadMediaDetails"; import getDownloadMediaDetails from "../../lib/appManagers/utils/download/getDownloadMediaDetails";
@ -136,7 +138,8 @@ export default async function wrapDocument({message, withTime, fontWeight, voice
let fileName = doc.file_name ? wrapPlainText(doc.file_name) : 'Unknown.file'; let fileName = doc.file_name ? wrapPlainText(doc.file_name) : 'Unknown.file';
const descriptionEl = document.createElement('div'); const descriptionEl = document.createElement('div');
descriptionEl.classList.add('document-description'); descriptionEl.classList.add('document-description');
const descriptionParts: (HTMLElement | string | DocumentFragment)[] = [formatBytes(doc.size)]; const bytesEl = formatBytes(doc.size);
const descriptionParts: (HTMLElement | string | DocumentFragment)[] = [bytesEl];
if(withTime) { if(withTime) {
descriptionParts.push(formatFullSentTime(message.date)); descriptionParts.push(formatFullSentTime(message.date));
@ -190,10 +193,29 @@ export default async function wrapDocument({message, withTime, fontWeight, voice
} }
}; };
const addByteProgress = (promise: CancellablePromise<any>) => {
const sizeContainer = document.createElement('span');
promise.then(() => {
onLoad();
sizeContainer.replaceWith(bytesEl);
}, () => {
replaceContent(sizeContainer, bytesEl);
});
let d = formatBytes(0);
bytesEl.replaceWith(sizeContainer);
sizeContainer.append(d, ' / ', bytesEl);
promise.addNotifyListener((progress: Progress) => {
const _d = formatBytes(progress.done);
d.replaceWith(_d);
d = _d;
});
};
const load = async(e?: Event) => { const load = async(e?: Event) => {
const save = !e || e.isTrusted; const save = !e || e.isTrusted;
const doc = await managers.appDocsManager.getDoc(docDiv.dataset.docId); const doc = await managers.appDocsManager.getDoc(docDiv.dataset.docId);
let download: Promise<any>; let download: CancellablePromise<any>;
const queueId = appImManager.chat.bubbles ? appImManager.chat.bubbles.lazyLoadQueue.queueId : undefined; const queueId = appImManager.chat.bubbles ? appImManager.chat.bubbles.lazyLoadQueue.queueId : undefined;
if(!save) { if(!save) {
download = appDownloadManager.downloadMediaVoid({media: doc, queueId}); download = appDownloadManager.downloadMediaVoid({media: doc, queueId});
@ -215,8 +237,8 @@ export default async function wrapDocument({message, withTime, fontWeight, voice
} }
if(downloadDiv) { if(downloadDiv) {
download.then(onLoad, noop);
preloader.attach(downloadDiv, true, download); preloader.attach(downloadDiv, true, download);
addByteProgress(download);
} }
}; };
@ -247,7 +269,7 @@ export default async function wrapDocument({message, withTime, fontWeight, voice
const uploadPromise = appDownloadManager.getUpload(uploadFileName); const uploadPromise = appDownloadManager.getUpload(uploadFileName);
preloader.attachPromise(uploadPromise); preloader.attachPromise(uploadPromise);
preloader.attach(downloadDiv); preloader.attach(downloadDiv);
uploadPromise.then(onLoad, noop); addByteProgress(uploadPromise);
} }
} }

4
src/lib/appManagers/appDialogsManager.ts

@ -347,7 +347,7 @@ export class AppDialogsManager {
id += 1; id += 1;
} */ } */
const _id = id;
id = +tabContent.dataset.filterId || FOLDER_ID_ALL; id = +tabContent.dataset.filterId || FOLDER_ID_ALL;
const isFilterAvailable = REAL_FOLDERS.has(id) || await this.managers.filtersStorage.isFilterIdAvailable(id); const isFilterAvailable = REAL_FOLDERS.has(id) || await this.managers.filtersStorage.isFilterIdAvailable(id);
@ -357,7 +357,7 @@ export class AppDialogsManager {
const wasFilterId = this.filterId; const wasFilterId = this.filterId;
if(!IS_MOBILE_SAFARI) { if(!IS_MOBILE_SAFARI) {
if(id) { if(_id) {
if(!this.filtersNavigationItem) { if(!this.filtersNavigationItem) {
this.filtersNavigationItem = { this.filtersNavigationItem = {
type: 'filters', type: 'filters',

Loading…
Cancel
Save