mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-13 09:17:20 +00:00
@@ -84,6 +84,11 @@ interface SideJob {
|
|||||||
encoderState?: EncoderState;
|
encoderState?: EncoderState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface LoadingFileInfo {
|
||||||
|
loading: boolean;
|
||||||
|
filename?: string;
|
||||||
|
}
|
||||||
|
|
||||||
async function decodeImage(
|
async function decodeImage(
|
||||||
signal: AbortSignal,
|
signal: AbortSignal,
|
||||||
blob: Blob,
|
blob: Blob,
|
||||||
@@ -257,12 +262,17 @@ function processorStateEquivalent(a: ProcessorState, b: ProcessorState) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const loadingIndicator = '⏳ ';
|
||||||
|
|
||||||
const originalDocumentTitle = document.title;
|
const originalDocumentTitle = document.title;
|
||||||
|
|
||||||
function updateDocumentTitle(filename: string = ''): void {
|
function updateDocumentTitle(loadingFileInfo: LoadingFileInfo): void {
|
||||||
document.title = filename
|
const { loading, filename } = loadingFileInfo;
|
||||||
? `${filename} - ${originalDocumentTitle}`
|
let title = '';
|
||||||
: originalDocumentTitle;
|
if (loading) title += loadingIndicator;
|
||||||
|
if (filename) title += filename + ' - ';
|
||||||
|
title += originalDocumentTitle;
|
||||||
|
document.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Compress extends Component<Props, State> {
|
export default class Compress extends Component<Props, State> {
|
||||||
@@ -366,7 +376,7 @@ export default class Compress extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount(): void {
|
componentWillUnmount(): void {
|
||||||
updateDocumentTitle();
|
updateDocumentTitle({ loading: false });
|
||||||
this.mainAbortController.abort();
|
this.mainAbortController.abort();
|
||||||
for (const controller of this.sideAbortControllers) {
|
for (const controller of this.sideAbortControllers) {
|
||||||
controller.abort();
|
controller.abort();
|
||||||
@@ -374,6 +384,21 @@ export default class Compress extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps: Props, prevState: State): void {
|
componentDidUpdate(prevProps: Props, prevState: State): void {
|
||||||
|
const wasLoading =
|
||||||
|
prevState.loading ||
|
||||||
|
prevState.sides[0].loading ||
|
||||||
|
prevState.sides[1].loading;
|
||||||
|
const isLoading =
|
||||||
|
this.state.loading ||
|
||||||
|
this.state.sides[0].loading ||
|
||||||
|
this.state.sides[1].loading;
|
||||||
|
const sourceChanged = prevState.source !== this.state.source;
|
||||||
|
if (wasLoading !== isLoading || sourceChanged) {
|
||||||
|
updateDocumentTitle({
|
||||||
|
loading: isLoading,
|
||||||
|
filename: this.state.source?.file.name,
|
||||||
|
});
|
||||||
|
}
|
||||||
this.queueUpdateImage();
|
this.queueUpdateImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -669,7 +694,6 @@ export default class Compress extends Component<Props, State> {
|
|||||||
}) as [Side, Side],
|
}) as [Side, Side],
|
||||||
};
|
};
|
||||||
newState = stateForNewSourceData(newState);
|
newState = stateForNewSourceData(newState);
|
||||||
updateDocumentTitle(source.file.name);
|
|
||||||
return newState;
|
return newState;
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user