Skip to content
Open
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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ Use it in CI with [mobai-ci](https://github.com/MobAI-App/mobai-ci).
The SwiftUI app bundles the CLI and adds:

- Searchable simulator status, disk-size, and live RAM columns.
- Searchable service profiles with per-daemon controls and purpose summaries.
- Searchable service profiles with per-daemon controls and purpose summaries,
exportable as a [profile file](#profile-files).
- Read-only disk analysis plus confirmed cleanup of allowlisted data.
- Clone, rename, erase, delete, and Finder shortcuts.

Expand Down Expand Up @@ -209,6 +210,9 @@ arrow keys and space to tick whole features to keep enabled, or press `→` to o
a feature and keep individual daemons within it. Point it at a directory to save
`<name>.json` there, or omit the path to print to stdout.

In the macOS app, pick the services to keep and click **Export…** to save the
same selection as a profile file.

### Checking a simulator with doctor

Slimming a simulator turns features off on purpose, so a test suite that needs
Expand Down
25 changes: 25 additions & 0 deletions gui/AppModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,31 @@ final class AppModel: ObservableObject {
keptServiceLabels.removeAll()
}

/// The profile Apply would use, as a file `simslim on --profile` reads. A daemon
/// a kept category already covers is not listed again in "keep".
func profileFileData() throws -> Data {
let covered = categories.filter { keptCategoryIDs.contains($0.id) }
.reduce(into: Set<String>()) { $0.formUnion($1.labels) }
let except = keptCategoryIDs.sorted()
let keep = keptServiceLabels.subtracting(covered).sorted()
guard !except.isEmpty || !keep.isEmpty else { return Data("{}\n".utf8) }

let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
let profile = SlimProfileFile(
except: except.isEmpty ? nil : except, keep: keep.isEmpty ? nil : keep)
return try encoder.encode(profile) + Data("\n".utf8)
}

func exportProfile(to url: URL) {
do {
try profileFileData().write(to: url, options: .atomic)
record(.success, "Exported the service profile to \(url.path)")
} catch {
recordFailure("Profile export failed: \(error.localizedDescription)", present: true)
}
}

func setDiskCleanupCategory(_ category: DiskCleanupCategory, selected: Bool) {
guard category.canClean else { return }
if selected {
Expand Down
14 changes: 14 additions & 0 deletions gui/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,11 @@ private struct ProfileSidebar: View {
Text("Services to keep")
.font(.headline)
Spacer()
Button("Export…") { exportProfile() }
.buttonStyle(.plain)
.foregroundStyle(.tint)
.disabled(model.categories.isEmpty)
.help("Save these services as a profile file for simslim on --profile")
Button("Full Slim") { model.resetProfile() }
.buttonStyle(.plain)
.foregroundStyle(.tint)
Expand Down Expand Up @@ -872,6 +877,15 @@ private struct ProfileSidebar: View {
}
}

private func exportProfile() {
let panel = NSSavePanel()
panel.allowedContentTypes = [.json]
panel.nameFieldStringValue = "profile.json"
panel.message = "Apply it with simslim on <udid> --profile <file>."
guard panel.runModal() == .OK, let url = panel.url else { return }
model.exportProfile(to: url)
}

private var stateLegend: some View {
VStack(alignment: .leading, spacing: 8) {
Text("Service state")
Expand Down
6 changes: 6 additions & 0 deletions gui/Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ struct AlwaysEnabledService: Decodable, Identifiable, Equatable {
var id: String { label }
}

/// A profile file for `simslim on --profile`; mirrors SlimProfile in profile_file.go.
struct SlimProfileFile: Encodable {
let except: [String]?
let keep: [String]?
}

struct SimulatorMeasurement: Decodable, Equatable {
let processes: Int
let bytes: Int64
Expand Down
Loading