Skip to content

Commit

Permalink
Implemented a picker for status bar disk selection from gao-sun#169
Browse files Browse the repository at this point in the history
  • Loading branch information
jevonmao committed Jan 31, 2021
1 parent 477c7bf commit 391efb7
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions Resource/ar.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@

// MARK: Disk
"disk.eject" = "Eject";
"disk.select" = "Select disk";

// MARK: Language
"language" = "اللغة";
Expand Down
1 change: 1 addition & 0 deletions Resource/cs.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@

// MARK: Disk
"disk.eject" = "Vysunout";
"disk.select" = "Select disk";

// MARK: Language
"language" = "Language";
Expand Down
1 change: 1 addition & 0 deletions Resource/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@

// MARK: Disk
"disk.eject" = "Eject";
"disk.select" = "Select disk";

// MARK: Language
"language" = "Sprache:";
Expand Down
1 change: 1 addition & 0 deletions Resource/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@

// MARK: Disk
"disk.eject" = "Eject";
"disk.select" = "Select disk";

// MARK: Language
"language" = "Language";
Expand Down
1 change: 1 addition & 0 deletions Resource/es.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@

// MARK: Disk
"disk.eject" = "Eject";
"disk.select" = "Select disk";

// MARK: Language
"language" = "Idioma";
Expand Down
1 change: 1 addition & 0 deletions Resource/fr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@

// MARK: Disk
"disk.eject" = "Ejecter";
"disk.select" = "Select disk";

// MARK: Language
"language" = "Language";
Expand Down
1 change: 1 addition & 0 deletions Resource/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@

// MARK: Disk
"disk.eject" = "Eject";
"disk.select" = "Select disk";

// MARK: Language
"language" = "言語";
Expand Down
1 change: 1 addition & 0 deletions Resource/ko.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@

// MARK: Disk
"disk.eject" = "Eject";
"disk.select" = "Select disk";

// MARK: Language
"language" = "언어";
Expand Down
1 change: 1 addition & 0 deletions Resource/mn.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@

// MARK: Disk
"disk.eject" = "Eject";
"disk.select" = "Select disk";

// MARK: Language
"language" = "Хэл";
Expand Down
1 change: 1 addition & 0 deletions Resource/pt.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@

// MARK: Disk
"disk.eject" = "Eject";
"disk.select" = "Select disk";

// MARK: Language
"language" = "Língua";
Expand Down
1 change: 1 addition & 0 deletions Resource/ru.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@

// MARK: Disk
"disk.eject" = "Eject";
"disk.select" = "Select disk";

// MARK: Language
"language" = "Язык";
Expand Down
1 change: 1 addition & 0 deletions Resource/uk.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@

// MARK: Disk
"disk.eject" = "Eject";
"disk.select" = "Select disk";

// MARK: Language
"language" = "Мова";
Expand Down
1 change: 1 addition & 0 deletions Resource/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@

// MARK: Disk
"disk.eject" = "推出";
"disk.select" = "Select disk";

// MARK: Language
"language" = "语言";
Expand Down
7 changes: 7 additions & 0 deletions eul/Schema/EulComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ enum EulComponent: String, CaseIterable, Identifiable, Codable, JSONCodabble, Lo
return true
}

var isDiskSelectionAvailable: Bool {
guard [.Disk].contains(self) else {
return false
}
return true
}

func getView() -> AnyView {
switch self {
case .Battery:
Expand Down
6 changes: 6 additions & 0 deletions eul/Schema/EulComponentConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ struct EulComponentConfig: Codable {
var component: EulComponent
var showIcon: Bool = true
var showGraph: Bool = false
var diskSelection: String = SharedStore.disk.list?.disks.first?.name ?? "N/A"

var json: JSON {
JSON([
"component": component.rawValue,
"showIcon": showIcon,
"showGraph": showGraph,
"diskSelection": diskSelection,
])
}
}
Expand All @@ -38,5 +40,9 @@ extension EulComponentConfig {
if let bool = json["showGraph"].bool {
showGraph = bool
}

if let string = json["diskSelection"].string {
diskSelection = string
}
}
}
13 changes: 11 additions & 2 deletions eul/Store/DiskStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ class DiskStore: ObservableObject, Refreshable {

@ObservedObject var componentsStore = SharedStore.components
@ObservedObject var menuComponentsStore = SharedStore.menuComponents
var config: EulComponentConfig {
SharedStore.componentConfig[EulComponent.Disk]
}

@Published var list: DiskList?
@Published var selectedDisk: DiskList.Disk?

var ceilingBytes: UInt64? {
list?.disks.reduce(0) { $0 + $1.size }
// list?.disks.reduce(0) { $0 + $1.size }
selectedDisk?.size
}

var freeBytes: UInt64? {
list?.disks.reduce(0) { $0 + $1.freeSize }
// list?.disks.reduce(0) { $0 + $1.freeSize }
selectedDisk?.freeSize
}

var usageString: String {
Expand Down Expand Up @@ -89,6 +95,9 @@ class DiskStore: ObservableObject, Refreshable {
isEjectable: isEjectable
)
})
if config.diskSelection != "", let list = list {
selectedDisk = list.disks.filter { $0.name == config.diskSelection }.first
}
}

init() {
Expand Down
11 changes: 11 additions & 0 deletions eul/Views/Preference/PreferenceComponentConfigView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ extension Preference {
struct ComponentConfigView: View {
@EnvironmentObject var batteryStore: BatteryStore
@EnvironmentObject var componentConfigStore: ComponentConfigStore
@EnvironmentObject var diskStore: DiskStore

var component: EulComponent
var config: Binding<EulComponentConfig> {
Expand All @@ -56,6 +57,16 @@ extension Preference {
.inlineSection()
}
}
if config.wrappedValue.component.isDiskSelectionAvailable {
let disks = diskStore.list?.disks ?? []
Picker(selection: config.diskSelection, label: Text("disk.select".localized()).inlineSection(), content: {
ForEach(disks) {
Text($0.name)
.inlineSection()
}
})
.frame(width: 200)
}
}
if component == .CPU {
ComponentTextConfigView<CpuTextComponent>()
Expand Down

0 comments on commit 391efb7

Please sign in to comment.