mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-06-02 03:58:36 +01:00
Show app usage
- Added app usage to settings - add more readable size formats
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useSettings } from "@/utils/atoms/settings";
|
||||
import { getOrSetDeviceId } from "@/utils/device";
|
||||
import { writeToLog } from "@/utils/log";
|
||||
import {useLog, writeToLog} from "@/utils/log";
|
||||
import {
|
||||
cancelAllJobs,
|
||||
cancelJobById,
|
||||
@@ -69,6 +69,7 @@ function useDownloadProvider() {
|
||||
const [settings] = useSettings();
|
||||
const router = useRouter();
|
||||
const [api] = useAtom(apiAtom);
|
||||
const { logs } = useLog();
|
||||
|
||||
const {saveSeriesPrimaryImage} = useDownloadHelper();
|
||||
const { saveImage } = useImageStorage();
|
||||
@@ -403,7 +404,7 @@ function useDownloadProvider() {
|
||||
});
|
||||
};
|
||||
|
||||
const forEveryDirectory = async (callback: (dir: FileInfo) => void) => {
|
||||
const forEveryDirectoryFile = async (includeMMKV: boolean = true, callback: (file: FileInfo) => void) => {
|
||||
const baseDirectory = FileSystem.documentDirectory;
|
||||
if (!baseDirectory) {
|
||||
throw new Error("Base directory not found");
|
||||
@@ -413,7 +414,7 @@ function useDownloadProvider() {
|
||||
for (const item of dirContents) {
|
||||
// Exclude mmkv directory.
|
||||
// Deleting this deletes all user information as well. Logout should handle this.
|
||||
if (item == "mmkv")
|
||||
if (item == "mmkv" && !includeMMKV)
|
||||
continue
|
||||
const itemInfo = await FileSystem.getInfoAsync(`${baseDirectory}${item}`);
|
||||
if (itemInfo.exists) {
|
||||
@@ -423,9 +424,9 @@ function useDownloadProvider() {
|
||||
}
|
||||
|
||||
const deleteLocalFiles = async (): Promise<void> => {
|
||||
await forEveryDirectory((dir) => {
|
||||
console.warn("Deleting file", dir.uri)
|
||||
FileSystem.deleteAsync(dir.uri, {idempotent: true})
|
||||
await forEveryDirectoryFile(false, (file) => {
|
||||
console.warn("Deleting file", file.uri)
|
||||
FileSystem.deleteAsync(file.uri, {idempotent: true})
|
||||
}
|
||||
)
|
||||
};
|
||||
@@ -534,15 +535,17 @@ function useDownloadProvider() {
|
||||
);
|
||||
}
|
||||
|
||||
const getAppSizeUsage = async () => {
|
||||
const appSizeUsage = useMemo(async () => {
|
||||
const sizes: number[] = [];
|
||||
await forEveryDirectory(dir => {
|
||||
if (dir.exists)
|
||||
sizes.push(dir.size)
|
||||
})
|
||||
await forEveryDirectoryFile(
|
||||
true,
|
||||
file => {
|
||||
if (file.exists) sizes.push(file.size)
|
||||
}
|
||||
)
|
||||
|
||||
return sizes.reduce((sum, size) => sum + size, 0);
|
||||
}
|
||||
}, [logs, downloadedFiles])
|
||||
|
||||
function getDownloadedItem(itemId: string): DownloadedItem | null {
|
||||
try {
|
||||
@@ -623,7 +626,7 @@ function useDownloadProvider() {
|
||||
startDownload,
|
||||
getDownloadedItem,
|
||||
deleteFileByType,
|
||||
getAppSizeUsage
|
||||
appSizeUsage
|
||||
};
|
||||
}
|
||||
|
||||
@@ -646,9 +649,17 @@ export function useDownload() {
|
||||
}
|
||||
|
||||
export function bytesToReadable(bytes: number): string {
|
||||
const gb = bytes / 1e+9;
|
||||
const gb = bytes / 1e9;
|
||||
|
||||
if (gb >= 1)
|
||||
return `${gb.toFixed(2)} GB`
|
||||
return `${(bytes / 1024 / 1024).toFixed(2)} MB`
|
||||
|
||||
const mb = bytes / 1024 / 1024
|
||||
if (mb >= 1)
|
||||
return `${mb.toFixed(2)} MB`
|
||||
|
||||
const kb = bytes / 1024
|
||||
if (kb >= 1)
|
||||
return `${kb.toFixed(2)} KB`
|
||||
return `${bytes.toFixed(2)} B`
|
||||
}
|
||||
Reference in New Issue
Block a user