@@ -527,7 +527,7 @@ window.MaxExtensionFloatingPanel = {
527527
528528 // Clear existing content in the panel
529529 panelContent . innerHTML = '' ;
530-
530+
531531 // Get all the button configurations from global config
532532 const buttonConfigs = globalMaxExtensionConfig . customButtons ;
533533 let configIndex = 0 ; // Track which config we're on
@@ -619,41 +619,96 @@ window.MaxExtensionFloatingPanel = {
619619 } ,
620620
621621 /**
622- * Loads panel settings from localStorage .
622+ * Loads panel settings from Chrome's storage through the config service worker .
623623 * If no settings are found, default settings are used.
624624 */
625625 loadPanelSettings : function ( ) {
626626 try {
627+ // Initialize with default settings immediately to avoid null references
628+ this . currentPanelSettings = { ...this . defaultPanelSettings } ;
629+
627630 const hostname = window . location . hostname ;
628- const storageKey = this . storageKeyPrefix + hostname ;
629- const savedSettings = localStorage . getItem ( storageKey ) ;
630631
631- if ( savedSettings ) {
632- this . currentPanelSettings = JSON . parse ( savedSettings ) ;
633- logConCgp ( '[floating-panel] Loaded panel settings for ' + hostname ) ;
634- } else {
635- this . currentPanelSettings = { ...this . defaultPanelSettings } ;
636- logConCgp ( '[floating-panel] Using default panel settings for ' + hostname ) ;
637- }
632+ // Use chrome.runtime.sendMessage to get settings from config service worker
633+ chrome . runtime . sendMessage ( {
634+ type : 'getFloatingPanelSettings' ,
635+ hostname : hostname
636+ } , ( response ) => {
637+ if ( response && response . settings ) {
638+ this . currentPanelSettings = response . settings ;
639+ logConCgp ( '[floating-panel] Loaded panel settings for ' + hostname ) ;
640+ } else {
641+ // Keep the default settings we already set
642+ logConCgp ( '[floating-panel] Using default panel settings for ' + hostname ) ;
643+ }
644+
645+ // Apply settings to panel if it exists
646+ if ( this . panelElement ) {
647+ this . updatePanelFromSettings ( ) ;
648+ }
649+
650+ // Restore panel visibility state after settings are loaded
651+ this . restorePanelState ( ) ;
652+ } ) ;
638653 } catch ( error ) {
639654 logConCgp ( '[floating-panel] Error loading panel settings: ' + error . message ) ;
640655 this . currentPanelSettings = { ...this . defaultPanelSettings } ;
641656 }
642657 } ,
643658
644659 /**
645- * Saves panel settings to localStorage .
660+ * Saves panel settings to Chrome's storage through the config service worker .
646661 */
647662 savePanelSettings : function ( ) {
648663 try {
649664 const hostname = window . location . hostname ;
650- const storageKey = this . storageKeyPrefix + hostname ;
651- localStorage . setItem ( storageKey , JSON . stringify ( this . currentPanelSettings ) ) ;
652- logConCgp ( '[floating-panel] Saved panel settings for ' + hostname ) ;
665+
666+ // Use chrome.runtime.sendMessage to save settings via config service worker
667+ chrome . runtime . sendMessage ( {
668+ type : 'saveFloatingPanelSettings' ,
669+ hostname : hostname ,
670+ settings : this . currentPanelSettings
671+ } , ( response ) => {
672+ if ( response && response . success ) {
673+ logConCgp ( '[floating-panel] Saved panel settings for ' + hostname ) ;
674+ } else {
675+ logConCgp ( '[floating-panel] Failed to save panel settings for ' + hostname ) ;
676+ }
677+ } ) ;
653678 } catch ( error ) {
654679 logConCgp ( '[floating-panel] Error saving panel settings: ' + error . message ) ;
655680 }
656681 } ,
682+
683+ /**
684+ * Updates the panel's appearance and position based on current settings.
685+ * Called after settings are loaded or changed.
686+ */
687+ updatePanelFromSettings : function ( ) {
688+ if ( ! this . panelElement ) return ;
689+
690+ this . panelElement . style . width = `${ this . currentPanelSettings . width } px` ;
691+ this . panelElement . style . height = `${ this . currentPanelSettings . height } px` ;
692+ this . panelElement . style . left = `${ this . currentPanelSettings . posX } px` ;
693+ this . panelElement . style . top = `${ this . currentPanelSettings . posY } px` ;
694+
695+ // Update opacity
696+ const bgOpacity = this . currentPanelSettings . opacity ;
697+ this . panelElement . style . backgroundColor = `rgba(50, 50, 50, ${ bgOpacity } )` ;
698+
699+ // Update header and footer opacity
700+ const headerFooterOpacity = bgOpacity + 0.1 ;
701+ const header = document . getElementById ( 'max-extension-floating-panel-header' ) ;
702+ const footer = document . getElementById ( 'max-extension-profile-switcher' ) ;
703+
704+ if ( header ) {
705+ header . style . backgroundColor = `rgba(40, 40, 40, ${ headerFooterOpacity } )` ;
706+ }
707+
708+ if ( footer ) {
709+ footer . style . backgroundColor = `rgba(40, 40, 40, ${ headerFooterOpacity } )` ;
710+ }
711+ } ,
657712
658713 /**
659714 * Restores the panel state based on saved settings.
@@ -671,9 +726,14 @@ window.MaxExtensionFloatingPanel = {
671726 * This method should be called when the extension is initialized.
672727 */
673728 initialize : function ( ) {
674- this . loadPanelSettings ( ) ;
729+ // First, set default settings to avoid null reference
730+ this . currentPanelSettings = { ...this . defaultPanelSettings } ;
731+
732+ // Create the panel with default settings initially
675733 this . createFloatingPanel ( ) ;
676- this . restorePanelState ( ) ;
734+
735+ // Load settings and update the panel once settings are available
736+ this . loadPanelSettings ( ) ;
677737
678738 // Load available profiles and initialize the profile switcher
679739 this . loadAvailableProfiles ( ) ;
0 commit comments