Skip to content

Commit 82c40cb

Browse files
committed
Initialize config loader earlier. Fixes #55
1 parent dabe437 commit 82c40cb

File tree

5 files changed

+57
-31
lines changed

5 files changed

+57
-31
lines changed

Finicky/Finicky.xcodeproj/project.pbxproj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
54899CCC1B20D5BC00647101 /* Sources */,
181181
54899CCD1B20D5BC00647101 /* Frameworks */,
182182
54899CCE1B20D5BC00647101 /* Resources */,
183+
54DD12C722989E1000D5D2BF /* ShellScript */,
183184
);
184185
buildRules = (
185186
);
@@ -276,6 +277,26 @@
276277
};
277278
/* End PBXResourcesBuildPhase section */
278279

280+
/* Begin PBXShellScriptBuildPhase section */
281+
54DD12C722989E1000D5D2BF /* ShellScript */ = {
282+
isa = PBXShellScriptBuildPhase;
283+
buildActionMask = 2147483647;
284+
files = (
285+
);
286+
inputFileListPaths = (
287+
);
288+
inputPaths = (
289+
);
290+
outputFileListPaths = (
291+
);
292+
outputPaths = (
293+
);
294+
runOnlyForDeploymentPostprocessing = 0;
295+
shellPath = /bin/sh;
296+
shellScript = "#Update build number with number of git commits if in release mode\nif [ ${CONFIGURATION} == \"Release\" ]; then\nbuildNumber=$(git rev-list HEAD | wc -l | tr -d ' ')\n/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $buildNumber\" \"${PROJECT_DIR}/${INFOPLIST_FILE}\"\nfi;\n";
297+
};
298+
/* End PBXShellScriptBuildPhase section */
299+
279300
/* Begin PBXSourcesBuildPhase section */
280301
54899CCC1B20D5BC00647101 /* Sources */ = {
281302
isa = PBXSourcesBuildPhase;

Finicky/Finicky/AppDelegate.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
1111
@IBOutlet weak var textView: NSTextView!
1212

1313
@objc var statusItem: NSStatusItem!
14-
var configLoader: FinickyConfig!
15-
var shortUrlResolver: FNShortUrlResolver!
14+
var configLoader: FinickyConfig = FinickyConfig()
15+
var shortUrlResolver: FNShortUrlResolver = FNShortUrlResolver()
1616
@objc var isActive: Bool = true
1717

18-
func applicationDidFinishLaunching(_ aNotification: Notification) {
19-
18+
func applicationWillFinishLaunching(_ aNotification: Notification) {
2019
yourTextField.delegate = self
2120
let bundleId = "net.kassett.Finicky"
2221
LSSetDefaultHandlerForURLScheme("http" as CFString, bundleId as CFString)
@@ -45,6 +44,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
4544

4645
configLoader = FinickyConfig(toggleIconCallback: toggleIconCallback, logToConsoleCallback: logToConsole, setShortUrlProviders: setShortUrlProviders)
4746
configLoader.reload(showSuccess: false)
47+
48+
let appleEventManager:NSAppleEventManager = NSAppleEventManager.shared()
49+
appleEventManager.setEventHandler(self, andSelector: #selector(AppDelegate.handleGetURLEvent(_:withReplyEvent:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
4850
}
4951

5052
@IBAction func reloadConfig(_ sender: NSMenuItem) {
@@ -160,7 +162,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
160162
showTestConfigWindow(nil)
161163
}
162164

163-
164165
func openUrlWithBrowser(_ url: URL, bundleIdentifier: String, openInBackground: Bool?) {
165166
// Launch in background by default if finicky isn't active to avoid something that causes some bug to happen...
166167
// Too long ago to remember what actually happened
@@ -180,11 +181,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
180181
}
181182
}
182183

183-
func applicationWillFinishLaunching(_ aNotification: Notification) {
184-
let appleEventManager:NSAppleEventManager = NSAppleEventManager.shared()
185-
appleEventManager.setEventHandler(self, andSelector: #selector(AppDelegate.handleGetURLEvent(_:withReplyEvent:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
186-
}
187-
188184
func applicationDidBecomeActive(_ aNotification: Notification) {
189185
isActive = true
190186
}

Finicky/Finicky/Config.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ open class FinickyConfig {
5151
if let path = Bundle.main.path(forResource: "processUrl.js", ofType: nil ) {
5252
processUrlJS = try! String(contentsOfFile: path, encoding: String.Encoding.utf8)
5353
}
54+
55+
createContext()
5456
}
5557

5658
public convenience init(toggleIconCallback: @escaping (_ hide: Bool) -> Void, logToConsoleCallback: @escaping (_ message: String) -> Void , setShortUrlProviders: @escaping (_ shortUrlProviders: [String]?) -> Void) {

Finicky/Finicky/Info.plist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<key>CFBundlePackageType</key>
4141
<string>APPL</string>
4242
<key>CFBundleShortVersionString</key>
43-
<string>2.0-RC1</string>
43+
<string>v2.0-rc.2</string>
4444
<key>CFBundleSignature</key>
4545
<string>????</string>
4646
<key>CFBundleURLTypes</key>
@@ -67,9 +67,9 @@
6767
</dict>
6868
</array>
6969
<key>CFBundleVersion</key>
70-
<string>1</string>
70+
<string>123</string>
7171
<key>LSApplicationCategoryType</key>
72-
<string></string>
72+
<string>public.app-category.utilities</string>
7373
<key>LSMinimumSystemVersion</key>
7474
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
7575
<key>NSHumanReadableCopyright</key>

Finicky/Finicky/ShortUrlResolver.swift

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,37 @@ class ResolveShortUrls: NSObject, URLSessionDelegate, URLSessionTaskDelegate {
2424
}
2525
}
2626

27+
let defaultUrlShorteners = [
28+
"adf.ly",
29+
"bit.do",
30+
"bit.ly",
31+
"buff.ly",
32+
"deck.ly",
33+
"fur.ly",
34+
"goo.gl",
35+
"is.gd",
36+
"mcaf.ee",
37+
"ow.ly",
38+
"spoti.fi",
39+
"su.pr",
40+
"t.co",
41+
"tiny.cc",
42+
"tinyurl.com"
43+
]
44+
45+
2746
class FNShortUrlResolver {
2847

2948
fileprivate var shortUrlProviders : [String] = []
3049
var version : String;
3150

32-
init(shortUrlProviders: [String]?) {
33-
self.shortUrlProviders = shortUrlProviders ?? [
34-
"adf.ly",
35-
"bit.do",
36-
"bit.ly",
37-
"buff.ly",
38-
"deck.ly",
39-
"fur.ly",
40-
"goo.gl",
41-
"is.gd",
42-
"mcaf.ee",
43-
"ow.ly",
44-
"spoti.fi",
45-
"su.pr",
46-
"t.co",
47-
"tiny.cc",
48-
"tinyurl.com"
49-
]
51+
init() {
52+
self.shortUrlProviders = defaultUrlShorteners
53+
self.version = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String
54+
}
5055

56+
init(shortUrlProviders: [String]?) {
57+
self.shortUrlProviders = shortUrlProviders ?? defaultUrlShorteners
5158
self.version = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String
5259
}
5360

0 commit comments

Comments
 (0)