Skip to content

Commit 342fe88

Browse files
committed
feat: show storage statistics in statistics screen
Signed-off-by: Tommy van der Vorst <tommy@pixelspark.nl>
1 parent 6899226 commit 342fe88

File tree

5 files changed

+216
-43
lines changed

5 files changed

+216
-43
lines changed

Localizable.xcstrings

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5226,6 +5226,52 @@
52265226
}
52275227
}
52285228
},
5229+
"Available disk space" : {
5230+
"localizations" : {
5231+
"de" : {
5232+
"stringUnit" : {
5233+
"state" : "translated",
5234+
"value" : "Verfügbarer Speicherplatz"
5235+
}
5236+
},
5237+
"es" : {
5238+
"stringUnit" : {
5239+
"state" : "translated",
5240+
"value" : "Espacio en disco disponible"
5241+
}
5242+
},
5243+
"it" : {
5244+
"stringUnit" : {
5245+
"state" : "translated",
5246+
"value" : "Spazio su disco disponibile"
5247+
}
5248+
},
5249+
"ja" : {
5250+
"stringUnit" : {
5251+
"state" : "translated",
5252+
"value" : "利用可能なディスク容量"
5253+
}
5254+
},
5255+
"nl" : {
5256+
"stringUnit" : {
5257+
"state" : "translated",
5258+
"value" : "Beschikbare schijfruimte"
5259+
}
5260+
},
5261+
"uk" : {
5262+
"stringUnit" : {
5263+
"state" : "translated",
5264+
"value" : "Доступне місце на диску"
5265+
}
5266+
},
5267+
"zh-Hans" : {
5268+
"stringUnit" : {
5269+
"state" : "translated",
5270+
"value" : "可用磁盘空间"
5271+
}
5272+
}
5273+
}
5274+
},
52295275
"Back" : {
52305276
"localizations" : {
52315277
"de" : {
@@ -30716,6 +30762,52 @@
3071630762
}
3071730763
}
3071830764
},
30765+
"The above numbers concern the disk the Synctrain database is stored on. If these values do not match those shown by the Settings app, restarting the device may help." : {
30766+
"localizations" : {
30767+
"de" : {
30768+
"stringUnit" : {
30769+
"state" : "translated",
30770+
"value" : "Die obigen Zahlen beziehen sich auf die Festplatte, auf der die Synctrain-Datenbank gespeichert ist. Wenn diese Werte nicht mit denen in der Einstellungen-App übereinstimmen, kann ein Neustart des Geräts helfen."
30771+
}
30772+
},
30773+
"es" : {
30774+
"stringUnit" : {
30775+
"state" : "translated",
30776+
"value" : "Los números anteriores se refieren al disco en el que se almacena la base de datos de Synctrain. Si estos valores no coinciden con los que muestra la aplicación de Configuración, reiniciar el dispositivo podría ayudar."
30777+
}
30778+
},
30779+
"it" : {
30780+
"stringUnit" : {
30781+
"state" : "translated",
30782+
"value" : "I numeri sopra indicati riguardano il disco su cui è memorizzato il database di Synctrain. Se questi valori non corrispondono a quelli mostrati dall'app Impostazioni, potrebbe essere utile riavviare il dispositivo."
30783+
}
30784+
},
30785+
"ja" : {
30786+
"stringUnit" : {
30787+
"state" : "translated",
30788+
"value" : "上記の数字は、Synctrainデータベースが保存されているディスクに関するものです。これらの値が設定アプリで表示されるものと一致しない場合、デバイスを再起動すると良いかもしれません。"
30789+
}
30790+
},
30791+
"nl" : {
30792+
"stringUnit" : {
30793+
"state" : "translated",
30794+
"value" : "De bovenstaande cijfers hebben betrekking op de schijf waarop de Synctrain-database is opgeslagen. Als deze waarden niet overeenkomen met die in de Instellingen-app, kan het opnieuw opstarten van het apparaat helpen."
30795+
}
30796+
},
30797+
"uk" : {
30798+
"stringUnit" : {
30799+
"state" : "translated",
30800+
"value" : "Вищезазначені цифри стосуються диска, на якому зберігається база даних Synctrain. Якщо ці значення не відповідають тим, що показані в додатку Налаштування, перезапуск пристрою може допомогти."
30801+
}
30802+
},
30803+
"zh-Hans" : {
30804+
"stringUnit" : {
30805+
"state" : "translated",
30806+
"value" : "上述数字是有关存储Synctrain数据库的磁盘的。如果这些值与设置应用中显示的不匹配,重启设备可能会有所帮助。"
30807+
}
30808+
}
30809+
}
30810+
},
3071930811
"The app is currently using a custom configuration from config.xml in the application directory. Remove it and restart the app to revert back to the default configuration." : {
3072030812
"localizations" : {
3072130813
"de" : {
@@ -34684,6 +34776,52 @@
3468434776
}
3468534777
}
3468634778
},
34779+
"Total disk space" : {
34780+
"localizations" : {
34781+
"de" : {
34782+
"stringUnit" : {
34783+
"state" : "translated",
34784+
"value" : "Gesamter Speicherplatz"
34785+
}
34786+
},
34787+
"es" : {
34788+
"stringUnit" : {
34789+
"state" : "translated",
34790+
"value" : "Espacio total en disco"
34791+
}
34792+
},
34793+
"it" : {
34794+
"stringUnit" : {
34795+
"state" : "translated",
34796+
"value" : "Spazio totale su disco"
34797+
}
34798+
},
34799+
"ja" : {
34800+
"stringUnit" : {
34801+
"state" : "translated",
34802+
"value" : "ディスク容量の合計"
34803+
}
34804+
},
34805+
"nl" : {
34806+
"stringUnit" : {
34807+
"state" : "translated",
34808+
"value" : "Totale schijfruimte"
34809+
}
34810+
},
34811+
"uk" : {
34812+
"stringUnit" : {
34813+
"state" : "translated",
34814+
"value" : "Загальний дисковий простір"
34815+
}
34816+
},
34817+
"zh-Hans" : {
34818+
"stringUnit" : {
34819+
"state" : "translated",
34820+
"value" : "总磁盘空间"
34821+
}
34822+
}
34823+
}
34824+
},
3468734825
"Total folder size" : {
3468834826
"localizations" : {
3468934827
"de" : {

Sushitrain.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
657603EF2D0457B400B36D78 /* Intents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 657603EE2D0457B300B36D78 /* Intents.swift */; };
3131
657603F12D045D0B00B36D78 /* QuickActions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 657603F02D045D0900B36D78 /* QuickActions.swift */; };
3232
658155A52E76D1B60040332B /* SushitrainGlass.icon in Resources */ = {isa = PBXBuildFile; fileRef = 658155A42E76D1B60040332B /* SushitrainGlass.icon */; };
33+
6582C5412E893454006F92F1 /* StatisticsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6582C5402E893450006F92F1 /* StatisticsView.swift */; };
3334
6586863D2CE892130023B1DA /* IgnoresView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6586863C2CE892100023B1DA /* IgnoresView.swift */; };
3435
658A29F02CA821950061D1D5 /* AVKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 658A29EF2CA821950061D1D5 /* AVKit.framework */; };
3536
659010962E3E6279000B767E /* ZipView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 659010952E3E6276000B767E /* ZipView.swift */; };
@@ -116,6 +117,7 @@
116117
657603EE2D0457B300B36D78 /* Intents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Intents.swift; sourceTree = "<group>"; };
117118
657603F02D045D0900B36D78 /* QuickActions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickActions.swift; sourceTree = "<group>"; };
118119
658155A42E76D1B60040332B /* SushitrainGlass.icon */ = {isa = PBXFileReference; lastKnownFileType = folder.iconcomposer.icon; path = SushitrainGlass.icon; sourceTree = "<group>"; };
120+
6582C5402E893450006F92F1 /* StatisticsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatisticsView.swift; sourceTree = "<group>"; };
119121
6586863C2CE892100023B1DA /* IgnoresView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IgnoresView.swift; sourceTree = "<group>"; };
120122
658A29EF2CA821950061D1D5 /* AVKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVKit.framework; path = System/Library/Frameworks/AVKit.framework; sourceTree = SDKROOT; };
121123
659010952E3E6276000B767E /* ZipView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZipView.swift; sourceTree = "<group>"; };
@@ -245,6 +247,7 @@
245247
652763BA2C45C99200250D3C /* SettingsView.swift */,
246248
65B478662E8009DE00438671 /* Sharing.swift */,
247249
65C9E14B2C3F341F00EDCE6C /* StartView.swift */,
250+
6582C5402E893450006F92F1 /* StatisticsView.swift */,
248251
65F7EFF62E5F58B5008A64E0 /* SupportView.swift */,
249252
65C9E1462C3DB67C00EDCE6C /* Sushitrain.entitlements */,
250253
65A3D2212CCEEEA200117501 /* ThumbnailImage.swift */,
@@ -382,6 +385,7 @@
382385
65F15BFC2CA03CBE00E13DDD /* BackgroundManager.swift in Sources */,
383386
6505643D2CA98930009FFFB9 /* GridFilesView.swift in Sources */,
384387
65B478672E8009E000438671 /* Sharing.swift in Sources */,
388+
6582C5412E893454006F92F1 /* StatisticsView.swift in Sources */,
385389
65F825EC2CAF1E0900564F57 /* AddressesView.swift in Sources */,
386390
65C9E14C2C3F341F00EDCE6C /* StartView.swift in Sources */,
387391
65F15C012CA06B2300E13DDD /* UploadsView.swift in Sources */,

