@@ -14,6 +14,13 @@ import {
1414 getValidHashTab ,
1515 replaceTabRoute ,
1616} from "@/utils/hashRouteTabs.mjs" ;
17+ import {
18+ PIN_UPDATES_ON_TOP_STORAGE_KEY ,
19+ PLUGIN_LIST_VIEW_MODE_STORAGE_KEY ,
20+ SHOW_RESERVED_PLUGINS_STORAGE_KEY ,
21+ readBooleanPreference ,
22+ writeBooleanPreference ,
23+ } from "./extensionPreferenceStorage.mjs" ;
1724import { ref , computed , onMounted , onUnmounted , reactive , watch } from "vue" ;
1825import { useRoute , useRouter } from "vue-router" ;
1926import { useDisplay } from "vuetify" ;
@@ -124,11 +131,7 @@ export const useExtensionPage = () => {
124131
125132 // 从 localStorage 恢复显示系统插件的状态,默认为 false(隐藏)
126133 const getInitialShowReserved = ( ) => {
127- if ( typeof window !== "undefined" && window . localStorage ) {
128- const saved = localStorage . getItem ( "showReservedPlugins" ) ;
129- return saved === "true" ;
130- }
131- return false ;
134+ return readBooleanPreference ( SHOW_RESERVED_PLUGINS_STORAGE_KEY , false ) ;
132135 } ;
133136 const showReserved = ref ( getInitialShowReserved ( ) ) ;
134137 const snack_message = ref ( "" ) ;
@@ -178,28 +181,19 @@ export const useExtensionPage = () => {
178181 // 新增变量支持列表视图
179182 // 从 localStorage 恢复显示模式,默认为 false(卡片视图)
180183 const getInitialListViewMode = ( ) => {
181- if ( typeof window !== "undefined" && window . localStorage ) {
182- return localStorage . getItem ( "pluginListViewMode" ) === "true" ;
183- }
184- return false ;
184+ return readBooleanPreference ( PLUGIN_LIST_VIEW_MODE_STORAGE_KEY , false ) ;
185185 } ;
186186 const isListView = ref ( getInitialListViewMode ( ) ) ;
187187 const pluginSearch = ref ( "" ) ;
188188 const installedStatusFilter = ref ( "all" ) ;
189189 const installedSortBy = ref ( "default" ) ;
190190 const installedSortOrder = ref ( "desc" ) ;
191191 const getInitialPinUpdatesOnTop = ( ) => {
192- if ( typeof window !== "undefined" && window . localStorage ) {
193- const saved = localStorage . getItem ( "pinUpdatesOnTop" ) ;
194- return saved !== "false" ;
195- }
196- return true ;
192+ return readBooleanPreference ( PIN_UPDATES_ON_TOP_STORAGE_KEY , true ) ;
197193 } ;
198194 const pinUpdatesOnTop = ref ( getInitialPinUpdatesOnTop ( ) ) ;
199195 watch ( pinUpdatesOnTop , ( val ) => {
200- if ( typeof window !== "undefined" && window . localStorage ) {
201- localStorage . setItem ( "pinUpdatesOnTop" , val . toString ( ) ) ;
202- }
196+ writeBooleanPreference ( PIN_UPDATES_ON_TOP_STORAGE_KEY , val ) ;
203197 } ) ;
204198 const loading_ = ref ( false ) ;
205199
@@ -660,9 +654,7 @@ export const useExtensionPage = () => {
660654 const toggleShowReserved = ( ) => {
661655 showReserved . value = ! showReserved . value ;
662656 // 保存到 localStorage
663- if ( typeof window !== "undefined" && window . localStorage ) {
664- localStorage . setItem ( "showReservedPlugins" , showReserved . value . toString ( ) ) ;
665- }
657+ writeBooleanPreference ( SHOW_RESERVED_PLUGINS_STORAGE_KEY , showReserved . value ) ;
666658 } ;
667659
668660 const toast = ( message , success ) => {
@@ -1627,9 +1619,7 @@ export const useExtensionPage = () => {
16271619
16281620 // 监听显示模式变化并保存到 localStorage
16291621 watch ( isListView , ( newVal ) => {
1630- if ( typeof window !== "undefined" && window . localStorage ) {
1631- localStorage . setItem ( "pluginListViewMode" , String ( newVal ) ) ;
1632- }
1622+ writeBooleanPreference ( PLUGIN_LIST_VIEW_MODE_STORAGE_KEY , newVal ) ;
16331623 } ) ;
16341624
16351625 watch (
0 commit comments