Skip to content

Store the settings when the settings dialog is closed - #3996

Draft
ann0see wants to merge 1 commit into
mainfrom
ios/save-settings-on-close
Draft

ann0see wants to merge 1 commit into
mainfrom
ios/save-settings-on-close

Conversation

@ann0see

@ann0see ann0see commented Nov 15, 2026

Copy link
Copy Markdown
Member

Short description of changes

Write the settings when the settings dialog is hidden, so that they are not lost when the application is terminated before it becomes inactive.

CSettings writes the ini file when the application becomes inactive or quits. Anything that ends the process before that — a crash, or the app being killed — discards whatever the user just configured: alias, instrument, audio device, buffer delay, language, MIDI settings.

CClientSettingsDlg::hideEvent() now calls CSettings::Save ( false ). That covers closing the dialog from its menu, unticking the Settings check box, and the hide during shutdown.

CHANGELOG: Client: Fixed settings being lost when the application is closed unexpectedly

Context: Fixes an issue?

Fixes #3994 (second item).

Measured on the iOS simulator with Jamulus.ini:

Step name_base64 before the change after
alias changed, dialog closed still the old value immediately the new value (No NameBgTestPer)
simctl terminate, relaunch change lost change survives

Does this change need documentation? What needs to be documented and how?

No.

Status of this Pull Request

Working implementation.

What is missing until this pull request can be merged?

  • Tested on the iPad Pro 11-inch simulator (iOS 27.2) with Qt 6.11.1, on top of Only compile the iOS app delegate for Qt 5 #3988, because main does not launch on iOS with Qt 6 without it.
  • Verified: closing and reopening the settings dialog twice does not crash, the ini stays valid (72 KB), and no new crash reports appear.
  • The write happens on every dialog close rather than per control change, so it is one ini write per settings session.
  • Not tested on Windows, Linux or macOS. The change is not platform-specific: the same data loss applies to any termination that does not go through the inactive or quit path there too, but the desktop behaviour was not exercised.

🤖 Used AI: DeepSeek V4.1 Flash, OpenCode

Settings are currently only written when the application becomes inactive or
quits (see CSettings). Anything that ends the process before that, for example a
crash or the application being killed, discards the changes the user just made,
including the musician profile, the audio device configuration and the language.

Write them as well when the settings dialog is hidden, which covers closing it
from the menu, from the check box and during shutdown.
@ann0see ann0see added the AI AI generated or potentially AI generated label Nov 15, 2026
@ann0see ann0see mentioned this pull request Nov 15, 2026
6 of 16 tasks
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The client settings dialog now saves settings when it is hidden. It then calls the base-class hide-event handler.

Changes: Client Settings Persistence

Layer / File(s) Summary
Save settings on hide
src/clientsettingsdlg.h, src/clientsettingsdlg.cpp
CClientSettingsDlg declares a hideEvent override. The handler calls pSettings->Save(false) before calling QDialog::hideEvent.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested labels: bug

Suggested reviewers: pljones, softins

Merge Risk: Minimal · up to 9c8e5