Sushitrain/SettingsView.swift

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,6 @@ import Foundation
77
import SwiftUI
88
import SushitrainCore
99

10-
struct TotalStatisticsView: View {
11-
@Environment(AppState.self) private var appState
12-
@State private var stats: SushitrainFolderStats? = nil
13-
14-
var body: some View {
15-
let formatter = ByteCountFormatter()
16-
17-
Form {
18-
if let stats = stats {
19-
if let global = stats.global {
20-
Section("All devices") {
21-
Text("Number of files").badge(global.files)
22-
Text("Number of directories").badge(global.directories)
23-
Text("File size").badge(formatter.string(fromByteCount: global.bytes))
24-
}
25-
}
26-
27-
if let local = stats.local {
28-
Section("This device") {
29-
Text("Number of files").badge(local.files)
30-
Text("Number of directories").badge(local.directories)
31-
Text("File size").badge(formatter.string(fromByteCount: local.bytes))
32-
}
33-
}
34-
}
35-
}
36-
.task {
37-
if self.appState.startupState != .started {
38-
self.stats = nil
39-
return
40-
}
41-
self.stats = try? self.appState.client.statistics()
42-
}
43-
.navigationTitle("Statistics")
44-
#if os(iOS)
45-
.navigationBarTitleDisplayMode(.inline)
46-
#endif
47-
#if os(macOS)
48-
.formStyle(.grouped)
49-
#endif
50-
}
51-
}
52-
5310
#if os(iOS)
5411
private struct ExportButtonView: View {
5512
enum ShowAlert {

Sushitrain/StatisticsView.swift

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (C) 2024 Tommy van der Vorst
2+
//
3+
// This Source Code Form is subject to the terms of the Mozilla Public
4+
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
5+
// You can obtain one at https://mozilla.org/MPL/2.0/.
6+
import Foundation
7+
import SwiftUI
8+
import SushitrainCore
9+
10+
struct TotalStatisticsView: View {
11+
@Environment(AppState.self) private var appState
12+
@State private var stats: SushitrainFolderStats? = nil
13+
@State private var diskSpaceFree: Int64? = nil
14+
@State private var diskSpaceTotal: Int64? = nil
15+
16+
var body: some View {
17+
let formatter = ByteCountFormatter()
18+
19+
Form {
20+
if let stats = stats {
21+
if let global = stats.global {
22+
Section("All devices") {
23+
Text("Number of files").badge(global.files)
24+
Text("Number of directories").badge(global.directories)
25+
Text("File size").badge(formatter.string(fromByteCount: global.bytes))
26+
}
27+
}
28+
29+
if let local = stats.local {
30+
Section("This device") {
31+
Text("Number of files").badge(local.files)
32+
Text("Number of directories").badge(local.directories)
33+
Text("File size").badge(formatter.string(fromByteCount: local.bytes))
34+
}
35+
}
36+
37+
if let free = self.diskSpaceFree, let total = self.diskSpaceTotal {
38+
Section {
39+
Text("Available disk space").badge(formatter.string(fromByteCount: free))
40+
Text("Total disk space").badge(formatter.string(fromByteCount: total))
41+
} footer: {
42+
Text("The above numbers concern the disk the Synctrain database is stored on. If these values do not match those shown by the Settings app, restarting the device may help.")
43+
}
44+
}
45+
}
46+
}
47+
.task {
48+
if self.appState.startupState != .started {
49+
self.stats = nil
50+
return
51+
}
52+
self.stats = try? self.appState.client.statistics()
53+
54+
self.diskSpaceFree = Int64(SushitrainGetFreeDiskSpaceMegaBytes()) * 1024 * 1024
55+
self.diskSpaceTotal = Int64(SushitrainGetTotalDiskSpaceMegaBytes()) * 1024 * 1024
56+
}
57+
.navigationTitle("Statistics")
58+
#if os(iOS)
59+
.navigationBarTitleDisplayMode(.inline)
60+
#endif
61+
#if os(macOS)
62+
.formStyle(.grouped)
63+
#endif
64+
}
65+
}

SushitrainCore/src/sushitrain.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,15 @@ func GetFreeDiskSpaceMegaBytes() int {
16421642
return 0
16431643
}
16441644

1645+
/** Returns the total size of the volume where the database is stored */
1646+
func GetTotalDiskSpaceMegaBytes() int {
1647+
dbPath := locations.Get(locations.Database)
1648+
if usage, err := fs.NewFilesystem(fs.FilesystemTypeBasic, dbPath).Usage("."); err == nil {
1649+
return int(usage.Total / 1024 / 1024)
1650+
}
1651+
return 0
1652+
}
1653+
16451654
func NewMeasurements(clt *Client) *Measurements {
16461655
return &Measurements{
16471656
client: clt,

0 commit comments

Comments
 (0)