Skip to content

Commit

Permalink
Added confirmation when reseting user defaults, unfocused mouse delay…
Browse files Browse the repository at this point in the history
… textfield when open settings
  • Loading branch information
dennis777 committed Oct 6, 2023
1 parent 300a521 commit f45a385
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Clicker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
/* Begin PBXFileReference section */
955AF6FB26A8954800F326B2 /* SpeedtestView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpeedtestView.swift; sourceTree = "<group>"; };
95762DF026443EFF0022C2E0 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
957FB3822AD065BD003534A1 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
9591D23B2614DBC700CDBBF0 /* Clicker.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Clicker.app; sourceTree = BUILT_PRODUCTS_DIR; };
9591D23E2614DBC700CDBBF0 /* ClickerApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClickerApp.swift; sourceTree = "<group>"; };
9591D2402614DBC700CDBBF0 /* OldContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OldContentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -85,6 +86,7 @@
9591D24C2614DBC800CDBBF0 /* Info.plist */,
9591D24D2614DBC800CDBBF0 /* Clicker.entitlements */,
9591D2492614DBC800CDBBF0 /* Clicker.xcdatamodeld */,
957FB3822AD065BD003534A1 /* README.md */,
9591D2442614DBC800CDBBF0 /* Preview Content */,
);
path = Clicker;
Expand Down
27 changes: 24 additions & 3 deletions Clicker/ClickerApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct ClickerApp: App {
#if DEBUG
Divider()
Button("Reset User defaults") {
UserDefaults.reset()
showConfirmResetUserDefaultsPrompt()
}
#endif

Expand Down Expand Up @@ -87,6 +87,25 @@ struct ClickerApp: App {
SettingsView().environmentObject(appSettings)
}
}

func showConfirmResetUserDefaultsPrompt() {
let alert = NSAlert()
alert.messageText = "Are you sure?"
alert.informativeText = "Clearing the UserDefaults will\nreset all your saved information such\nas textfields, ms presets, and key command settings"
alert.addButton(withTitle: "Confirm")
alert.buttons[0].hasDestructiveAction = true
alert.addButton(withTitle: "Cancel")
let result = alert.runModal()
switch result {
case .alertFirstButtonReturn:
UserDefaults.reset()
break
case .alertSecondButtonReturn:
break
default:
break
}
}
}

final class AppDelegate: NSObject, NSApplicationDelegate {
Expand All @@ -101,14 +120,16 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
didSetWindowSize.toggle()

if UserDefaults.standard.object(forKey: "displayedWelcomeMessages") as? Bool == nil {
let appSettings = AppSettings()

let alert1 = NSAlert()
alert1.messageText = "Welcome to Clicker"
alert1.informativeText = AppSettings().welcomeMessage
alert1.informativeText = appSettings.welcomeMessage
alert1.runModal()

let alert2 = NSAlert()
alert2.messageText = "New this update"
alert2.informativeText = AppSettings().updateMessage
alert2.informativeText = appSettings.updateMessage
alert2.runModal()

UserDefaults.standard.setValue(true, forKey: "displayedWelcomeMessages")
Expand Down
8 changes: 4 additions & 4 deletions Clicker/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -493,26 +493,26 @@ struct ContentView: View {
// }

// MARK: - General Functions

func resignFirstResponder() {
DispatchQueue.main.async {
NSApp.keyWindow?.makeFirstResponder(nil)
}
}

func requestPermissions() {
if !hasPermissions() {
inject(events: createEvents(from: [(0xFF, nil)]), into: NSRunningApplication.current.processIdentifier)
cycles = 0
}
}

func hasPermissions() -> Bool {
let options: NSDictionary = [kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String : true]
let accessEnabled = AXIsProcessTrustedWithOptions(options)
return accessEnabled
}

func findRunningApplication() {
runningApplications = getRunningApplications()
if appSettings.appSelectionName == "" || appSettings.appSelectionName == "Error" {
Expand Down
24 changes: 24 additions & 0 deletions Clicker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Clicker
A simple but speedy macOS clicker for both mouse and keyboard

## How to install
1. Download the zip archive from [here]()
2. Open the .zip file
3. Move the application to the /Applications folder *(not a requirement for the app to run, but its good practice)*
4. Open Clicker, and you will see the following pop up
<img width="573" alt="Screenshot 2023-10-06 at 09 06 24" src="https://github.com/dennis777/Clicker/assets/25965937/79194004-ca80-4923-92e9-237001043f95">

5. Press `Open System Settings`
6. Enable the toggle for Clicker *(it may prompt you for authentication i.e. TouchID or Password)*
<img width="469" alt="image" src="https://github.com/dennis777/Clicker/assets/25965937/6a0959d4-7def-410d-81dd-a72f5b7ae290">

7. Back in Clicker, open settings and assign key commands *(Certain key commands are reserved for macOS such as* <kbd>⇧⌘3</kbd> *,* <kbd>⇧⌘4</kbd> *and* <kbd>⇧⌘5</kbd>*)*
<img width="174" alt="image" src="https://github.com/dennis777/Clicker/assets/25965937/1be75adf-de27-4323-9b2c-f67f57065b83">

.
<img width="387" alt="image" src="https://github.com/dennis777/Clicker/assets/25965937/f68cacca-556f-4157-9bfa-512ee73ada1d">

9. More info can be found under Help tab (<kbd>⌘/</kbd>)

## Usage
Press your defined key command to toggle the clicker on or off. *Remember these shortcuts are global, meaning they will actiate in any app, any window*
9 changes: 9 additions & 0 deletions Clicker/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ struct SettingsView: View {
.font(.title)
}
}
.onAppear {
resignFirstResponder()
}
}

func resignFirstResponder() {
DispatchQueue.main.async {
NSApp.keyWindow?.makeFirstResponder(nil)
}
}
}

Expand Down

0 comments on commit f45a385

Please sign in to comment.