Skip to content

Commit

Permalink
Initialize config loader earlier. Fixes #55
Browse files Browse the repository at this point in the history
  • Loading branch information
johnste committed May 25, 2019
1 parent dabe437 commit 82c40cb
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 31 deletions.
21 changes: 21 additions & 0 deletions Finicky/Finicky.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
54899CCC1B20D5BC00647101 /* Sources */,
54899CCD1B20D5BC00647101 /* Frameworks */,
54899CCE1B20D5BC00647101 /* Resources */,
54DD12C722989E1000D5D2BF /* ShellScript */,
);
buildRules = (
);
Expand Down Expand Up @@ -276,6 +277,26 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
54DD12C722989E1000D5D2BF /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
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";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
54899CCC1B20D5BC00647101 /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down
16 changes: 6 additions & 10 deletions Finicky/Finicky/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
@IBOutlet weak var textView: NSTextView!

@objc var statusItem: NSStatusItem!
var configLoader: FinickyConfig!
var shortUrlResolver: FNShortUrlResolver!
var configLoader: FinickyConfig = FinickyConfig()
var shortUrlResolver: FNShortUrlResolver = FNShortUrlResolver()
@objc var isActive: Bool = true

func applicationDidFinishLaunching(_ aNotification: Notification) {

func applicationWillFinishLaunching(_ aNotification: Notification) {
yourTextField.delegate = self
let bundleId = "net.kassett.Finicky"
LSSetDefaultHandlerForURLScheme("http" as CFString, bundleId as CFString)
Expand Down Expand Up @@ -45,6 +44,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele

configLoader = FinickyConfig(toggleIconCallback: toggleIconCallback, logToConsoleCallback: logToConsole, setShortUrlProviders: setShortUrlProviders)
configLoader.reload(showSuccess: false)

let appleEventManager:NSAppleEventManager = NSAppleEventManager.shared()
appleEventManager.setEventHandler(self, andSelector: #selector(AppDelegate.handleGetURLEvent(_:withReplyEvent:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
}

@IBAction func reloadConfig(_ sender: NSMenuItem) {
Expand Down Expand Up @@ -160,7 +162,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
showTestConfigWindow(nil)
}


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

func applicationWillFinishLaunching(_ aNotification: Notification) {
let appleEventManager:NSAppleEventManager = NSAppleEventManager.shared()
appleEventManager.setEventHandler(self, andSelector: #selector(AppDelegate.handleGetURLEvent(_:withReplyEvent:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
}

func applicationDidBecomeActive(_ aNotification: Notification) {
isActive = true
}
Expand Down
2 changes: 2 additions & 0 deletions Finicky/Finicky/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ open class FinickyConfig {
if let path = Bundle.main.path(forResource: "processUrl.js", ofType: nil ) {
processUrlJS = try! String(contentsOfFile: path, encoding: String.Encoding.utf8)
}

createContext()
}

public convenience init(toggleIconCallback: @escaping (_ hide: Bool) -> Void, logToConsoleCallback: @escaping (_ message: String) -> Void , setShortUrlProviders: @escaping (_ shortUrlProviders: [String]?) -> Void) {
Expand Down
6 changes: 3 additions & 3 deletions Finicky/Finicky/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.0-RC1</string>
<string>v2.0-rc.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand All @@ -67,9 +67,9 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<string>123</string>
<key>LSApplicationCategoryType</key>
<string></string>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
Expand Down
43 changes: 25 additions & 18 deletions Finicky/Finicky/ShortUrlResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,37 @@ class ResolveShortUrls: NSObject, URLSessionDelegate, URLSessionTaskDelegate {
}
}

let defaultUrlShorteners = [
"adf.ly",
"bit.do",
"bit.ly",
"buff.ly",
"deck.ly",
"fur.ly",
"goo.gl",
"is.gd",
"mcaf.ee",
"ow.ly",
"spoti.fi",
"su.pr",
"t.co",
"tiny.cc",
"tinyurl.com"
]


class FNShortUrlResolver {

fileprivate var shortUrlProviders : [String] = []
var version : String;

init(shortUrlProviders: [String]?) {
self.shortUrlProviders = shortUrlProviders ?? [
"adf.ly",
"bit.do",
"bit.ly",
"buff.ly",
"deck.ly",
"fur.ly",
"goo.gl",
"is.gd",
"mcaf.ee",
"ow.ly",
"spoti.fi",
"su.pr",
"t.co",
"tiny.cc",
"tinyurl.com"
]
init() {
self.shortUrlProviders = defaultUrlShorteners
self.version = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String
}

init(shortUrlProviders: [String]?) {
self.shortUrlProviders = shortUrlProviders ?? defaultUrlShorteners
self.version = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String
}

Expand Down

0 comments on commit 82c40cb

Please sign in to comment.