@@ -31,6 +31,7 @@ window.qBittorrent.Client ??= (() => {
3131 return {
3232 setup : setup ,
3333 initializeCaches : initializeCaches ,
34+ initializeClientData : initializeClientData ,
3435 closeWindow : closeWindow ,
3536 closeFrameWindow : closeFrameWindow ,
3637 getSyncMainDataInterval : getSyncMainDataInterval ,
@@ -56,15 +57,47 @@ window.qBittorrent.Client ??= (() => {
5657 const tagMap = new Map ( ) ;
5758
5859 let cacheAllSettled ;
60+ let clientDataPromise ;
5961 const setup = ( ) => {
6062 // fetch various data and store it in memory
63+ clientDataPromise = window . qBittorrent . ClientData . fetch ( [
64+ "show_search_engine" ,
65+ "show_rss_reader" ,
66+ "show_log_viewer" ,
67+ "speed_in_browser_title_bar" ,
68+ "show_top_toolbar" ,
69+ "show_status_bar" ,
70+ "show_filters_sidebar" ,
71+ "hide_zero_status_filters" ,
72+ "color_scheme" ,
73+ "full_url_tracker_column" ,
74+ "use_alt_row_colors" ,
75+ "use_virtual_list" ,
76+ "dblclick_complete" ,
77+ "dblclick_download" ,
78+ "dblclick_filter" ,
79+ "search_in_filter" ,
80+ "qbt_selected_log_levels" ,
81+ "add_torrent_default_category" ,
82+ ] ) ;
83+
6184 cacheAllSettled = Promise . allSettled ( [
6285 window . qBittorrent . Cache . buildInfo . init ( ) ,
6386 window . qBittorrent . Cache . preferences . init ( ) ,
64- window . qBittorrent . Cache . qbtVersion . init ( )
87+ window . qBittorrent . Cache . qbtVersion . init ( ) ,
88+ clientDataPromise ,
6589 ] ) ;
6690 } ;
6791
92+ const initializeClientData = async ( ) => {
93+ try {
94+ await clientDataPromise ;
95+ }
96+ catch ( error ) {
97+ console . error ( `Failed to initialize client data. Reason: "${ error } ".` ) ;
98+ }
99+ } ;
100+
68101 const initializeCaches = async ( ) => {
69102 const results = await cacheAllSettled ;
70103 for ( const [ idx , result ] of results . entries ( ) ) {
@@ -223,8 +256,8 @@ let queueing_enabled = true;
223256let serverSyncMainDataInterval = 1500 ;
224257let customSyncMainDataInterval = null ;
225258let useSubcategories = true ;
226- const useAutoHideZeroStatusFilters = localPreferences . get ( "hide_zero_status_filters" , " false" ) === "true" ;
227- const displayFullURLTrackerColumn = localPreferences . get ( "full_url_tracker_column" , " false" ) === "true" ;
259+ let useAutoHideZeroStatusFilters = false ;
260+ let displayFullURLTrackerColumn = false ;
228261
229262/* Categories filter */
230263const CATEGORIES_ALL = "b4af0e4c-e76d-4bac-a392-46cbc18d9655" ;
@@ -250,6 +283,8 @@ const TRACKERS_WARNING = "82a702c5-210c-412b-829f-97632d7557e9";
250283// Map<trackerHost: String, Map<trackerURL: String, torrents: Set>>
251284const trackerMap = new Map ( ) ;
252285
286+ const clientData = window . qBittorrent . ClientData ;
287+
253288let selectedTracker = localPreferences . get ( "selected_tracker" , TRACKERS_ALL ) ;
254289let setTrackerFilter = ( ) => { } ;
255290
@@ -258,7 +293,13 @@ let selectedStatus = localPreferences.get("selected_filter", "all");
258293let setStatusFilter = ( ) => { } ;
259294let toggleFilterDisplay = ( ) => { } ;
260295
261- window . addEventListener ( "DOMContentLoaded" , ( event ) => {
296+ window . addEventListener ( "DOMContentLoaded" , async ( event ) => {
297+ await window . qBittorrent . Client . initializeClientData ( ) ;
298+ window . qBittorrent . ColorScheme . update ( ) ;
299+
300+ useAutoHideZeroStatusFilters = clientData . get ( "hide_zero_status_filters" ) === true ;
301+ displayFullURLTrackerColumn = clientData . get ( "full_url_tracker_column" ) === true ;
302+
262303 window . qBittorrent . LocalPreferences . upgrade ( ) ;
263304
264305 let isSearchPanelLoaded = false ;
@@ -405,6 +446,13 @@ window.addEventListener("DOMContentLoaded", (event) => {
405446 localPreferences . set ( `filter_${ filterListID . replace ( "FilterList" , "" ) } _collapsed` , filterList . classList . toggle ( "invisible" ) . toString ( ) ) ;
406447 } ;
407448
449+ const highlightSelectedStatus = ( ) => {
450+ const statusFilter = document . getElementById ( "statusFilterList" ) ;
451+ const filterID = `${ selectedStatus } _filter` ;
452+ for ( const status of statusFilter . children )
453+ status . classList . toggle ( "selectedFilter" , ( status . id === filterID ) ) ;
454+ } ;
455+
408456 new MochaUI . Panel ( {
409457 id : "Filters" ,
410458 title : "Panel" ,
@@ -426,35 +474,35 @@ window.addEventListener("DOMContentLoaded", (event) => {
426474 initializeWindows ( ) ;
427475
428476 // Show Top Toolbar is enabled by default
429- let showTopToolbar = localPreferences . get ( "show_top_toolbar" , "true" ) === "true" ;
477+ let showTopToolbar = clientData . get ( "show_top_toolbar" ) !== false ;
430478 if ( ! showTopToolbar ) {
431479 document . getElementById ( "showTopToolbarLink" ) . firstElementChild . style . opacity = "0" ;
432480 document . getElementById ( "mochaToolbar" ) . classList . add ( "invisible" ) ;
433481 }
434482
435483 // Show Status Bar is enabled by default
436- let showStatusBar = localPreferences . get ( "show_status_bar" , "true" ) === "true" ;
484+ let showStatusBar = clientData . get ( "show_status_bar" ) !== false ;
437485 if ( ! showStatusBar ) {
438486 document . getElementById ( "showStatusBarLink" ) . firstElementChild . style . opacity = "0" ;
439487 document . getElementById ( "desktopFooterWrapper" ) . classList . add ( "invisible" ) ;
440488 }
441489
442490 // Show Filters Sidebar is enabled by default
443- let showFiltersSidebar = localPreferences . get ( "show_filters_sidebar" , "true" ) === "true" ;
491+ let showFiltersSidebar = clientData . get ( "show_filters_sidebar" ) !== false ;
444492 if ( ! showFiltersSidebar ) {
445493 document . getElementById ( "showFiltersSidebarLink" ) . firstElementChild . style . opacity = "0" ;
446494 document . getElementById ( "filtersColumn" ) . classList . add ( "invisible" ) ;
447495 document . getElementById ( "filtersColumn_handle" ) . classList . add ( "invisible" ) ;
448496 }
449497
450- let speedInTitle = localPreferences . get ( "speed_in_browser_title_bar" ) === " true" ;
498+ let speedInTitle = clientData . get ( "speed_in_browser_title_bar" ) === true ;
451499 if ( ! speedInTitle )
452500 document . getElementById ( "speedInBrowserTitleBarLink" ) . firstElementChild . style . opacity = "0" ;
453501
454502 // After showing/hiding the toolbar + status bar
455- window . qBittorrent . Client . showSearchEngine ( localPreferences . get ( "show_search_engine" ) !== " false" ) ;
456- window . qBittorrent . Client . showRssReader ( localPreferences . get ( "show_rss_reader" ) !== " false" ) ;
457- window . qBittorrent . Client . showLogViewer ( localPreferences . get ( "show_log_viewer" ) === " true" ) ;
503+ window . qBittorrent . Client . showSearchEngine ( clientData . get ( "show_search_engine" ) !== false ) ;
504+ window . qBittorrent . Client . showRssReader ( clientData . get ( "show_rss_reader" ) !== false ) ;
505+ window . qBittorrent . Client . showLogViewer ( clientData . get ( "show_log_viewer" ) === true ) ;
458506
459507 // After Show Top Toolbar
460508 MochaUI . Desktop . setDesktopSize ( ) ;
@@ -571,13 +619,6 @@ window.addEventListener("DOMContentLoaded", (event) => {
571619 window . qBittorrent . Filters . clearStatusFilter ( ) ;
572620 } ;
573621
574- const highlightSelectedStatus = ( ) => {
575- const statusFilter = document . getElementById ( "statusFilterList" ) ;
576- const filterID = `${ selectedStatus } _filter` ;
577- for ( const status of statusFilter . children )
578- status . classList . toggle ( "selectedFilter" , ( status . id === filterID ) ) ;
579- } ;
580-
581622 const updateCategoryList = ( ) => {
582623 const categoryList = document . getElementById ( "categoryFilterList" ) ;
583624 if ( ! categoryList )
@@ -1223,7 +1264,7 @@ window.addEventListener("DOMContentLoaded", (event) => {
12231264
12241265 document . getElementById ( "showTopToolbarLink" ) . addEventListener ( "click" , ( e ) => {
12251266 showTopToolbar = ! showTopToolbar ;
1226- localPreferences . set ( " show_top_toolbar" , showTopToolbar . toString ( ) ) ;
1267+ clientData . set ( { show_top_toolbar : showTopToolbar } ) ;
12271268 if ( showTopToolbar ) {
12281269 document . getElementById ( "showTopToolbarLink" ) . firstElementChild . style . opacity = "1" ;
12291270 document . getElementById ( "mochaToolbar" ) . classList . remove ( "invisible" ) ;
@@ -1237,7 +1278,7 @@ window.addEventListener("DOMContentLoaded", (event) => {
12371278
12381279 document . getElementById ( "showStatusBarLink" ) . addEventListener ( "click" , ( e ) => {
12391280 showStatusBar = ! showStatusBar ;
1240- localPreferences . set ( " show_status_bar" , showStatusBar . toString ( ) ) ;
1281+ clientData . set ( { show_status_bar : showStatusBar } ) ;
12411282 if ( showStatusBar ) {
12421283 document . getElementById ( "showStatusBarLink" ) . firstElementChild . style . opacity = "1" ;
12431284 document . getElementById ( "desktopFooterWrapper" ) . classList . remove ( "invisible" ) ;
@@ -1274,7 +1315,7 @@ window.addEventListener("DOMContentLoaded", (event) => {
12741315
12751316 document . getElementById ( "showFiltersSidebarLink" ) . addEventListener ( "click" , ( e ) => {
12761317 showFiltersSidebar = ! showFiltersSidebar ;
1277- localPreferences . set ( " show_filters_sidebar" , showFiltersSidebar . toString ( ) ) ;
1318+ clientData . set ( { show_filters_sidebar : showFiltersSidebar } ) ;
12781319 if ( showFiltersSidebar ) {
12791320 document . getElementById ( "showFiltersSidebarLink" ) . firstElementChild . style . opacity = "1" ;
12801321 document . getElementById ( "filtersColumn" ) . classList . remove ( "invisible" ) ;
@@ -1290,7 +1331,7 @@ window.addEventListener("DOMContentLoaded", (event) => {
12901331
12911332 document . getElementById ( "speedInBrowserTitleBarLink" ) . addEventListener ( "click" , ( e ) => {
12921333 speedInTitle = ! speedInTitle ;
1293- localPreferences . set ( " speed_in_browser_title_bar" , speedInTitle . toString ( ) ) ;
1334+ clientData . set ( { speed_in_browser_title_bar : speedInTitle } ) ;
12941335 if ( speedInTitle )
12951336 document . getElementById ( "speedInBrowserTitleBarLink" ) . firstElementChild . style . opacity = "1" ;
12961337 else
@@ -1300,19 +1341,19 @@ window.addEventListener("DOMContentLoaded", (event) => {
13001341
13011342 document . getElementById ( "showSearchEngineLink" ) . addEventListener ( "click" , ( e ) => {
13021343 window . qBittorrent . Client . showSearchEngine ( ! window . qBittorrent . Client . isShowSearchEngine ( ) ) ;
1303- localPreferences . set ( " show_search_engine" , window . qBittorrent . Client . isShowSearchEngine ( ) . toString ( ) ) ;
1344+ clientData . set ( { show_search_engine : window . qBittorrent . Client . isShowSearchEngine ( ) } ) ;
13041345 updateTabDisplay ( ) ;
13051346 } ) ;
13061347
13071348 document . getElementById ( "showRssReaderLink" ) . addEventListener ( "click" , ( e ) => {
13081349 window . qBittorrent . Client . showRssReader ( ! window . qBittorrent . Client . isShowRssReader ( ) ) ;
1309- localPreferences . set ( " show_rss_reader" , window . qBittorrent . Client . isShowRssReader ( ) . toString ( ) ) ;
1350+ clientData . set ( { show_rss_reader : window . qBittorrent . Client . isShowRssReader ( ) } ) ;
13101351 updateTabDisplay ( ) ;
13111352 } ) ;
13121353
13131354 document . getElementById ( "showLogViewerLink" ) . addEventListener ( "click" , ( e ) => {
13141355 window . qBittorrent . Client . showLogViewer ( ! window . qBittorrent . Client . isShowLogViewer ( ) ) ;
1315- localPreferences . set ( " show_log_viewer" , window . qBittorrent . Client . isShowLogViewer ( ) . toString ( ) ) ;
1356+ clientData . set ( { show_log_viewer : window . qBittorrent . Client . isShowLogViewer ( ) } ) ;
13161357 updateTabDisplay ( ) ;
13171358 } ) ;
13181359
@@ -1369,7 +1410,7 @@ window.addEventListener("DOMContentLoaded", (event) => {
13691410 // main window tabs
13701411
13711412 const showTransfersTab = ( ) => {
1372- const showFiltersSidebar = localPreferences . get ( "show_filters_sidebar" , "true" ) === "true" ;
1413+ const showFiltersSidebar = clientData . get ( "show_filters_sidebar" ) !== false ;
13731414 if ( showFiltersSidebar ) {
13741415 document . getElementById ( "filtersColumn" ) . classList . remove ( "invisible" ) ;
13751416 document . getElementById ( "filtersColumn_handle" ) . classList . remove ( "invisible" ) ;
0 commit comments