Skip to content

Commit

Permalink
Improved code and add all disks option
Browse files Browse the repository at this point in the history
  • Loading branch information
gao-sun committed Feb 4, 2021
1 parent 25bc621 commit 14f34d8
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 19 deletions.
1 change: 1 addition & 0 deletions Resource/ar.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
// MARK: Disk
"disk.eject" = "Eject";
"disk.select" = "Select disk";
"disk.all" = "All Disks";

// 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 @@ -120,6 +120,7 @@
// MARK: Disk
"disk.eject" = "Vysunout";
"disk.select" = "Select disk";
"disk.all" = "All Disks";

// 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 @@ -121,6 +121,7 @@
// MARK: Disk
"disk.eject" = "Eject";
"disk.select" = "Select disk";
"disk.all" = "All Disks";

// 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 @@ -121,6 +121,7 @@
// MARK: Disk
"disk.eject" = "Eject";
"disk.select" = "Select disk";
"disk.all" = "All Disks";

// 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 @@ -121,6 +121,7 @@
// MARK: Disk
"disk.eject" = "Eject";
"disk.select" = "Select disk";
"disk.all" = "All Disks";

// 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 @@ -121,6 +121,7 @@
// MARK: Disk
"disk.eject" = "Ejecter";
"disk.select" = "Select disk";
"disk.all" = "All Disks";

// 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 @@ -121,6 +121,7 @@
// MARK: Disk
"disk.eject" = "Eject";
"disk.select" = "Select disk";
"disk.all" = "All Disks";

// 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 @@ -124,6 +124,7 @@
// MARK: Disk
"disk.eject" = "Eject";
"disk.select" = "Select disk";
"disk.all" = "All Disks";

// 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 @@ -121,6 +121,7 @@
// MARK: Disk
"disk.eject" = "Eject";
"disk.select" = "Select disk";
"disk.all" = "All Disks";

// 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 @@ -121,6 +121,7 @@
// MARK: Disk
"disk.eject" = "Eject";
"disk.select" = "Select disk";
"disk.all" = "All Disks";

// 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 @@ -121,6 +121,7 @@
// MARK: Disk
"disk.eject" = "Eject";
"disk.select" = "Select disk";
"disk.all" = "All Disks";

// 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 @@ -121,6 +121,7 @@
// MARK: Disk
"disk.eject" = "Eject";
"disk.select" = "Select disk";
"disk.all" = "All Disks";

// MARK: Language
"language" = "Мова";
Expand Down
3 changes: 2 additions & 1 deletion Resource/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@

// MARK: Disk
"disk.eject" = "推出";
"disk.select" = "Select disk";
"disk.select" = "选择存储";
"disk.all" = "所有存储";

// MARK: Language
"language" = "语言";
Expand Down
5 changes: 1 addition & 4 deletions eul/Schema/EulComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ enum EulComponent: String, CaseIterable, Identifiable, Codable, JSONCodabble, Lo
}

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

func getView() -> AnyView {
Expand Down
2 changes: 1 addition & 1 deletion eul/Schema/EulComponentConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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 diskSelection: String = ""

var json: JSON {
JSON([
Expand Down
17 changes: 9 additions & 8 deletions eul/Store/DiskStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ class DiskStore: ObservableObject, Refreshable {
}

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

var selectedDisk: DiskList.Disk? {
guard config.diskSelection != "" else {
return nil
}
return list?.disks.filter { $0.name == config.diskSelection }.first
}

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

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

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

init() {
Expand Down
18 changes: 13 additions & 5 deletions eul/Views/Preference/PreferenceComponentConfigView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,23 @@ extension Preference {
.inlineSection()
}
}
if config.wrappedValue.component.isDiskSelectionAvailable {
let disks = diskStore.list?.disks ?? []
Picker(selection: config.diskSelection, label: Text("disk.select".localized()).inlineSection(), content: {
if
config.wrappedValue.component.isDiskSelectionAvailable,
let disks = diskStore.list?.disks
{
Picker(
"disk.select".localized(),
selection: config.diskSelection
) {
Text("disk.all".localized())
.inlineSection()
.tag("")
ForEach(disks) {
Text($0.name)
.inlineSection()
}
})
.frame(width: 200)
}
.frame(width: 200)
}
}
if component == .CPU {
Expand Down

0 comments on commit 14f34d8

Please sign in to comment.