SaveWorkspace writes the workspace as a v4 file (workspace envelope).
(w *Workspace)
| 130 | |
| 131 | // SaveWorkspace writes the workspace as a v4 file (workspace envelope). |
| 132 | func SaveWorkspace(w *Workspace) error { |
| 133 | path, err := DataPath() |
| 134 | if err != nil { |
| 135 | return err |
| 136 | } |
| 137 | f := diskFile{ |
| 138 | SchemaVersion: schemaVersion, |
| 139 | ActiveIdx: w.ActiveIdx, |
| 140 | Boards: w.Boards, |
| 141 | } |
| 142 | // Always persist the background — cork=false is meaningful, and the |
| 143 | // legacy Mode field must never be written. |
| 144 | bg := w.Background |
| 145 | bg.Mode = "" |
| 146 | f.Background = &bg |
| 147 | data, err := json.MarshalIndent(f, "", " ") |
| 148 | if err != nil { |
| 149 | return err |
| 150 | } |
| 151 | tmp := path + ".tmp" |
| 152 | if err := os.WriteFile(tmp, data, 0o644); err != nil { |
| 153 | return err |
| 154 | } |
| 155 | return os.Rename(tmp, path) |
| 156 | } |
| 157 | |
| 158 | // --- debouncer -------------------------------------------------------- |
| 159 |