Skip to content

Commit 6c468bb

Browse files
committed
fix: disable idle timer while migrating (fixes #181)
1 parent 4925a88 commit 6c468bb

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

Sushitrain/App.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct SushitrainApp: App {
4444
Log.info("Logging enabled: \(enableLogging)")
4545

4646
let client = SushitrainNewClient(configPath, documentsPath, enableLogging)!
47-
47+
4848
// Optionally clear v1 and/or v2 index
4949
let clearV1Index = UserDefaults.standard.bool(forKey: "clearV1Index")
5050
let clearV2Index = UserDefaults.standard.bool(forKey: "clearV2Index")
@@ -68,7 +68,7 @@ struct SushitrainApp: App {
6868
Log.warn("Failed to delete v2 index: " + error.localizedDescription)
6969
}
7070
}
71-
71+
7272
let appState = AppState(client: client, documentsDirectory: documentsDirectory, configDirectory: configDirectory)
7373
self.appState = appState
7474

Sushitrain/AppState.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ enum AppStartupState: Equatable {
159159
if resetDeltas {
160160
Log.info("Reset deltas requested from settings")
161161
}
162-
162+
163163
DispatchQueue.global(qos: .userInitiated).async {
164164
do {
165165
// This one opens the database, migrates stuff, etc. and may take a while
@@ -175,7 +175,7 @@ enum AppStartupState: Equatable {
175175
self.isMigratedToNewDatabase = !client.hasOldDatabase()
176176
Log.info("Performing app migrations...")
177177
self.performMigrations()
178-
178+
179179
Log.info("Configuring the user interface...")
180180
self.applySettings()
181181
self.update()

Sushitrain/ContentView.swift

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,7 @@ struct MainView: View {
1414
var body: some View {
1515
switch appState.startupState {
1616
case .notStarted:
17-
VStack(spacing: 10) {
18-
ProgressView().progressViewStyle(.circular)
19-
if !appState.isMigratedToNewDatabase {
20-
// We are likely migrating now
21-
Text("Upgrading the database. This may take a few minutes, depending on how many files you have. Please do not close the app until this is finished.")
22-
.foregroundStyle(.secondary)
23-
.multilineTextAlignment(.center)
24-
.frame(maxWidth: 320)
25-
}
26-
}
17+
LoadingView(appState: appState)
2718
case .error(let e):
2819
ContentUnavailableView("Cannot start the app", systemImage: "exclamationmark.triangle.fill", description: Text(e))
2920
case .started:
@@ -274,6 +265,33 @@ private struct ContentView: View {
274265
}
275266
}
276267

268+
private struct LoadingView: View {
269+
@ObservedObject var appState: AppState
270+
271+
var body: some View {
272+
VStack(spacing: 10) {
273+
ProgressView().progressViewStyle(.circular)
274+
if !appState.isMigratedToNewDatabase {
275+
// We are likely migrating now
276+
Text(
277+
"Upgrading the database. This may take a few minutes, depending on how many files you have. Please do not close the app until this is finished."
278+
)
279+
.foregroundStyle(.secondary)
280+
.multilineTextAlignment(.center)
281+
.frame(maxWidth: 320)
282+
}
283+
}
284+
.onAppear {
285+
Log.info("Asserting idle timer disable")
286+
UIApplication.shared.isIdleTimerDisabled = true
287+
}
288+
.onDisappear {
289+
Log.info("Deasserting idle timer disable")
290+
UIApplication.shared.isIdleTimerDisabled = false
291+
}
292+
}
293+
}
294+
277295
private struct StartOrSearchView: View {
278296
@ObservedObject var appState: AppState
279297
@Binding var route: Route?

0 commit comments

Comments
 (0)