Skip to content
Merged

Systray #1448

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ jobs:
prerelease: ${{ inputs.release-as-prerelease }}
generate_release_notes: ${{ inputs.generate-release-notes }}
files: |
./massastation_*_bin/massastation_*
./massastation_installer_*/massastation_*.msi
./massastation_installer_*/massastation_*.pkg
./massastation_installer_*/massastation_*.deb
51 changes: 31 additions & 20 deletions int/config/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,22 +376,19 @@ func (n *MSConfigManager) AddNetwork(name, url string, makeDefault bool) error {
}
n.Network.Networks = append(n.Network.Networks, newNet)

networkChanged := false
if makeDefault {
n.Network.currentNetwork = &n.Network.Networks[len(n.Network.Networks)-1]
networkChanged = true
}

n.configMutex.Unlock()

// Call the network change callback if set
if networkChanged {
n.networkChangeMutex.RLock()
callback := n.onNetworkChange
n.networkChangeMutex.RUnlock()
if callback != nil {
callback()
}
// Always call callback when a network is added (even if not default) to refresh systray menu
n.networkChangeMutex.RLock()
callback := n.onNetworkChange
n.networkChangeMutex.RUnlock()
if callback != nil {
callback()
}
Comment on lines +386 to 392

Copilot AI Jan 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The callback is now invoked unconditionally when a network is added, but there are no tests validating this new callback behavior. Consider adding tests to verify that the callback is triggered correctly in all scenarios (when makeDefault is true and false).

Copilot uses AI. Check for mistakes.

return nil
Expand Down Expand Up @@ -511,25 +508,21 @@ func (n *MSConfigManager) EditNetwork(currentName string, newURL *string, makeDe
}

// Switch current network if default requested or if current was renamed
networkChanged := false
if makeDefault != nil && *makeDefault {
n.Network.currentNetwork = &n.Network.Networks[targetIdx]
networkChanged = true
} else if n.Network.currentNetwork != nil && n.Network.currentNetwork.Name == currentName && targetName != currentName {
n.Network.currentNetwork = &n.Network.Networks[targetIdx]
networkChanged = true
}

n.configMutex.Unlock()

// Call the network change callback if set
if networkChanged {
n.networkChangeMutex.RLock()
callback := n.onNetworkChange
n.networkChangeMutex.RUnlock()
if callback != nil {
callback()
}
// Always call callback when a network is edited to refresh systray menu
n.networkChangeMutex.RLock()
callback := n.onNetworkChange
n.networkChangeMutex.RUnlock()
if callback != nil {
callback()
}
Comment on lines +520 to 526

Copilot AI Jan 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The callback is now invoked unconditionally when a network is edited, but there are no tests validating this new callback behavior. Consider adding tests to verify that the callback is triggered correctly in various edit scenarios (URL changes, renames, makeDefault changes).

Copilot uses AI. Check for mistakes.

return nil
Expand All @@ -538,27 +531,32 @@ func (n *MSConfigManager) EditNetwork(currentName string, newURL *string, makeDe
// DeleteNetwork removes a network from both memory and persistent configuration
func (n *MSConfigManager) DeleteNetwork(name string) error {
n.configMutex.Lock()
defer n.configMutex.Unlock()

if name == "" {
n.configMutex.Unlock()
return fmt.Errorf("name is required")
}

cfg, err := LoadConfig()
if err != nil {
n.configMutex.Unlock()
return fmt.Errorf("load config: %w", err)
}
if cfg.Networks == nil {
n.configMutex.Unlock()
return fmt.Errorf("no networks configured")
}
if _, exists := cfg.Networks[name]; !exists {
n.configMutex.Unlock()
return fmt.Errorf("unknown network: %s", name)
}
if len(cfg.Networks) == 1 {
n.configMutex.Unlock()
return fmt.Errorf("cannot delete the last remaining network")
}

if len(n.Network.Networks) <= 1 {
n.configMutex.Unlock()
return fmt.Errorf("cannot delete the last remaining network")
}

Expand All @@ -582,6 +580,7 @@ func (n *MSConfigManager) DeleteNetwork(name string) error {
}

if err := saveConfigUnsafe(cfg); err != nil {
n.configMutex.Unlock()
return err
}

Expand All @@ -600,10 +599,22 @@ func (n *MSConfigManager) DeleteNetwork(name string) error {
// If current was deleted, switch to the first remaining network
if deletingCurrent {
if len(n.Network.Networks) == 0 {
n.configMutex.Unlock()
return fmt.Errorf("no remaining networks after deletion")
}
n.Network.currentNetwork = &n.Network.Networks[0]
}

n.configMutex.Unlock()

// Call the network change callback if set
// Always call callback when a network is deleted to refresh systray menu
n.networkChangeMutex.RLock()
callback := n.onNetworkChange
n.networkChangeMutex.RUnlock()
if callback != nil {
callback()
}
Comment on lines +610 to +617

Copilot AI Jan 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A callback invocation has been added to DeleteNetwork, but there are no tests validating this new callback behavior. Consider adding tests to verify that the callback is triggered correctly when a network is deleted.

Copilot uses AI. Check for mistakes.
Comment thread
peterjah marked this conversation as resolved.

return nil
}
Loading