From 815c6a18e8b172c31d53f1ed5f1f98ed63642f30 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Fri, 5 Jan 2024 19:23:37 -0500 Subject: [PATCH 01/11] Customize home screen --- .../Screens/HomeScreen/HomeScreen.bs | 9 +- .../Screens/HomeScreen/HomeScreen.xml | 1 + .../Screens/HomeScreen/HomeScreenUtils.bs | 28 ++++ .../HomeScreenEditor/EditHomeScreenControl.bs | 58 +++++++ .../EditHomeScreenControl.xml | 21 +++ .../HomeScreenEditor/HomeScreenEditor.bs | 148 ++++++++++++++++++ .../HomeScreenEditor/HomeScreenEditor.xml | 53 +++++++ .../Services/Preferences/Preferences.bs | 16 +- .../Middleware/HomeLayoutRouter.bs | 25 +++ .../Web/PlayletWebServer/PlayletWebServer.bs | 2 + .../src/config/default_home_layout.yaml | 8 + playlet-lib/src/config/preferences.json5 | 49 ++++++ playlet-lib/src/source/utils/MathUtils.bs | 19 +++ playlet-web/src/App.svelte | 5 + playlet-web/src/lib/Api/PlayletApi.ts | 6 + playlet-web/src/lib/Screens/HomeScreen.svelte | 4 +- .../EditHomeScreenControl.svelte | 146 +++++++++++++++++ .../lib/Screens/Settings/SettingsNode.svelte | 2 + playlet-web/src/lib/Stores.ts | 2 + .../src/lib/VideoFeed/VideoListRow.svelte | 18 ++- 20 files changed, 606 insertions(+), 14 deletions(-) create mode 100644 playlet-lib/src/components/Screens/HomeScreen/HomeScreenUtils.bs create mode 100644 playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/EditHomeScreenControl.bs create mode 100644 playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/EditHomeScreenControl.xml create mode 100644 playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/HomeScreenEditor.bs create mode 100644 playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/HomeScreenEditor.xml create mode 100644 playlet-lib/src/components/Web/PlayletWebServer/Middleware/HomeLayoutRouter.bs create mode 100644 playlet-lib/src/source/utils/MathUtils.bs create mode 100644 playlet-web/src/lib/Screens/Settings/SettingControls/EditHomeScreenControl.svelte diff --git a/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.bs b/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.bs index 7016fc03..b7b80bb1 100644 --- a/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.bs +++ b/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.bs @@ -1,6 +1,7 @@ import "pkg:/components/ContextMenu/ContextMenuUtils.bs" import "pkg:/components/Navigation/Navigation.bs" import "pkg:/source/utils/FocusManagement.bs" +import "HomeScreenUtils.bs" function Init() m.top.focusable = true @@ -14,7 +15,9 @@ function OnNodeReady() SetNavigation(invalid, "left", m.navBar) m.rowList@.BindNode() - m.rowList.feeds = ParseJson(ReadAsciiFile(m.top.feedFile)) + + m.preferences.observeFieldScoped("misc.home_screen_layout", FuncName(OnHomeLayoutChange)) + OnHomeLayoutChange() end function function OnFocusChange() as void @@ -35,3 +38,7 @@ function GetContextMenuOptionsForItem(rowItem as object) as object refresh = ContextMenuUtils.CreateOption("Refresh Home", m.rowList, "Refresh", [invalid]) return [refresh] end function + +function OnHomeLayoutChange() as void + m.rowList.feeds = HomeScreenUtils.GetFeed(m.top.feedFile, m.preferences) +end function diff --git a/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.xml b/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.xml index 1bc3da92..65778c7b 100644 --- a/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.xml +++ b/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.xml @@ -2,6 +2,7 @@ + diff --git a/playlet-lib/src/components/Screens/HomeScreen/HomeScreenUtils.bs b/playlet-lib/src/components/Screens/HomeScreen/HomeScreenUtils.bs new file mode 100644 index 00000000..41edfc97 --- /dev/null +++ b/playlet-lib/src/components/Screens/HomeScreen/HomeScreenUtils.bs @@ -0,0 +1,28 @@ +import "pkg:/source/utils/Types.bs" + +namespace HomeScreenUtils + + function GetFeed(feedFileName as string, preferences as object) as object + feed = ParseJson(ReadAsciiFile(feedFileName)) + + homeLayout = preferences["misc.home_screen_layout"] + if not IsArray(homeLayout) or homeLayout.Count() = 0 + return feed + end if + + feedItems = {} + for each item in feed + feedItems[item["id"]] = item + end for + + filteredFeed = [] + for each item in homeLayout + if item.enabled = true + filteredFeed.push(feedItems[item.id]) + end if + end for + + return filteredFeed + end function + +end namespace diff --git a/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/EditHomeScreenControl.bs b/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/EditHomeScreenControl.bs new file mode 100644 index 00000000..fc20d00f --- /dev/null +++ b/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/EditHomeScreenControl.bs @@ -0,0 +1,58 @@ +import "pkg:/source/utils/Types.bs" +import "pkg:/source/utils/FocusManagement.bs" +import "pkg:/components/parts/AutoBind/OnNodeReadyNoOp.bs" + +function Init() + m.top.focusable = true + m.top.itemSpacings = [8] + + m.button = m.top.findNode("button") + m.button.observeField("buttonSelected", FuncName(OpenHomeScreenEditor)) +end function + +function OnFocusChange() as void + if not m.top.focus + return + end if + + NodeSetFocus(m.button, true) +end function + +function BindPreference(preferences as object, key as string) + if m.preferences <> invalid and m.key <> invalid + m.preferences.unobserveFieldScoped(m.key) + end if + + m.preferences = preferences + m.key = key + + if preferences <> invalid and key <> invalid + preferences.observeFieldScoped(key, FuncName(OnPreferenceChange)) + OnPreferenceChange() + end if +end function + +function OpenHomeScreenEditor() + editor = CreateObject("roSGNode", "HomeScreenEditor") + m.appController@.PushScreen(editor) + editor@.BindNode() + editor.value = m.top.value + editor.observeField("save", FuncName(OnSaveHomeScreenEditor)) +end function + +function OnSaveHomeScreenEditor(event as object) + editor = event.GetRoSGNode() + m.top.value = editor.value +end function + +function OnPreferenceChange() + m.top.value = m.preferences[m.key] +end function + +function OnValueChange() as void + if m.preferences = invalid or m.key = invalid + return + end if + + m.preferences[m.key] = m.top.value +end function diff --git a/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/EditHomeScreenControl.xml b/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/EditHomeScreenControl.xml new file mode 100644 index 00000000..9d4db494 --- /dev/null +++ b/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/EditHomeScreenControl.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + diff --git a/playlet-web/src/lib/Screens/Settings/SettingsNode.svelte b/playlet-web/src/lib/Screens/Settings/SettingsNode.svelte index b2f6012c..e2a1eb6c 100644 --- a/playlet-web/src/lib/Screens/Settings/SettingsNode.svelte +++ b/playlet-web/src/lib/Screens/Settings/SettingsNode.svelte @@ -1,6 +1,7 @@ diff --git a/playlet-web/src/lib/Stores.ts b/playlet-web/src/lib/Stores.ts index 035f51fa..cda0be34 100644 --- a/playlet-web/src/lib/Stores.ts +++ b/playlet-web/src/lib/Stores.ts @@ -15,6 +15,8 @@ export const userPreferencesStore = writable({} as any); export const invidiousVideoApiStore = writable({} as any); +export const homeLayoutStore = writable([] as any); + export const homeLayoutFileStore = writable([] as any); export const bookmarksStore = writable([] as any); diff --git a/playlet-web/src/lib/VideoFeed/VideoListRow.svelte b/playlet-web/src/lib/VideoFeed/VideoListRow.svelte index 389cbe7d..d6a02824 100644 --- a/playlet-web/src/lib/VideoFeed/VideoListRow.svelte +++ b/playlet-web/src/lib/VideoFeed/VideoListRow.svelte @@ -7,7 +7,7 @@ // TODO:P1 figure out why some uncached feeds (e.g. channels/ucid/videos) get hit twice export let feed: any = undefined; - export let videos = []; + let videos = []; enum FeedLoadState { None, @@ -28,6 +28,8 @@ let scrollStart = 0; let scrollEnd = 0; + let loadDataTask = undefined; + // w-80|w-60 p-2: 320px|240px + 16px padding on each side const videoItemWidth = 320 + 16 * 2; const channelItemWidth = 240 + 16 * 2; @@ -42,6 +44,18 @@ { threshold: [0] } ); + $: { + if (feed) { + feedSourcesIndex = 0; + feedLoadState = FeedLoadState.None; + videos = []; + itemWidths = []; + scrollStart = 0; + scrollEnd = 0; + loadDataTask = undefined; + } + } + $: { if ( carouselElement && @@ -112,8 +126,6 @@ loadDataTask = undefined; } - let loadDataTask; - async function loadData() { feedLoadState = FeedLoadState.Loading; let totalFetchedItems = 0; From 793b100d57a3ffa94a3793369c5a2716507ce44b Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Fri, 5 Jan 2024 19:28:45 -0500 Subject: [PATCH 02/11] remove logs --- .../Settings/SettingControls/EditHomeScreenControl.svelte | 2 -- 1 file changed, 2 deletions(-) diff --git a/playlet-web/src/lib/Screens/Settings/SettingControls/EditHomeScreenControl.svelte b/playlet-web/src/lib/Screens/Settings/SettingControls/EditHomeScreenControl.svelte index b84d3514..da568c7e 100644 --- a/playlet-web/src/lib/Screens/Settings/SettingControls/EditHomeScreenControl.svelte +++ b/playlet-web/src/lib/Screens/Settings/SettingControls/EditHomeScreenControl.svelte @@ -44,13 +44,11 @@ const refreshUserPrefrences = PlayletApi.getUserPreferences(); refreshUserPrefrences.then((value) => { userPreferencesStore.set(value); - console.log("refreshed user preferences"); }); const refreshHomeLayout = PlayletApi.getHomeLayout(); refreshHomeLayout.then((value) => { homeLayoutStore.set(value); - console.log("refreshed home layout"); }); await Promise.all([refreshUserPrefrences, refreshHomeLayout]); From eace91903b345af47271fc3945dd2a46eed2c7c5 Mon Sep 17 00:00:00 2001 From: github-action linter Date: Sat, 6 Jan 2024 00:29:48 +0000 Subject: [PATCH 03/11] Lint fix --- playlet-lib/src/components/Screens/HomeScreen/HomeScreen.bs | 2 +- .../SettingsScreen/HomeScreenEditor/EditHomeScreenControl.bs | 4 ++-- .../SettingsScreen/HomeScreenEditor/HomeScreenEditor.bs | 2 +- .../src/components/Web/PlayletWebServer/PlayletWebServer.bs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.bs b/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.bs index b7b80bb1..f3000e15 100644 --- a/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.bs +++ b/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.bs @@ -1,7 +1,7 @@ +import "HomeScreenUtils.bs" import "pkg:/components/ContextMenu/ContextMenuUtils.bs" import "pkg:/components/Navigation/Navigation.bs" import "pkg:/source/utils/FocusManagement.bs" -import "HomeScreenUtils.bs" function Init() m.top.focusable = true diff --git a/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/EditHomeScreenControl.bs b/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/EditHomeScreenControl.bs index fc20d00f..b4c98019 100644 --- a/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/EditHomeScreenControl.bs +++ b/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/EditHomeScreenControl.bs @@ -1,6 +1,6 @@ -import "pkg:/source/utils/Types.bs" -import "pkg:/source/utils/FocusManagement.bs" import "pkg:/components/parts/AutoBind/OnNodeReadyNoOp.bs" +import "pkg:/source/utils/FocusManagement.bs" +import "pkg:/source/utils/Types.bs" function Init() m.top.focusable = true diff --git a/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/HomeScreenEditor.bs b/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/HomeScreenEditor.bs index b8973027..bcc3885d 100644 --- a/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/HomeScreenEditor.bs +++ b/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/HomeScreenEditor.bs @@ -1,7 +1,7 @@ import "pkg:/components/Navigation/Navigation.bs" import "pkg:/components/parts/AutoBind/OnNodeReadyNoOp.bs" -import "pkg:/source/utils/Types.bs" import "pkg:/source/utils/MathUtils.bs" +import "pkg:/source/utils/Types.bs" function Init() m.homeLayout = {} diff --git a/playlet-lib/src/components/Web/PlayletWebServer/PlayletWebServer.bs b/playlet-lib/src/components/Web/PlayletWebServer/PlayletWebServer.bs index 9a6c013b..2b66b104 100644 --- a/playlet-lib/src/components/Web/PlayletWebServer/PlayletWebServer.bs +++ b/playlet-lib/src/components/Web/PlayletWebServer/PlayletWebServer.bs @@ -1,6 +1,7 @@ import "pkg:/components/parts/AutoBind/OnNodeReadyNoOp.bs" import "pkg:/components/Web/PlayletWebServer/Middleware/BookmarksRouter.bs" import "pkg:/components/Web/PlayletWebServer/Middleware/DashRouter.bs" +import "pkg:/components/Web/PlayletWebServer/Middleware/HomeLayoutRouter.bs" import "pkg:/components/Web/PlayletWebServer/Middleware/InvidiousRouter.bs" import "pkg:/components/Web/PlayletWebServer/Middleware/PlayletLibUrlsRouter.bs" import "pkg:/components/Web/PlayletWebServer/Middleware/PlayQueueRouter.bs" @@ -12,7 +13,6 @@ import "pkg:/components/Web/WebServer/Middleware/CorsMiddleware.bs" import "pkg:/components/Web/WebServer/Middleware/EtagMiddleware.bs" import "pkg:/components/Web/WebServer/Middleware/HttpStaticFilesRouter.bs" import "pkg:/components/Web/WebServer/WebSockets/WebSocketMiddleware.bs" -import "pkg:/components/Web/PlayletWebServer/Middleware/HomeLayoutRouter.bs" function Init() m.top.packageName = "Playlet" From 26bff7296ada9ec69a5841772f20c48fab8eb299 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Fri, 5 Jan 2024 19:32:42 -0500 Subject: [PATCH 04/11] move func --- .../src/components/Screens/HomeScreen/HomeScreen.bs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.bs b/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.bs index f3000e15..0e1198f0 100644 --- a/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.bs +++ b/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.bs @@ -20,6 +20,10 @@ function OnNodeReady() OnHomeLayoutChange() end function +function OnHomeLayoutChange() as void + m.rowList.feeds = HomeScreenUtils.GetFeed(m.top.feedFile, m.preferences) +end function + function OnFocusChange() as void if not m.top.focus return @@ -38,7 +42,3 @@ function GetContextMenuOptionsForItem(rowItem as object) as object refresh = ContextMenuUtils.CreateOption("Refresh Home", m.rowList, "Refresh", [invalid]) return [refresh] end function - -function OnHomeLayoutChange() as void - m.rowList.feeds = HomeScreenUtils.GetFeed(m.top.feedFile, m.preferences) -end function From 32e948733c7572f972c5f5230d76187888d4f32b Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Sat, 6 Jan 2024 09:52:49 -0500 Subject: [PATCH 05/11] Fix for checklist --- .../SettingsScreen/HomeScreenEditor/HomeScreenEditor.bs | 9 ++++++++- .../SettingsScreen/HomeScreenEditor/HomeScreenEditor.xml | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/HomeScreenEditor.bs b/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/HomeScreenEditor.bs index bcc3885d..39cb1152 100644 --- a/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/HomeScreenEditor.bs +++ b/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/HomeScreenEditor.bs @@ -109,7 +109,6 @@ function OnCheckedStateChange() as void m.top.value = value end function -' TODO:P0 check if moving items preserves the checked state function OnMoveUpButtonSelected() as void MoveItem(-1) end function @@ -132,13 +131,21 @@ function MoveItem(offset as integer) as void return end if + checkedState = m.checkList.checkedState node = content.getChild(index) content.insertChild(node, newIndex) + tmp = checkedState[index] + checkedState[index] = checkedState[newIndex] + checkedState[newIndex] = tmp + m.checkList.itemFocused = newIndex + m.checkList.jumpToItem = newIndex + m.checkList.checkedState = checkedState end function function OnSaveButtonSelected() + ' TODO:P0 save the new layout does not always work? m.top.save = true Close() end function diff --git a/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/HomeScreenEditor.xml b/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/HomeScreenEditor.xml index 742fb23f..f50e4961 100644 --- a/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/HomeScreenEditor.xml +++ b/playlet-lib/src/components/Screens/SettingsScreen/HomeScreenEditor/HomeScreenEditor.xml @@ -28,13 +28,13 @@ id="moveUpButton" text="Move up" showFocusFootprint="true" - minWidth="200" + minWidth="220" translation="[640,183]" />