Skip to content

Commit

Permalink
Add modifier keys to option dictionary (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnste committed Jun 15, 2019
1 parent d024992 commit af2ee09
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
13 changes: 13 additions & 0 deletions Finicky/Finicky/Config.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import JavaScriptCore
import AppKit

var FNConfigPath: String = "~/.finicky.js"

Expand Down Expand Up @@ -272,12 +273,24 @@ open class FinickyConfig {
let optionsDict = [
"sourceBundleIdentifier": sourceBundleIdentifier as Any,
"urlString": url.absoluteString,
"keys": getModifierKeyFlags(),
"url": FinickyAPI.getUrlParts(url.absoluteString),
] as [AnyHashable: Any]
let result = ctx.evaluateScript(processUrlJS)?.call(withArguments: [optionsDict])
return result
}

func getModifierKeyFlags() -> [String: Bool] {
return [
"shift": NSEvent.modifierFlags.contains(.shift),
"option": NSEvent.modifierFlags.contains(.option),
"command": NSEvent.modifierFlags.contains(.command),
"control": NSEvent.modifierFlags.contains(.control),
"capsLock": NSEvent.modifierFlags.contains(.capsLock),
"function": NSEvent.modifierFlags.contains(.function),
]
}

open func setupAPI() {
ctx = createJSContext()

Expand Down
2 changes: 1 addition & 1 deletion Finicky/Finicky/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>134</string>
<string>136</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Finicky is an macOS application that allows you to set up rules that decide whic
- [Basic configuration](#basic-configuration)
- [Rewrite urls](#rewrite-urls)
- [Advanced usage, settings](#advanced-usage-settings)
- [Keyboard modifiers](#keyboard-modifiers)
- [Configuration ideas](#configuration-ideas)
- [API Reference](#api-reference)
- [Issues](#issues)
Expand All @@ -48,7 +49,7 @@ Finicky is an macOS application that allows you to set up rules that decide whic
1. Install Finicky:

- Download [the latest release](https://github.com/johnste/finicky/releases), unzip and put `Finicky.app` in your application folder.
<!-- - Alternatively, you can install with [homebrew-cask](https://github.com/caskroom/homebrew-cask): `brew cask install finicky`. -->
<!-- - Alternatively, you can install with [homebrew-cask](https://github.com/caskroom/homebrew-cask): `brew cask install finicky`. -->

2. Create a file called `.finicky.js` with configuration
([examples](#example-configuration)) in your home directory.
Expand Down Expand Up @@ -128,6 +129,23 @@ module.exports = {
};
```

### Keyboard modifiers

```js
module.exports = {
defaultBrowser: "Google Chrome",
handlers: [
{
// Open links in Safari when the option key is pressed
// Valid keys are: shift, option, command, control, capsLock, and function.
// Please not that control usually opens a tooltip menu instead of visiting a link
match: ({ keys }) => keys.option,
browser: "Safari"
}
]
};
```

### Configuration ideas

See the wiki page for other [configuration ideas](https://github.com/johnste/finicky/wiki/Configuration-ideas)
Expand Down

0 comments on commit af2ee09

Please sign in to comment.