Skip to content

Commit

Permalink
Add DoctorAlertView.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Oct 4, 2023
1 parent 59a8708 commit 7032a3f
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/apps/SettingsWindow/src/ContentViewStates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ final class ContentViewStates: ObservableObject {
@Published public var showDriverNotActivatedAlert = false
@Published public var showDriverVersionMismatchedAlert = false
@Published public var showInputMonitoringPermissionsAlert = false
@Published public var showDoctorAlert = false

//
// ContentMainView
Expand Down
3 changes: 3 additions & 0 deletions src/apps/SettingsWindow/src/View/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ struct ContentView: View {
.alert(
isPresented: contentViewStates.showInputMonitoringPermissionsAlert
) { InputMonitoringPermissionsAlertView() }
.alert(
isPresented: contentViewStates.showDoctorAlert
) { DoctorAlertView() }
}
.frame(
minWidth: 1100,
Expand Down
71 changes: 71 additions & 0 deletions src/apps/SettingsWindow/src/View/DoctorAlertView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import SwiftUI

struct DoctorAlertView: View {
@ObservedObject private var doctor = Doctor.shared

var body: some View {
ZStack(alignment: .topLeading) {
VStack(alignment: .center, spacing: 20.0) {
if !doctor.userPIDDirectoryWritable {
Label(
"Unable to write files to the working folder.",
systemImage: "exclamationmark.triangle"
)
.font(.system(size: 24))

GroupBox {
VStack(alignment: .leading, spacing: 0.0) {
Text(
"Karabiner-Elements failed to write a file to $HOME/.local/share/karabiner folder."
)
Text("Typically this is due to incorrect permissions on the $HOME/.local folder.")
Text("Make sure you have a permission to write $HOME/.local/share/karabiner.")
}
.padding()
}

GroupBox(label: Text("How to check the permission")) {
VStack(alignment: .leading, spacing: 10.0) {
HStack {
Text("1. Open Home folder in Finder")

Button(
action: { openHomeDirectory() },
label: {
Label(
"Open Home folder...",
systemImage: "arrow.forward.circle.fill")
})
}

Text("2. Press Command + Shift + . (period) to show hidden files")

Text("3. Find .local folder, and choose \"Get Info\" from Menu")

}
.padding()
}
}
}
.padding()
.frame(width: 850)

SheetCloseButton {
ContentViewStates.shared.showDoctorAlert = false
}
}
}

private func openHomeDirectory() {
NSWorkspace.shared.open(FileManager.default.homeDirectoryForCurrentUser)
}
}

struct DoctorAlertView_Previews: PreviewProvider {
static var previews: some View {
Group {
DoctorAlertView()
.previewLayout(.sizeThatFits)
}
}
}

0 comments on commit 7032a3f

Please sign in to comment.