Repository navigation
Read fresh shell config before mutations #13913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sprajs
wants to merge
14
commits into
omacom:quattro
Choose a base branch
from
sprajs:fix/issue-10885
base: quattro
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b8a6794
Read current shell config before mutations
sprajs 534cae5
Keep config test IPC socket paths short
sprajs fe58aba
Use fresh toggle state and report config mutation errors
sprajs 8ac120d
Merge quattro into fix/issue-10885
omarchybot 11a12c1
Stop the config mutation fixture child during cleanup
sprajs df758a9
Merge quattro into fix/issue-10885
omarchybot 7dde27d
Merge quattro and retain fresh config writes for new bar sections
sprajs 0a324a5
Cancel stale bar drops against the fresh layout
sprajs a8ad77a
Let a plugin bar's mutation cancel its write
omarchybot ccd32d6
Merge quattro into fix/issue-10885
omarchybot f2f5dc6
Apply a change for the session only when the store found shell.json u…
omarchybot feda743
Describe session-only changes to an unusable shell.json in the shell …
omarchybot 4c04a09
Keep put from moving a widget the file already has on the bar
sprajs 66b69a5
Keep put from switching a clone the file already has back to its source
omarchybot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import QtQml | ||
| import Quickshell.Io | ||
|
|
||
| // Mutation reads are independent of the asynchronous FileView used to watch | ||
| // the running config. Never turn an unreadable/invalid file into defaults. | ||
| QtObject { | ||
| id: store | ||
|
|
||
| property string path | ||
| property string lastError: "" | ||
| // The last mutate() found shell.json present but not a usable config, before running the mutator. | ||
| property bool unusable: false | ||
| property int loadError: 0 | ||
| property int saveError: 0 | ||
| property FileView file: FileView { | ||
| path: store.path | ||
| preload: false | ||
| blockAllReads: true | ||
| blockWrites: true | ||
| atomicWrites: true | ||
| printErrors: false | ||
| onLoadFailed: function(error) { store.loadError = error } | ||
| onSaveFailed: function(error) { store.saveError = error } | ||
| } | ||
|
|
||
| function read() { | ||
| loadError = 0 | ||
| // text() alone returns cached contents. With preload disabled and | ||
| // blockAllReads, reload() invalidates them and text() reads synchronously. | ||
| file.reload() | ||
| var text = file.text() | ||
| return { text: text, error: loadError } | ||
| } | ||
|
|
||
| function reject(message) { | ||
| lastError = message | ||
| console.warn("shell.json mutation refused: " + message + " path=" + path) | ||
| return null | ||
| } | ||
|
|
||
| function mutate(mutator, defaults) { | ||
| lastError = "" | ||
| unusable = false | ||
| var source = read() | ||
| var config | ||
| if (source.error === FileViewError.FileNotFound) { | ||
| config = JSON.parse(JSON.stringify(defaults)) | ||
| } else if (source.error) { | ||
| return reject("read failed: " + source.error) | ||
| } else { | ||
| try { | ||
| config = JSON.parse(source.text) | ||
| } catch (e) { | ||
| unusable = true | ||
| return reject("invalid JSON: " + e) | ||
| } | ||
| if (!config || typeof config !== "object" || Array.isArray(config) || config.version !== 1) { | ||
| unusable = true | ||
| return reject("expected a config object with version: 1") | ||
| } | ||
| } | ||
|
|
||
| try { | ||
| // Returning false cancels a no-op mutation without writing the file. | ||
| if (mutator(config) === false) return null | ||
| config.version = 1 | ||
| var text = JSON.stringify(config, null, 2) + "\n" | ||
| } catch (e) { | ||
| return reject("mutation failed: " + e) | ||
| } | ||
|
|
||
| var current = read() | ||
| if (current.error !== source.error || current.text !== source.text) | ||
| return reject("file changed during mutation; retry the action") | ||
| if (text !== current.text) { | ||
| saveError = 0 | ||
| file.setText(text) | ||
| if (saveError) return reject("write failed: " + saveError) | ||
| } | ||
| // Atomic writes protect against partial output, not other writers after | ||
| // the comparison above. Writers do not currently share a config lock. | ||
| return config | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.