Settings are now written to the ini file when the settings dialog is hidden, so recent changes are less likely to be lost if the app terminates early. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: the settings are now stored when the settings dialog closes. The raw summary confirms that CClientSettingsDlg::hideEvent() now calls CSettings::Save(false), so the ti…
Description check Passed The description covers the required template sections. It gives a short description of the change and a CHANGELOG entry. It links the fix to issue #3994, states that no documentation is needed, gives …
Linked Issues check Passed Directly linked issue #3994 has one checked item in scope for this PR: settings changes are lost when the app does not go inactive first. The objective is to persist settings when the settings dialog …
Out of Scope Changes check Passed The change set consists of one hideEvent override declaration in src/clientsettingsdlg.h and one hideEvent body in src/clientsettingsdlg.cpp that calls CSettings::Save(false) (per the supplied summary…
Full details: Title check

Explanation

The title states the main change: the settings are now stored when the settings dialog closes. The raw summary confirms that CClientSettingsDlg::hideEvent() now calls CSettings::Save(false), so the title matches the changeset.

Full details: Description check

Explanation

The description covers the required template sections. It gives a short description of the change and a CHANGELOG entry. It links the fix to issue #3994, states that no documentation is needed, gives the status as a working implementation, and lists what remains before merge. The checklist is not ticked, but the template treats it as a maintainer step. Some items are not in the template, such as the test table and the AI usage note, but they add useful context.

Full details: Linked Issues check

Explanation

Directly linked issue #3994 has one checked item in scope for this PR: settings changes are lost when the app does not go inactive first. The objective is to persist settings when the settings dialog is closed, so later termination does not discard them. The PR adds CClientSettingsDlg::hideEvent(), which calls CSettings::Save(false) before QDialog::hideEvent (src/clientsettingsdlg.cpp, and the override declared in src/clientsettingsdlg.h). The write covers closing the dialog from the menu, unticking the Settings check box, and hiding during shutdown. This matches the issue's measured repro (alias changed, dialog closed, ini updated). Other #3994 items (chat z-order, keyboard layout, Load Mixer Channels, labels, accessibility) are not in this PR's stated scope and are not assessed. Limits: the file diff tool returned no content, so this verdict relies on the supplied AI-generated summary of the diff and the PR description, not on a read of the changed hunk. Settings changed while the dialog stays open and the process is killed before the dialog closes are not saved by this change; the issue's repro does not cover that case.

Full details: Out of Scope Changes check

Explanation

The change set consists of one hideEvent override declaration in src/clientsettingsdlg.h and one hideEvent body in src/clientsettingsdlg.cpp that calls CSettings::Save(false) (per the supplied summary, +9/-0 lines in the .cpp and +1 line in the .h). This directly implements the settings persistence objective of #3994. No unrelated changes were identified in the supplied evidence. The file diff could not be read, so this verdict relies on the supplied summary.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: QUIET
  • Plan: Advanced
  • Run ID: fd83ae03-9a96-43a3-9c2c-87ceb011ea1e
Commits

Reviewing files that changed from the base of the PR and between 2442abc and 9c8e59d.

Files selected for processing: 2

  • src/clientsettingsdlg.cpp
  • src/clientsettingsdlg.h

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@ann0see
ann0see marked this pull request as draft November 15, 2026 17:36
@ann0see

ann0see commented Nov 15, 2026

Copy link
Copy Markdown
Member Author

Not 100% sure about this one, might need more investigation.

@ann0see ann0see added the bug Something isn't working label Nov 15, 2026
@github-project-automation github-project-automation Bot moved this to Triage in Tracking Nov 15, 2026
@ann0see ann0see added the iOS iOS runtime issue label Nov 15, 2026
Comment thread src/clientsettingsdlg.cpp

void CClientSettingsDlg::hideEvent ( QHideEvent* event )
{
// store the settings when the dialog is closed, so that they survive the

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Suggested change
// store the settings when the dialog is closed, so that they survive the
// store the settings when the dialog is hidden, so that they survive the

@ann0see

ann0see commented Nov 15, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai what do you think about this?

@coderabbitai

coderabbitai Bot commented Nov 15, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

Analysis chain

Script executed:

#!/bin/bash
printf '%s\n' '--- Repository state ---'
git status --short
git branch --show-current
printf '%s\n' '--- PR diff ---'
gh pr diff 3996 --repo jamulussoftware/jamulus 2>&1 | head -200
printf '%s\n' '--- Dialog outlines ---'
ast-grep outline src/clientsettingsdlg.cpp --items all --match 'hideEvent|CClientSettingsDlg' --view expanded 2>&1
ast-grep outline src/clientsettingsdlg.h --items all --match 'hideEvent|CClientSettingsDlg' --view expanded 2>&1
printf '%s\n' '--- Settings files ---'
fd -i 'settings.*\.(cpp|h)$' .
printf '%s\n' '--- Save, settings initialization, and dialog references ---'
rg -n -C 3 'CSettings::Save|pSettings->Save|\.Save\s*\(\s*(false|true)|CClientSettingsDlg::hideEvent|pSettings\s*=|CClientSettingsDlg\s*\(' src
printf '%s\n' '--- Contribution instructions ---'
rg -n -C 2 '^##? (Contributing to Jamulus|Using AI|Testing)|AI|testing' CONTRIBUTING.md | head -100

Length of output: 9217


Script executed:

#!/bin/bash
printf '%s\n' '--- Relevant outlines ---'
for f in src/settings.cpp src/settings.h src/clientsettingsdlg.cpp src/clientsettingsdlg.h src/clientdlg.cpp; do
  echo "--- $f"
  ast-grep outline "$f" --items all 2>&1 | head -100
done
printf '%s\n' '--- Save implementation ---'
cat -n src/settings.cpp | sed -n '1,220p'
printf '%s\n' '--- Settings declarations ---'
rg -n -C 4 'class CSettings|class CClientSettings|Save\s*\(|WriteSettings|ReadSettings|~CSettings' src/settings.h src/settings.cpp
printf '%s\n' '--- Every Save call ---'
rg -n -C 3 --glob '*.{cpp,h}' '(\.Save|->Save)\s*\(' src
printf '%s\n' '--- Dialog ownership and hiding ---'
rg -n -C 4 --glob '*.{cpp,h}' 'CClientSettingsDlg|SettingsDlg|settingsDlg|settingsdlg' src

Length of output: 89360


Script executed:

#!/bin/bash
printf '%s\n' '--- Client settings serialization ---'
cat -n src/settings.cpp | sed -n '892,1088p'
printf '%s\n' '--- Settings lifecycle connections ---'
cat -n src/settings.h | sed -n '64,105p;159,215p'
printf '%s\n' '--- Client shutdown and visibility paths ---'
cat -n src/clientdlg.cpp | sed -n '626,658p;1000,1053p'
printf '%s\n' '--- Dialog hide and text editing connections ---'
cat -n src/clientsettingsdlg.cpp | sed -n '720,785p;950,1045p'
printf '%s\n' '--- Settings and client creation ---'
rg -n -C 5 'CClientSettings\s+\w+|new\s+CClientSettings\b|CClientDlg\s+\w+|new\s+CClientDlg\b|OnAboutToQuit' src
printf '%s\n' '--- Mixer storage ---'
rg -n -C 4 'StoreAllFaderSettings\s*\(' src

Length of output: 42653


@ann0see I think this is a reasonable fix for the reported iOS case. hideEvent() uses the same Save(false) path as the existing inactive-state save. The reported alias test supports the approach, but I have not run it myself.

I would check these points before merge:

  • Focused edits: Test closing the dialog while the new-client-level or custom-directory field still has focus. Both use editingFinished, so the test should confirm that the new value reaches the settings before the save.
  • Other platforms and settings: Repeat the close-and-relaunch test on desktop, with audio and MIDI changes as well as profile changes. Also test closing the dialog while connected.
  • Save timing: The save writes the full settings file, but current mixer fader settings are copied into the settings object separately. During shutdown, that copy happens after the settings dialog closes (src/clientdlg.cpp, Line 639 and Line 648). I would verify normal shutdown and a forced termination separately; they do not have the same save sequence.

One existing limitation is worth noting: CSettings::WriteToFile writes directly to the file and does not report write errors (src/settings.cpp, Line 85). Termination during a write could leave an incomplete file. This PR adds more save opportunities, but it does not introduce that write method.

I would keep this approach for #3994 after those checks. It does not save edits if the process ends while the dialog remains open.

🤖 AI-generated review by CodeRabbit.


Learnings used

Learnt from: CR
Repo: jamulussoftware/jamulus PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2026-11-10T12:45:02.245Z
Learning: Applies to {src/sound/**,src/socket.cpp,src/server.cpp} : Applicability reference:
AGENTS.md: # Jamulus — Agent Instructions
**[`CONTRIBUTING.md`](CONTRIBUTING.md) is the source of truth for what this project requires of a contribution; where this file and CONTRIBUTING.md disagree, CONTRIBUTING.md wins.** Read it before changing code, and before opening or commenting on an issue, Pull Request or discussion here.

AGENTS.md: # Jamulus — Agent Instructions
**AI disclosure, the example form:** `> 🤖 Used AI: <model>, <harness>`. The requirement itself is [Using AI](CONTRIBUTING.md#using-ai).

AGENTS.md: # Jamulus — Agent Instructions
## Build and Test
**Testing:** run headless server (args `-s -n`), connect a client (e.g. via: `-n -c localhost`; may need jackd running on Linux. Run dummy Jack via: `jackd -d dummy`), exercise the change; use the JSON-RPC API (`docs/JSON-RPC.md`, enabled with `--jsonrpcport` and `--jsonrpcsecretfile`) where possible. Connecting a client needs a build without `serveronly` (`COMPILING.md`, "Compile time arguments"); `serveronly` rejects `-c`. A build is not a test: [Testing](CONTRIBUTING.md#testing) says what to exercise and what to report.

AGENTS.md: # Jamulus — Agent Instructions
## Where the rules are
| Before you… | Read |
|---|---|
| start writing anything at all | [the opening bullets](CONTRIBUTING.md#contributing-to-jamulus) |

AGENTS.md: # Jamulus — Agent Instructions
## Where the rules are
| Before you… | Read |
|---|---|
| touch `src/sound`, `src/socket.cpp` or `src/server.cpp` | [Real-time safety](CONTRIBUTING.md#real-time-safety) |

AGENTS.md: # Jamulus — Agent Instructions
## Where the rules are
| Before you… | Read |
|---|---|
| parse anything that arrived over the network | [Input arriving over the network](CONTRIBUTING.md#input-arriving-over-the-network) |

AGENTS.md: # Jamulus — Agent Instructions
## Where the rules are
| Before you… | Read |
|---|---|
| edit a generated file, or anything under `libs/` | [Files not to edit by hand](CONTRIBUTING.md#files-not-to-edit-by-hand) |

AGENTS.md: # Jamulus — Agent Instructions
## Where the rules are
| Before you… | Read |
|---|---|
| update the `ChangeLog` | [Documentation/Acknowledgements](CONTRIBUTING.md#documentationacknowledgements) |

AGENTS.md: # Jamulus — Agent Instructions
## Where the rules are
| Before you… | Read |
|---|---|
| resolve a design tradeoff | [general principles](CONTRIBUTING.md#jamulus-projectsource-code-general-principles) |

AGENTS.md: # Jamulus — Agent Instructions
## Where the rules are
| Before you… | Read |
|---|---|
| change an existing protocol message | [Wire compatibility](CONTRIBUTING.md#wire-compatibility) |

AGENTS.md: # Jamulus — Agent Instructions
## Where the rules are
| Before you… | Read |
|---|---|
| format code | [Source code consistency](CONTRIBUTING.md#source-code-consistency) |

AGENTS.md: # Jamulus — Agent Instructions
## Where the rules are
| Before you… | Read |
|---|---|
| use AI for any part of the work | [Using AI](CONTRIBUTING.md#using-ai) |

AGENTS.md: # Jamulus — Agent Instructions
## Where the rules are
| Before you… | Read |
|---|---|
| add a file, or copy code from elsewhere | [Licensing](CONTRIBUTING.md#licensing) |

AGENTS.md: # Jamulus — Agent Instructions
## Where the rules are
| Before you… | Read |
|---|---|
| use a Qt or C++ feature that may be too new | [Supported platforms](CONTRIBUTING.md#supported-platforms) |

AGENTS.md: # Jamulus — Agent Instructions
## Where the rules are
| Before you… | Read |
|---|---|
| add a dependency | [Dependencies](CONTRIBUTING.md#dependencies) |

AGENTS.md: # Jamulus — Agent Instructions
## Where the rules are
| Before you… | Read |
|---|---|
| write user-facing text | [User experience](CONTRIBUTING.md#user-experience) |

Source excerpt:
# Contributing to Jamulus

## Jamulus project/source code general principles

### 1. Stability

#### Real-time safety

Do not introduce code that prevents processing of audio within the _minimum_ cycle time for _any_ frame (i.e. worst case must remain viable); DO test this and produce evidence to support the change.

You are interacting with an AI system.

@mcfnord

mcfnord commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

🤖 AI: Works on desktop Linux: with this PR, closing the settings dialog writes the ini, and the edits survive the process being killed. Tested at 2442abcb plus this PR's two files, Qt 6.11.1, offscreen platform, client killed with _exit (no quit path) 0 ms and 1000 ms after close():

Edit before close() main this PR
alias typed no ini on disk, lost saved
New Client Level typed, field still focused lost 37 saved
custom directory typed, field still focused lost address saved

editingFinished fires inside close(), before the save, so focused fields need no extra flush on this platform. Not tested: Windows, macOS, a real window manager.

@pljones

pljones commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

The write happens on every dialog close rather than per control change, so it is one ini write per settings session.

Is this the right place? Why not loss of focus? It's not modal, so I can switch within Jamulus - and I probably want a save if I'm switching to another application, in case that causes a crash that's not otherwise saved.

... on the basis we're changing it ...

(Any path through app exit should already be caught.)

... but maybe it shouldn't be done in the real-time (audio, network) thread, as it's a disk write ...

And should apply equally to client and server settings.

@ann0see

ann0see commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

As I said, I'm not 100% sure about this. The issue is probably that in iOS we have multiple ways to exit the app. Force Quit, Backgrounding, ... making this behaviour more visible there. There probably is a reason why we only safe on exit.

@ann0see

ann0see commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

Actually I believe that save on exit only makes the app more resilient in case the app crashed due to some kind of misconfiguration. It auto reverts then as the config wasn't written.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI AI generated or potentially AI generated bug Something isn't working iOS iOS runtime issue

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

AI bug findings for iOS

3 participants