Add search history preference (#193)
This commit is contained in:
1 parent
91be37fd8a
commit
4c32243e6e
13 files changed
+78
-19
No files matched your search
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- An option to disable search history
|
||||||
|
|
||||||
## [0.15.0] - 2023-11-05
|
## [0.15.0] - 2023-11-05
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
<ApplicationInfo id="ApplicationInfo" />
|
<ApplicationInfo id="ApplicationInfo" />
|
||||||
<Preferences id="Preferences" />
|
<Preferences id="Preferences" />
|
||||||
<Bookmarks id="Bookmarks" />
|
<Bookmarks id="Bookmarks" />
|
||||||
|
<SearchHistory id="SearchHistory" />
|
||||||
<Invidious id="Invidious" />
|
<Invidious id="Invidious" />
|
||||||
<PlayletWebServer id="WebServer" port="8888" />
|
<PlayletWebServer id="WebServer" port="8888" />
|
||||||
</AppController>
|
</AppController>
|
||||||
|
|||||||
@@ -53,6 +53,8 @@
|
|||||||
<ApplicationInfo id="ApplicationInfo" />
|
<ApplicationInfo id="ApplicationInfo" />
|
||||||
<Preferences id="Preferences" />
|
<Preferences id="Preferences" />
|
||||||
<Bookmarks id="Bookmarks" />
|
<Bookmarks id="Bookmarks" />
|
||||||
|
<SearchHistory id="SearchHistory"
|
||||||
|
preferences="bind:../Preferences" />
|
||||||
|
|
||||||
<Invidious id="Invidious"
|
<Invidious id="Invidious"
|
||||||
webServer="bind:../WebServer"
|
webServer="bind:../WebServer"
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ function InitializeBindings()
|
|||||||
"notifications": "../Notifications",
|
"notifications": "../Notifications",
|
||||||
"preferences": "../Preferences"
|
"preferences": "../Preferences"
|
||||||
},
|
},
|
||||||
|
"SearchHistory": {
|
||||||
|
"preferences": "../Preferences"
|
||||||
|
},
|
||||||
"Invidious": {
|
"Invidious": {
|
||||||
"webServer": "../WebServer",
|
"webServer": "../WebServer",
|
||||||
"applicationInfo": "../ApplicationInfo",
|
"applicationInfo": "../ApplicationInfo",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import "pkg:/components/Navigation/Navigation.bs"
|
import "pkg:/components/Navigation/Navigation.bs"
|
||||||
import "pkg:/components/Screens/SearchScreen/SearchSuggestionsTask.bs"
|
import "pkg:/components/Screens/SearchScreen/SearchSuggestionsTask.bs"
|
||||||
|
import "pkg:/components/Services/SearchHistory/SearchHistoryUtils.bs"
|
||||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||||
import "pkg:/source/services/SearchHistory.bs"
|
|
||||||
import "pkg:/source/utils/ErrorUtils.bs"
|
import "pkg:/source/utils/ErrorUtils.bs"
|
||||||
import "pkg:/source/utils/FocusManagement.bs"
|
import "pkg:/source/utils/FocusManagement.bs"
|
||||||
import "pkg:/source/utils/LoadingScreen.bs"
|
import "pkg:/source/utils/LoadingScreen.bs"
|
||||||
@@ -99,7 +99,8 @@ function OnTextChange() as void
|
|||||||
|
|
||||||
m.searchSuggestionsTask = StartAsyncTask(SearchSuggestionsTask, {
|
m.searchSuggestionsTask = StartAsyncTask(SearchSuggestionsTask, {
|
||||||
q: m.keyboard.text,
|
q: m.keyboard.text,
|
||||||
invidious: m.invidious
|
invidious: m.invidious,
|
||||||
|
preferences: m.preferences
|
||||||
}, OnSearchSuggestionsTaskResults)
|
}, OnSearchSuggestionsTaskResults)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
@@ -155,7 +156,7 @@ end function
|
|||||||
function OnSearchButtonSelected()
|
function OnSearchButtonSelected()
|
||||||
selected = m.suggestions.buttonSelected
|
selected = m.suggestions.buttonSelected
|
||||||
text = m.suggestions.buttons[selected]
|
text = m.suggestions.buttons[selected]
|
||||||
SearchHistory.Save(text)
|
SearchHistoryUtils.Save(m.preferences, text)
|
||||||
Search(text)
|
Search(text)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
<field id="navBar" type="node" bind="/NavBar" />
|
<field id="navBar" type="node" bind="/NavBar" />
|
||||||
<field id="invidious" type="node" bind="/Invidious" />
|
<field id="invidious" type="node" bind="/Invidious" />
|
||||||
<field id="appController" type="node" bind="/AppController" />
|
<field id="appController" type="node" bind="/AppController" />
|
||||||
|
<field id="preferences" type="node" bind="/Preferences" />
|
||||||
<field id="filters" type="assocarray" />
|
<field id="filters" type="assocarray" />
|
||||||
</interface>
|
</interface>
|
||||||
<children>
|
<children>
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||||
import "pkg:/source/services/SearchHistory.bs"
|
import "pkg:/components/Services/SearchHistory/SearchHistoryUtils.bs"
|
||||||
|
|
||||||
@asynctask
|
@asynctask
|
||||||
function SearchSuggestionsTask(input as object) as object
|
function SearchSuggestionsTask(input as object) as object
|
||||||
q = input.q
|
q = input.q
|
||||||
invidiousNode = input.invidious
|
invidiousNode = input.invidious
|
||||||
|
preferencesNode = input.preferences
|
||||||
|
|
||||||
service = new Invidious.InvidiousService(invidiousNode)
|
service = new Invidious.InvidiousService(invidiousNode)
|
||||||
|
|
||||||
@@ -18,7 +19,7 @@ function SearchSuggestionsTask(input as object) as object
|
|||||||
return invalid
|
return invalid
|
||||||
end if
|
end if
|
||||||
|
|
||||||
history = SearchHistory.GetSaved(q)
|
history = SearchHistoryUtils.GetSaved(preferencesNode, q)
|
||||||
|
|
||||||
if searchSuggestsions <> invalid
|
if searchSuggestsions <> invalid
|
||||||
history = MergeSearchSuggestions(history, searchSuggestsions.suggestions)
|
history = MergeSearchSuggestions(history, searchSuggestsions.suggestions)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||||
import "pkg:/source/services/SearchHistory.bs"
|
import "pkg:/components/Services/SearchHistory/SearchHistoryUtils.bs"
|
||||||
import "pkg:/source/utils/FocusManagement.bs"
|
import "pkg:/source/utils/FocusManagement.bs"
|
||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
@@ -21,6 +21,6 @@ function BindPreference(preferences as object, key as string)
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function OnButtonSelected()
|
function OnButtonSelected()
|
||||||
SearchHistory.Clear()
|
SearchHistoryUtils.Clear()
|
||||||
DialogUtils.ShowDialog("Search history cleared.", "Success")
|
DialogUtils.ShowDialog("Search history cleared.", "Success")
|
||||||
end function
|
end function
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import "pkg:/components/Services/SearchHistory/SearchHistoryUtils.bs"
|
||||||
|
import "pkg:/source/utils/Types.bs"
|
||||||
|
|
||||||
|
function Init()
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnNodeReady()
|
||||||
|
OnSearchHistoryPreference()
|
||||||
|
m.preferences.observeFieldScoped("search_history.enabled", FuncName(OnSearchHistoryPreference))
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnSearchHistoryPreference() as void
|
||||||
|
seachHistoryEnabled = m.preferences["search_history.enabled"]
|
||||||
|
if seachHistoryEnabled
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
SearchHistoryUtils.Clear()
|
||||||
|
end function
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<component name="SearchHistory" extends="Node" includes="AutoBind">
|
||||||
|
<interface>
|
||||||
|
<field id="preferences" type="node" />
|
||||||
|
</interface>
|
||||||
|
</component>
|
||||||
+16
-7
@@ -2,9 +2,14 @@ import "pkg:/source/utils/ArrayUtils.bs"
|
|||||||
import "pkg:/source/utils/RegistryUtils.bs"
|
import "pkg:/source/utils/RegistryUtils.bs"
|
||||||
import "pkg:/source/utils/StringUtils.bs"
|
import "pkg:/source/utils/StringUtils.bs"
|
||||||
|
|
||||||
namespace SearchHistory
|
namespace SearchHistoryUtils
|
||||||
function Save(q as string, maxItems = 10 as integer)
|
function Save(preferencesNode as object, q as string, maxItems = 10 as integer) as void
|
||||||
history = GetAllSaved()
|
seachHistoryEnabled = preferencesNode["search_history.enabled"]
|
||||||
|
if not seachHistoryEnabled
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
history = GetAllSaved(preferencesNode)
|
||||||
index = ArrayUtils.IndexOfString(history, q)
|
index = ArrayUtils.IndexOfString(history, q)
|
||||||
if index <> -1
|
if index <> -1
|
||||||
history.Delete(index)
|
history.Delete(index)
|
||||||
@@ -21,8 +26,8 @@ namespace SearchHistory
|
|||||||
RegistryUtils.Write(RegistryUtils.SEARCH_HISTORY, history)
|
RegistryUtils.Write(RegistryUtils.SEARCH_HISTORY, history)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function GetSaved(q as string) as object
|
function GetSaved(preferencesNode as object, q as string) as object
|
||||||
history = GetAllSaved()
|
history = GetAllSaved(preferencesNode)
|
||||||
if history.count() = 0
|
if history.count() = 0
|
||||||
return []
|
return []
|
||||||
end if
|
end if
|
||||||
@@ -39,7 +44,12 @@ namespace SearchHistory
|
|||||||
return result
|
return result
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function GetAllSaved() as object
|
function GetAllSaved(preferencesNode as object) as object
|
||||||
|
seachHistoryEnabled = preferencesNode["search_history.enabled"]
|
||||||
|
if not seachHistoryEnabled
|
||||||
|
return []
|
||||||
|
end if
|
||||||
|
|
||||||
history = RegistryUtils.Read(RegistryUtils.SEARCH_HISTORY)
|
history = RegistryUtils.Read(RegistryUtils.SEARCH_HISTORY)
|
||||||
if history = invalid
|
if history = invalid
|
||||||
return []
|
return []
|
||||||
@@ -47,7 +57,6 @@ namespace SearchHistory
|
|||||||
return ParseJson(history)
|
return ParseJson(history)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
|
||||||
function Clear()
|
function Clear()
|
||||||
RegistryUtils.Delete(RegistryUtils.SEARCH_HISTORY)
|
RegistryUtils.Delete(RegistryUtils.SEARCH_HISTORY)
|
||||||
end function
|
end function
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import "pkg:/source/services/SearchHistory.bs"
|
import "pkg:/components/Services/SearchHistory/SearchHistoryUtils.bs"
|
||||||
|
|
||||||
namespace Http
|
namespace Http
|
||||||
|
|
||||||
@@ -9,13 +9,18 @@ namespace Http
|
|||||||
|
|
||||||
m.Get("/api/search-history", function(context as object) as boolean
|
m.Get("/api/search-history", function(context as object) as boolean
|
||||||
response = context.response
|
response = context.response
|
||||||
response.Json(SearchHistory.GetAllSaved())
|
task = context.server.task
|
||||||
|
preferences = task.preferences
|
||||||
|
|
||||||
|
response.Json(SearchHistoryUtils.GetAllSaved(preferences))
|
||||||
return true
|
return true
|
||||||
end function)
|
end function)
|
||||||
|
|
||||||
m.Put("/api/search-history", function(context as object) as boolean
|
m.Put("/api/search-history", function(context as object) as boolean
|
||||||
request = context.request
|
request = context.request
|
||||||
response = context.response
|
response = context.response
|
||||||
|
task = context.server.task
|
||||||
|
preferences = task.preferences
|
||||||
|
|
||||||
payload = request.Json()
|
payload = request.Json()
|
||||||
if payload = invalid
|
if payload = invalid
|
||||||
@@ -29,15 +34,15 @@ namespace Http
|
|||||||
return true
|
return true
|
||||||
end if
|
end if
|
||||||
|
|
||||||
SearchHistory.Save(query)
|
SearchHistoryUtils.Save(preferences, query)
|
||||||
response.Json(SearchHistory.GetAllSaved())
|
response.Json(SearchHistoryUtils.GetAllSaved(preferences))
|
||||||
return true
|
return true
|
||||||
end function)
|
end function)
|
||||||
|
|
||||||
m.Delete("/api/search-history", function(context as object) as boolean
|
m.Delete("/api/search-history", function(context as object) as boolean
|
||||||
response = context.response
|
response = context.response
|
||||||
|
|
||||||
SearchHistory.Clear()
|
SearchHistoryUtils.Clear()
|
||||||
response.Default(204, "OK")
|
response.Default(204, "OK")
|
||||||
return true
|
return true
|
||||||
end function)
|
end function)
|
||||||
|
|||||||
@@ -98,6 +98,13 @@
|
|||||||
key: "search_history",
|
key: "search_history",
|
||||||
description: "Search history preferences",
|
description: "Search history preferences",
|
||||||
children: [
|
children: [
|
||||||
|
{
|
||||||
|
displayText: "Enable search history",
|
||||||
|
key: "search_history.enabled",
|
||||||
|
description: "Enable search history",
|
||||||
|
type: "boolean",
|
||||||
|
defaultValue: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayText: "Clear Search History",
|
displayText: "Clear Search History",
|
||||||
key: "search_history.clear_search_history",
|
key: "search_history.clear_search_history",
|
||||||
|
|||||||
Reference in new issue
Block a user