Skip to content

Commit

Permalink
✨ Finish new update window
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKai77 committed Jun 16, 2024
1 parent f4f7637 commit a9d6b0c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 51 deletions.
5 changes: 4 additions & 1 deletion Loop/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@
"Include padding" : {

},
"Install Update" : {
"Install" : {

},
"Instant" : {
Expand Down Expand Up @@ -1844,6 +1844,9 @@
}
}
}
},
"Restart to complete" : {

},
"Restore Defaults" : {
"extractionState" : "stale",
Expand Down
94 changes: 44 additions & 50 deletions Loop/Updater/UpdateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import Luminare
import SwiftUI

struct UpdateView: View {
@Environment(\.tintColor) var tintColor

@ObservedObject var updater = AppDelegate.updater
@State var isInstalling: Bool = false
@State var readyToRestart: Bool = false

var body: some View {
VStack(spacing: 0) {
Expand Down Expand Up @@ -38,67 +41,58 @@ struct UpdateView: View {
AppDelegate.updater.dismissWindow()
}

Button("Install Update") {
AppDelegate.updater.dismissWindow()
Button {
if readyToRestart {
AppDelegate.relaunch()
}

withAnimation(.smooth(duration: 0.25)) {
isInstalling = true
}
Task {
await AppDelegate.updater.installUpdate()

withAnimation(.smooth(duration: 0.25).delay(1)) {
isInstalling = false
readyToRestart = true
}
}
} label: {
if isInstalling {
Capsule()
.frame(maxWidth: .infinity)
.frame(height: 5)
.foregroundStyle(.quinary)
.overlay {
GeometryReader { geo in
Rectangle()
.foregroundStyle(tintColor())
.clipShape(.rect(cornerRadius: 4))
.frame(width: CGFloat(updater.progressBar.1) * geo.size.width)
.animation(.easeIn(duration: 1), value: updater.progressBar.1)
.shadow(color: tintColor(), radius: 2)
}
}
.overlay {
Capsule()
.strokeBorder(.quaternary, lineWidth: 1)
}
} else {
Text(readyToRestart ? "Restart to complete" : "Install")
}
}
.allowsHitTesting(!isInstalling)
}
.buttonStyle(LuminareCompactButtonStyle())
.padding(12)
.background(VisualEffectView(material: .fullScreenUI, blendingMode: .behindWindow))
.background(VisualEffectView(material: .menu, blendingMode: .behindWindow))
.overlay {
VStack {
Divider()
Spacer()
}
}
.fixedSize(horizontal: false, vertical: true)

// HStack(spacing: 2) {
// Button("Remind me later") {
// AppDelegate.updater.dismissWindow()
// }
// .buttonStyle(LuminareButtonStyle())
//
// Button(
// action: {
// if !isInstalling {
// withAnimation {
// isInstalling.toggle()
// }
// Task {
// await AppDelegate.updater.installUpdate()
// }
// } else if updater.progressBar.1 == 1.0 {
// AppDelegate.updater.dismissWindow()
// AppDelegate.relaunch()
// }
// },
// label: {
// if updater.progressBar.1 < 1.0 {
// Text(isInstalling ? "Downloading & installing..." : "Install")
// } else {
// Text("Restart to complete")
// }
// }
// )
//
// .buttonStyle(LuminareButtonStyle())
// .overlay {
// if isInstalling {
// GeometryReader { geo in
// Rectangle()
// .foregroundStyle(.tertiary)
// .clipShape(.rect(cornerRadius: 4))
// .frame(width: CGFloat(updater.progressBar.1) * geo.size.width)
// .animation(.easeIn(duration: 1), value: updater.progressBar.1)
// }
// .allowsHitTesting(false)
// .opacity(updater.progressBar.1 < 1.0 ? 1 : 0)
// }
// }
// }
// .frame(height: 42)
// }
}
.frame(width: 570, height: 480)
}
Expand Down

0 comments on commit a9d6b0c

Please sign in to comment.