Skip to content

Commit

Permalink
Merge pull request #43 from pablopunk/refresh-permissions-auto
Browse files Browse the repository at this point in the history
Refresh permissions automatically
  • Loading branch information
pablopunk authored Feb 29, 2024
2 parents b0659d0 + 96f8e03 commit 8e4aad6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
20 changes: 8 additions & 12 deletions Swift Shift/src/app/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import ShortcutRecorder
import Sparkle

struct SettingsView: View {
@State var hasPermissions = false
private var version: String? = nil
@State private var hasPermissions = false
private var version: String?
private let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()

init(hasPermissions: Bool = false) {
self.hasPermissions = hasPermissions
self._hasPermissions = State(initialValue: hasPermissions)
self.version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
}

private func refreshPermissions() {
hasPermissions = PermissionsManager.hasAccessibilityPermission()
hasPermissions = PermissionsManager.hasAccessibilityPermission()
}

var body: some View {
Expand Down Expand Up @@ -52,21 +53,16 @@ struct SettingsView: View {
}
})
.keyboardShortcut("Q", modifiers: .command)

if !hasPermissions {
Button("Refresh permissions") {
refreshPermissions()
}
.buttonStyle(.borderedProminent)
.tint(.orange)
}
}
.padding([.bottom, .horizontal])
.padding(.top, 5)
}
.onAppear {
refreshPermissions()
}
.onReceive(timer) { _ in
refreshPermissions()
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion Swift Shift/src/permissions/PermissionsRequestView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct PermissionRequestView: View {
.lineLimit(2)
HStack {
Text("Accessibility").font(.subheadline)
Image(systemName: "exclamationmark.triangle").foregroundColor(.orange)
Spacer()
Button("Open Preferences") {
PermissionsManager.openPreferences(at: .accessibility)
Expand All @@ -20,5 +21,5 @@ struct PermissionRequestView: View {
}

#Preview {
PermissionRequestView()
PermissionRequestView().padding()
}

0 comments on commit 8e4aad6

Please sign in to comment.