diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4b00fd19..e8608c93 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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/),
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
### Added
diff --git a/playlet-lib/src/components/MainScene.transpiled.xml b/playlet-lib/src/components/MainScene.transpiled.xml
index 49c6246a..046ba7d5 100644
--- a/playlet-lib/src/components/MainScene.transpiled.xml
+++ b/playlet-lib/src/components/MainScene.transpiled.xml
@@ -41,6 +41,7 @@
+
diff --git a/playlet-lib/src/components/MainScene.xml b/playlet-lib/src/components/MainScene.xml
index e5d4dde4..e136dc96 100644
--- a/playlet-lib/src/components/MainScene.xml
+++ b/playlet-lib/src/components/MainScene.xml
@@ -53,6 +53,8 @@
+
+
diff --git a/playlet-lib/src/components/Screens/SearchScreen/SearchSuggestionsTask.bs b/playlet-lib/src/components/Screens/SearchScreen/SearchSuggestionsTask.bs
index 0d18aac0..1a9134e1 100644
--- a/playlet-lib/src/components/Screens/SearchScreen/SearchSuggestionsTask.bs
+++ b/playlet-lib/src/components/Screens/SearchScreen/SearchSuggestionsTask.bs
@@ -1,10 +1,11 @@
import "pkg:/components/Services/Invidious/InvidiousService.bs"
-import "pkg:/source/services/SearchHistory.bs"
+import "pkg:/components/Services/SearchHistory/SearchHistoryUtils.bs"
@asynctask
function SearchSuggestionsTask(input as object) as object
q = input.q
invidiousNode = input.invidious
+ preferencesNode = input.preferences
service = new Invidious.InvidiousService(invidiousNode)
@@ -18,7 +19,7 @@ function SearchSuggestionsTask(input as object) as object
return invalid
end if
- history = SearchHistory.GetSaved(q)
+ history = SearchHistoryUtils.GetSaved(preferencesNode, q)
if searchSuggestsions <> invalid
history = MergeSearchSuggestions(history, searchSuggestsions.suggestions)
diff --git a/playlet-lib/src/components/Screens/SettingsScreen/ClearSearchHistoryControl.bs b/playlet-lib/src/components/Screens/SettingsScreen/ClearSearchHistoryControl.bs
index 7454e2fc..e14a07dc 100644
--- a/playlet-lib/src/components/Screens/SettingsScreen/ClearSearchHistoryControl.bs
+++ b/playlet-lib/src/components/Screens/SettingsScreen/ClearSearchHistoryControl.bs
@@ -1,5 +1,5 @@
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"
function Init()
@@ -21,6 +21,6 @@ function BindPreference(preferences as object, key as string)
end function
function OnButtonSelected()
- SearchHistory.Clear()
+ SearchHistoryUtils.Clear()
DialogUtils.ShowDialog("Search history cleared.", "Success")
end function
diff --git a/playlet-lib/src/components/Services/SearchHistory/SearchHistory.bs b/playlet-lib/src/components/Services/SearchHistory/SearchHistory.bs
new file mode 100644
index 00000000..3c1f2d56
--- /dev/null
+++ b/playlet-lib/src/components/Services/SearchHistory/SearchHistory.bs
@@ -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
diff --git a/playlet-lib/src/components/Services/SearchHistory/SearchHistory.xml b/playlet-lib/src/components/Services/SearchHistory/SearchHistory.xml
new file mode 100644
index 00000000..8716bd91
--- /dev/null
+++ b/playlet-lib/src/components/Services/SearchHistory/SearchHistory.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/playlet-lib/src/source/services/SearchHistory.bs b/playlet-lib/src/components/Services/SearchHistory/SearchHistoryUtils.bs
similarity index 64%
rename from playlet-lib/src/source/services/SearchHistory.bs
rename to playlet-lib/src/components/Services/SearchHistory/SearchHistoryUtils.bs
index d210c720..78d592c7 100644
--- a/playlet-lib/src/source/services/SearchHistory.bs
+++ b/playlet-lib/src/components/Services/SearchHistory/SearchHistoryUtils.bs
@@ -2,9 +2,14 @@ import "pkg:/source/utils/ArrayUtils.bs"
import "pkg:/source/utils/RegistryUtils.bs"
import "pkg:/source/utils/StringUtils.bs"
-namespace SearchHistory
- function Save(q as string, maxItems = 10 as integer)
- history = GetAllSaved()
+namespace SearchHistoryUtils
+ function Save(preferencesNode as object, q as string, maxItems = 10 as integer) as void
+ seachHistoryEnabled = preferencesNode["search_history.enabled"]
+ if not seachHistoryEnabled
+ return
+ end if
+
+ history = GetAllSaved(preferencesNode)
index = ArrayUtils.IndexOfString(history, q)
if index <> -1
history.Delete(index)
@@ -21,8 +26,8 @@ namespace SearchHistory
RegistryUtils.Write(RegistryUtils.SEARCH_HISTORY, history)
end function
- function GetSaved(q as string) as object
- history = GetAllSaved()
+ function GetSaved(preferencesNode as object, q as string) as object
+ history = GetAllSaved(preferencesNode)
if history.count() = 0
return []
end if
@@ -39,7 +44,12 @@ namespace SearchHistory
return result
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)
if history = invalid
return []
@@ -47,7 +57,6 @@ namespace SearchHistory
return ParseJson(history)
end function
-
function Clear()
RegistryUtils.Delete(RegistryUtils.SEARCH_HISTORY)
end function
diff --git a/playlet-lib/src/components/Web/PlayletWebServer/Middleware/SearchHistoryRouter.bs b/playlet-lib/src/components/Web/PlayletWebServer/Middleware/SearchHistoryRouter.bs
index 9be6667a..d52fbc8a 100644
--- a/playlet-lib/src/components/Web/PlayletWebServer/Middleware/SearchHistoryRouter.bs
+++ b/playlet-lib/src/components/Web/PlayletWebServer/Middleware/SearchHistoryRouter.bs
@@ -1,4 +1,4 @@
-import "pkg:/source/services/SearchHistory.bs"
+import "pkg:/components/Services/SearchHistory/SearchHistoryUtils.bs"
namespace Http
@@ -9,13 +9,18 @@ namespace Http
m.Get("/api/search-history", function(context as object) as boolean
response = context.response
- response.Json(SearchHistory.GetAllSaved())
+ task = context.server.task
+ preferences = task.preferences
+
+ response.Json(SearchHistoryUtils.GetAllSaved(preferences))
return true
end function)
m.Put("/api/search-history", function(context as object) as boolean
request = context.request
response = context.response
+ task = context.server.task
+ preferences = task.preferences
payload = request.Json()
if payload = invalid
@@ -29,15 +34,15 @@ namespace Http
return true
end if
- SearchHistory.Save(query)
- response.Json(SearchHistory.GetAllSaved())
+ SearchHistoryUtils.Save(preferences, query)
+ response.Json(SearchHistoryUtils.GetAllSaved(preferences))
return true
end function)
m.Delete("/api/search-history", function(context as object) as boolean
response = context.response
- SearchHistory.Clear()
+ SearchHistoryUtils.Clear()
response.Default(204, "OK")
return true
end function)
diff --git a/playlet-lib/src/config/preferences.json5 b/playlet-lib/src/config/preferences.json5
index 9e06880e..3b2060ed 100644
--- a/playlet-lib/src/config/preferences.json5
+++ b/playlet-lib/src/config/preferences.json5
@@ -98,6 +98,13 @@
key: "search_history",
description: "Search history preferences",
children: [
+ {
+ displayText: "Enable search history",
+ key: "search_history.enabled",
+ description: "Enable search history",
+ type: "boolean",
+ defaultValue: true,
+ },
{
displayText: "Clear Search History",
key: "search_history.clear_search_history",