@@ -126,7 +126,7 @@ type Config struct {
126126 filePath string
127127 statusMu sync.RWMutex
128128
129- dsettingsChangedCbMap map [string ]func (LastoreDaemonStatus , interface {})
129+ dsettingsChangedCbMap map [string ]func (interface {} , interface {})
130130 dsettingsChangedCbMapMu sync.Mutex
131131}
132132
@@ -165,7 +165,7 @@ const (
165165 dSettingsKeyVersion = "version"
166166 dSettingsKeyAutoCheckUpdates = "auto-check-updates"
167167 dSettingsKeyDisableUpdateMetadata = "disable-update-metadata"
168- dSettingsKeyAutoDownloadUpdates = "auto-download-updates"
168+ DSettingsKeyAutoDownloadUpdates = "auto-download-updates"
169169 dSettingsKeyAutoClean = "auto-clean"
170170 dSettingsKeyMirrorSource = "mirror-source"
171171 dSettingsKeyUpdateNotify = "update-notify"
@@ -192,8 +192,8 @@ const (
192192 dSettingsKeyLocalDownloadSpeedLimit = "local-download-speed-limit"
193193 DSettingsKeyLastoreDaemonStatus = "lastore-daemon-status"
194194 dSettingsKeyUpdateStatus = "update-status"
195- dSettingsKeyPlatformUpdate = "platform-update"
196- dSettingsKeyPlatformUrl = "platform-url"
195+ DSettingsKeyPlatformUpdate = "platform-update"
196+ DSettingsKeyPlatformUrl = "platform-url"
197197 dSettingsKeyStartCheckRange = "start-check-range"
198198 dSettingsKeyIncludeDiskInfo = "include-disk-info"
199199 dSettingsKeyPostUpgradeOnCalendar = "post-upgrade-on-calendar"
@@ -209,7 +209,7 @@ const (
209209 dSettingsKeySystemRepoType = "system-repo-type"
210210 dSettingsKeySecurityRepoType = "security-repo-type"
211211 dSettingsKeyPlatformRepoComponents = "platform-repo-components"
212- dSettingsKeyIncrementalUpdate = "incremental-update"
212+ DSettingsKeyIncrementalUpdate = "incremental-update"
213213 dSettingsKeyIntranetUpdate = "intranet-update"
214214 dSettingsKeyGetHardwareIdByHelper = "hardware-id-from-helper"
215215 dSettingsKeyCheckPolicyInterval = "check-policy-interval"
@@ -266,7 +266,7 @@ func getConfigFromDSettings() *Config {
266266 c .DisableUpdateMetadata = v .Value ().(bool )
267267 }
268268
269- v , err = c .dsLastoreManager .Value (0 , dSettingsKeyAutoDownloadUpdates )
269+ v , err = c .dsLastoreManager .Value (0 , DSettingsKeyAutoDownloadUpdates )
270270 if err != nil {
271271 logger .Warning (err )
272272 } else {
@@ -280,7 +280,7 @@ func getConfigFromDSettings() *Config {
280280 c .AutoClean = v .Value ().(bool )
281281 }
282282
283- v , err = c .dsLastoreManager .Value (0 , dSettingsKeyIncrementalUpdate )
283+ v , err = c .dsLastoreManager .Value (0 , DSettingsKeyIncrementalUpdate )
284284 if err != nil {
285285 logger .Warning (err )
286286 } else {
@@ -485,25 +485,6 @@ func getConfigFromDSettings() *Config {
485485 }
486486 }
487487 updateLastoreDaemonStatus ()
488- _ , err = c .dsLastoreManager .ConnectValueChanged (func (key string ) {
489- switch key {
490- case DSettingsKeyLastoreDaemonStatus :
491- oldStatus := c .lastoreDaemonStatus
492- updateLastoreDaemonStatus ()
493- newStatus := c .lastoreDaemonStatus
494- if (oldStatus & DisableUpdate ) != (newStatus & DisableUpdate ) {
495- c .dsettingsChangedCbMapMu .Lock ()
496- cb := c .dsettingsChangedCbMap [key ]
497- if cb != nil {
498- go cb (DisableUpdate , c .lastoreDaemonStatus )
499- }
500- c .dsettingsChangedCbMapMu .Unlock ()
501- }
502- }
503- })
504- if err != nil {
505- logger .Warning (err )
506- }
507488
508489 v , err = c .dsLastoreManager .Value (0 , dSettingsKeyCheckUpdateMode )
509490 if err != nil {
@@ -519,15 +500,15 @@ func getConfigFromDSettings() *Config {
519500 c .UpdateStatus = v .Value ().(string )
520501 }
521502
522- v , err = c .dsLastoreManager .Value (0 , dSettingsKeyPlatformUpdate )
503+ v , err = c .dsLastoreManager .Value (0 , DSettingsKeyPlatformUpdate )
523504 if err != nil {
524505 logger .Warning (err )
525506 } else {
526507 c .PlatformUpdate = v .Value ().(bool )
527508 }
528509
529510 var url string
530- v , err = c .dsLastoreManager .Value (0 , dSettingsKeyPlatformUrl )
511+ v , err = c .dsLastoreManager .Value (0 , DSettingsKeyPlatformUrl )
531512 if err != nil {
532513 logger .Warning (err )
533514 } else {
@@ -628,15 +609,6 @@ func getConfigFromDSettings() *Config {
628609 }
629610 }
630611 updateUpgradeDeliveryEnabled ()
631- _ , err = c .dsLastoreManager .ConnectValueChanged (func (key string ) {
632- switch key {
633- case dSettingsKeyUpgradeDeliveryEnabled :
634- updateUpgradeDeliveryEnabled ()
635- }
636- })
637- if err != nil {
638- logger .Warning (err )
639- }
640612
641613 v , err = c .dsLastoreManager .Value (0 , dSettingsKeySystemCustomSource )
642614 if err != nil {
@@ -722,6 +694,110 @@ func getConfigFromDSettings() *Config {
722694 }
723695 c .OtherSourceList = append (c .OtherSourceList , "/etc/apt/sources.list.d/driver.list" )
724696 c .SecuritySourceList = append (c .SecuritySourceList , system .SecuritySourceFile )
697+
698+ _ , err = c .dsLastoreManager .ConnectValueChanged (func (key string ) {
699+ logger .Infof ("config update: key=%s" , key )
700+ switch key {
701+ case dSettingsKeyIntranetUpdate :
702+ v , err = c .dsLastoreManager .Value (0 , dSettingsKeyIntranetUpdate )
703+ if err != nil {
704+ logger .Warning (err )
705+ } else {
706+ c .IntranetUpdate = v .Value ().(bool )
707+ }
708+ case DSettingsKeyPlatformUpdate :
709+ v , err = c .dsLastoreManager .Value (0 , DSettingsKeyPlatformUpdate )
710+ if err != nil {
711+ logger .Warning (err )
712+ } else {
713+ oldValue := c .PlatformUpdate
714+ newValue := v .Value ().(bool )
715+ c .PlatformUpdate = newValue
716+ c .dsettingsChangedCbMapMu .Lock ()
717+ cb := c .dsettingsChangedCbMap [key ]
718+ if cb != nil {
719+ go cb (oldValue , newValue )
720+ }
721+ c .dsettingsChangedCbMapMu .Unlock ()
722+ }
723+ case DSettingsKeyPlatformUrl :
724+ v , err = c .dsLastoreManager .Value (0 , DSettingsKeyPlatformUrl )
725+ if err != nil {
726+ logger .Warning (err )
727+ } else {
728+ oldValue := c .PlatformUrl
729+ newValue := v .Value ().(string )
730+ c .PlatformUrl = newValue
731+ c .dsettingsChangedCbMapMu .Lock ()
732+ cb := c .dsettingsChangedCbMap [key ]
733+ if cb != nil {
734+ go cb (oldValue , newValue )
735+ }
736+ c .dsettingsChangedCbMapMu .Unlock ()
737+ }
738+ case dSettingsKeyGetHardwareIdByHelper :
739+ v , err = c .dsLastoreManager .Value (0 , dSettingsKeyGetHardwareIdByHelper )
740+ if err != nil {
741+ logger .Warning (err )
742+ } else {
743+ c .GetHardwareIdByHelper = v .Value ().(bool )
744+ }
745+ case dSettingsKeyIncludeDiskInfo :
746+ v , err = c .dsLastoreManager .Value (0 , dSettingsKeyIncludeDiskInfo )
747+ if err != nil {
748+ logger .Warning (err )
749+ } else {
750+ c .IncludeDiskInfo = v .Value ().(bool )
751+ }
752+ case DSettingsKeyIncrementalUpdate :
753+ v , err = c .dsLastoreManager .Value (0 , DSettingsKeyIncrementalUpdate )
754+ if err != nil {
755+ logger .Warning (err )
756+ } else {
757+ oldValue := c .IncrementalUpdate
758+ newValue := v .Value ().(bool )
759+ c .IncrementalUpdate = newValue
760+ c .dsettingsChangedCbMapMu .Lock ()
761+ cb := c .dsettingsChangedCbMap [key ]
762+ if cb != nil {
763+ go cb (oldValue , newValue )
764+ }
765+ c .dsettingsChangedCbMapMu .Unlock ()
766+ }
767+ case DSettingsKeyAutoDownloadUpdates :
768+ v , err = c .dsLastoreManager .Value (0 , DSettingsKeyAutoDownloadUpdates )
769+ if err != nil {
770+ logger .Warning (err )
771+ } else {
772+ oldValue := c .AutoDownloadUpdates
773+ newValue := v .Value ().(bool )
774+ c .AutoDownloadUpdates = newValue
775+ c .dsettingsChangedCbMapMu .Lock ()
776+ cb := c .dsettingsChangedCbMap [key ]
777+ if cb != nil {
778+ go cb (oldValue , newValue )
779+ }
780+ c .dsettingsChangedCbMapMu .Unlock ()
781+ }
782+ case dSettingsKeyUpgradeDeliveryEnabled :
783+ updateUpgradeDeliveryEnabled ()
784+ case DSettingsKeyLastoreDaemonStatus :
785+ oldStatus := c .lastoreDaemonStatus
786+ updateLastoreDaemonStatus ()
787+ newStatus := c .lastoreDaemonStatus
788+ if (oldStatus & DisableUpdate ) != (newStatus & DisableUpdate ) {
789+ c .dsettingsChangedCbMapMu .Lock ()
790+ cb := c .dsettingsChangedCbMap [key ]
791+ if cb != nil {
792+ go cb (oldStatus , newStatus )
793+ }
794+ c .dsettingsChangedCbMapMu .Unlock ()
795+ }
796+ }
797+ })
798+ if err != nil {
799+ logger .Warning (err )
800+ }
725801 return c
726802}
727803
@@ -747,12 +823,11 @@ func (c *Config) json2DSettings(oldConfig *Config) {
747823 _ = c .SetRepository (oldConfig .Repository )
748824 _ = c .SetMirrorsUrl (oldConfig .MirrorsUrl )
749825 _ = c .SetAllowInstallRemovePkgExecPaths (append (oldConfig .AllowInstallRemovePkgExecPaths , c .AllowInstallRemovePkgExecPaths ... ))
750- return
751826}
752827
753- func (c * Config ) ConnectConfigChanged (key string , cb func (LastoreDaemonStatus , interface {})) {
828+ func (c * Config ) ConnectConfigChanged (key string , cb func (interface {} , interface {})) {
754829 if c .dsettingsChangedCbMap == nil {
755- c .dsettingsChangedCbMap = make (map [string ]func (LastoreDaemonStatus , interface {}))
830+ c .dsettingsChangedCbMap = make (map [string ]func (interface {} , interface {}))
756831 }
757832 c .dsettingsChangedCbMapMu .Lock ()
758833 c .dsettingsChangedCbMap [key ] = cb
@@ -796,7 +871,7 @@ func (c *Config) SetUpdateNotify(enable bool) error {
796871
797872func (c * Config ) SetAutoDownloadUpdates (enable bool ) error {
798873 c .AutoDownloadUpdates = enable
799- return c .save (dSettingsKeyAutoDownloadUpdates , enable )
874+ return c .save (DSettingsKeyAutoDownloadUpdates , enable )
800875}
801876
802877func (c * Config ) SetAutoClean (enable bool ) error {
@@ -806,7 +881,7 @@ func (c *Config) SetAutoClean(enable bool) error {
806881
807882func (c * Config ) SetIncrementalUpdate (enable bool ) error {
808883 c .IncrementalUpdate = enable
809- return c .save (dSettingsKeyIncrementalUpdate , enable )
884+ return c .save (DSettingsKeyIncrementalUpdate , enable )
810885}
811886
812887func (c * Config ) UseIncrementalUpdate () bool {
0 commit comments