From ef6cc6afb73467feb53813d15bb95042dd1ea4f1 Mon Sep 17 00:00:00 2001 From: ward Date: Mon, 9 Jun 2025 15:15:51 +1200 Subject: [PATCH] Improve caching, improve unique item Id func --- materialious/android/app/build.gradle | 4 ++-- .../electron/materialious.metainfo.xml | 6 +++++- materialious/electron/package-lock.json | 4 ++-- materialious/electron/package.json | 2 +- materialious/package-lock.json | 4 ++-- materialious/package.json | 2 +- .../lib/components/Settings/Interface.svelte | 9 +++++++-- .../src/lib/components/VideoList.svelte | 5 ++++- materialious/src/lib/misc.ts | 2 ++ materialious/src/lib/navPages.ts | 4 +++- materialious/src/routes/(app)/+page.ts | 6 ++++-- .../routes/(app)/search/[slug]/+page.svelte | 4 +++- .../src/routes/(app)/search/[slug]/+page.ts | 6 +++++- .../src/routes/(app)/subscriptions/+page.ts | 3 ++- .../src/routes/(app)/trending/+page.ts | 6 ++++-- update_versions.py | 18 +++++------------- 16 files changed, 52 insertions(+), 33 deletions(-) diff --git a/materialious/android/app/build.gradle b/materialious/android/app/build.gradle index d2b6382c..a7b993a6 100644 --- a/materialious/android/app/build.gradle +++ b/materialious/android/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "us.materialio.app" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 121 - versionName "1.9.4" + versionCode 122 + versionName "1.9.5" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" aaptOptions { // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps. diff --git a/materialious/electron/materialious.metainfo.xml b/materialious/electron/materialious.metainfo.xml index f5605588..24976e82 100644 --- a/materialious/electron/materialious.metainfo.xml +++ b/materialious/electron/materialious.metainfo.xml @@ -56,7 +56,11 @@ - + + + https://github.com/Materialious/Materialious/releases/tag/1.9.5 + + https://github.com/Materialious/Materialious/releases/tag/1.9.4 diff --git a/materialious/electron/package-lock.json b/materialious/electron/package-lock.json index df959c28..77d7bcaf 100644 --- a/materialious/electron/package-lock.json +++ b/materialious/electron/package-lock.json @@ -1,12 +1,12 @@ { "name": "Materialious", - "version": "1.9.3", + "version": "1.9.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "Materialious", - "version": "1.9.3", + "version": "1.9.4", "license": "MIT", "dependencies": { "@capacitor-community/electron": "^5.0.0", diff --git a/materialious/electron/package.json b/materialious/electron/package.json index f395a13c..427bb385 100644 --- a/materialious/electron/package.json +++ b/materialious/electron/package.json @@ -1,6 +1,6 @@ { "name": "Materialious", - "version": "1.9.4", + "version": "1.9.5", "description": "Modern material design for Invidious.", "author": { "name": "Ward Pearce", diff --git a/materialious/package-lock.json b/materialious/package-lock.json index 6ae38161..dc044c0a 100644 --- a/materialious/package-lock.json +++ b/materialious/package-lock.json @@ -1,12 +1,12 @@ { "name": "materialious", - "version": "1.9.1", + "version": "1.9.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "materialious", - "version": "1.9.1", + "version": "1.9.4", "hasInstallScript": true, "dependencies": { "@capacitor-community/electron": "^5.0.1", diff --git a/materialious/package.json b/materialious/package.json index 1fcc8c6e..e0e0e777 100644 --- a/materialious/package.json +++ b/materialious/package.json @@ -1,6 +1,6 @@ { "name": "materialious", - "version": "1.9.4", + "version": "1.9.5", "private": true, "scripts": { "dev": "vite dev", diff --git a/materialious/src/lib/components/Settings/Interface.svelte b/materialious/src/lib/components/Settings/Interface.svelte index 3e5a6bec..47972c31 100644 --- a/materialious/src/lib/components/Settings/Interface.svelte +++ b/materialious/src/lib/components/Settings/Interface.svelte @@ -10,7 +10,7 @@ import { _ } from '$lib/i18n'; import { get } from 'svelte/store'; import { ensureNoTrailingSlash } from '../../misc'; - import { getPages } from '../../navPages'; + import { getPages, type Pages } from '../../navPages'; import { authStore, darkModeStore, @@ -109,6 +109,11 @@ await window.electronAPI.setAllowInsecureSSL(isAllowed); } }); + + let pages: Pages = $state([]); + authStore.subscribe(() => { + pages = getPages(); + }); {#if Capacitor.isNativePlatform()} @@ -314,7 +319,7 @@ bind:value={defaultPage} onchange={() => interfaceDefaultPage.set(defaultPage)} > - {#each getPages() as page} + {#each pages as page} {#if !page.requiresAuth || get(authStore)} diff --git a/materialious/src/lib/components/VideoList.svelte b/materialious/src/lib/components/VideoList.svelte index a4bff508..656847eb 100644 --- a/materialious/src/lib/components/VideoList.svelte +++ b/materialious/src/lib/components/VideoList.svelte @@ -21,10 +21,13 @@ } onMount(() => { - if ($feedLastItemId) + if ($feedLastItemId) { document .getElementById($feedLastItemId) ?.scrollIntoView({ behavior: 'instant', block: 'center', inline: 'nearest' }); + + feedLastItemId.set(undefined); + } }); diff --git a/materialious/src/lib/misc.ts b/materialious/src/lib/misc.ts index 85253e26..f9035a5d 100644 --- a/materialious/src/lib/misc.ts +++ b/materialious/src/lib/misc.ts @@ -80,6 +80,8 @@ export type feedItems = feedItem[]; export function extractUniqueId(item: feedItem): string { if ('videoId' in item) { return item.videoId; + } else if ('playlistId' in item) { + return item.playlistId; } else if ('authorId' in item) { return item.authorId; } else { diff --git a/materialious/src/lib/navPages.ts b/materialious/src/lib/navPages.ts index a3bb0f43..075cf106 100644 --- a/materialious/src/lib/navPages.ts +++ b/materialious/src/lib/navPages.ts @@ -1,8 +1,10 @@ import { _ } from '$lib/i18n'; import { get } from 'svelte/store'; +export type Pages = { icon: string; href: string; name: string; requiresAuth: boolean }[]; + // Must be a func do to how i18n is loaded -export function getPages(): { icon: string; href: string; name: string; requiresAuth: boolean }[] { +export function getPages(): Pages { return [ { icon: 'home', diff --git a/materialious/src/routes/(app)/+page.ts b/materialious/src/routes/(app)/+page.ts index 37b3ed62..14feb4fb 100644 --- a/materialious/src/routes/(app)/+page.ts +++ b/materialious/src/routes/(app)/+page.ts @@ -18,9 +18,11 @@ export async function load() { } } - feedCacheStore.set({ popular }); + feedCacheStore.set({ ...get(feedCacheStore), popular }); } else { - getPopular().then((newPopular) => feedCacheStore.set({ popular: newPopular })); + getPopular().then((newPopular) => + feedCacheStore.set({ ...get(feedCacheStore), popular: newPopular }) + ); } return { diff --git a/materialious/src/routes/(app)/search/[slug]/+page.svelte b/materialious/src/routes/(app)/search/[slug]/+page.svelte index 4dc3e7c5..49210d0e 100644 --- a/materialious/src/routes/(app)/search/[slug]/+page.svelte +++ b/materialious/src/routes/(app)/search/[slug]/+page.svelte @@ -22,6 +22,8 @@ document .getElementById($feedLastItemId) ?.scrollIntoView({ behavior: 'instant', block: 'center', inline: 'nearest' }); + + feedLastItemId.set(undefined); } }); @@ -94,7 +96,7 @@ class="no-padding" style="height: 100%;" role="presentation" - onclick={() => feedLastItemId.set(extractUniqueId(item))} + onclick={async () => feedLastItemId.set(await extractUniqueId(item))} id={extractUniqueId(item)} > {#if item.type === 'video'} diff --git a/materialious/src/routes/(app)/search/[slug]/+page.ts b/materialious/src/routes/(app)/search/[slug]/+page.ts index 597f0f15..ed03be4a 100644 --- a/materialious/src/routes/(app)/search/[slug]/+page.ts +++ b/materialious/src/routes/(app)/search/[slug]/+page.ts @@ -20,13 +20,17 @@ export async function load({ params, url }) { if (!search) { try { - searchCacheStore.set({ [searchStoreId]: await getSearch(params.slug, { type: type }) }); + searchCacheStore.set({ + ...get(searchCacheStore), + [searchStoreId]: await getSearch(params.slug, { type: type }) + }); } catch (errorMessage: any) { error(500, errorMessage); } } else { getSearch(params.slug, { type: type }).then((newSearch) => { searchCacheStore.set({ + ...get(searchCacheStore), [searchStoreId]: excludeDuplicateFeeds(search, newSearch) as ( | Channel | Video diff --git a/materialious/src/routes/(app)/subscriptions/+page.ts b/materialious/src/routes/(app)/subscriptions/+page.ts index 991eaac8..f98b8a5a 100644 --- a/materialious/src/routes/(app)/subscriptions/+page.ts +++ b/materialious/src/routes/(app)/subscriptions/+page.ts @@ -18,11 +18,12 @@ export async function load() { videos = [...feeds.notifications, ...feeds.videos]; - feedCacheStore.set({ subscription: videos }); + feedCacheStore.set({ ...get(feedCacheStore), subscription: videos }); } else { await getFeed(100, 1).then((feeds) => { const newVideos = [...feeds.notifications, ...feeds.videos, ...videos]; feedCacheStore.set({ + ...get(feedCacheStore), subscription: excludeDuplicateFeeds(videos, newVideos) as ( | VideoBase | Video diff --git a/materialious/src/routes/(app)/trending/+page.ts b/materialious/src/routes/(app)/trending/+page.ts index 252f2de0..91f3c46a 100644 --- a/materialious/src/routes/(app)/trending/+page.ts +++ b/materialious/src/routes/(app)/trending/+page.ts @@ -13,8 +13,10 @@ export async function load() { error(500, errorMessage); } - feedCacheStore.set({ trending }); + feedCacheStore.set({ ...get(feedCacheStore), trending }); } else { - getTrending().then((newTrending) => feedCacheStore.set({ trending: newTrending })); + getTrending().then((newTrending) => + feedCacheStore.set({ ...get(feedCacheStore), trending: newTrending }) + ); } } diff --git a/update_versions.py b/update_versions.py index 8f69fc3c..ba36b5ab 100644 --- a/update_versions.py +++ b/update_versions.py @@ -3,19 +3,15 @@ import os import re from datetime import datetime -LATEST_VERSION = "1.9.4" +LATEST_VERSION = "1.9.5" RELEASE_DATE = datetime.now().strftime("%Y-%-m-%d") # Format: YYYY-M-D -WORKING_DIR = os.path.join( - os.path.dirname(os.path.realpath(__file__)), "materialious" -) +WORKING_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "materialious") ROOT_PACKAGE = os.path.join(WORKING_DIR, "package.json") ELECTRON_PACKAGE = os.path.join(WORKING_DIR, "electron", "package.json") ANDROID_PACKAGE = os.path.join(WORKING_DIR, "android", "app", "build.gradle") -METAINFO_FILE = os.path.join( - WORKING_DIR, "electron", "materialious.metainfo.xml" -) +METAINFO_FILE = os.path.join(WORKING_DIR, "electron", "materialious.metainfo.xml") def package_json_update_ver(location: str) -> None: @@ -38,9 +34,7 @@ def update_android_version() -> None: if version_code_match and version_name_match: version_code = int(version_code_match.group(1)) + 1 - contents = re.sub( - r"versionCode\s+\d+", f"versionCode {version_code}", contents - ) + contents = re.sub(r"versionCode\s+\d+", f"versionCode {version_code}", contents) contents = re.sub( r'versionName\s+"[^"]+"', f'versionName "{LATEST_VERSION}"', @@ -66,9 +60,7 @@ def update_metainfo_release() -> None: """ # Insert the new release after the opening tag - updated_contents = re.sub( - r"(\s*)", rf"\1{new_release}\n", contents - ) + updated_contents = re.sub(r"(\s*)", rf"\1{new_release}\n", contents) with open(METAINFO_FILE, "w") as f_: f_.write(updated_contents)