From 82c40cbd2c622c342d78554752ff9d49948bb089 Mon Sep 17 00:00:00 2001 From: John Sterling Date: Sat, 25 May 2019 09:47:35 +0200 Subject: [PATCH] Initialize config loader earlier. Fixes #55 --- Finicky/Finicky.xcodeproj/project.pbxproj | 21 +++++++++++ Finicky/Finicky/AppDelegate.swift | 16 ++++----- Finicky/Finicky/Config.swift | 2 ++ Finicky/Finicky/Info.plist | 6 ++-- Finicky/Finicky/ShortUrlResolver.swift | 43 +++++++++++++---------- 5 files changed, 57 insertions(+), 31 deletions(-) diff --git a/Finicky/Finicky.xcodeproj/project.pbxproj b/Finicky/Finicky.xcodeproj/project.pbxproj index d56ffe8..1ff4916 100644 --- a/Finicky/Finicky.xcodeproj/project.pbxproj +++ b/Finicky/Finicky.xcodeproj/project.pbxproj @@ -180,6 +180,7 @@ 54899CCC1B20D5BC00647101 /* Sources */, 54899CCD1B20D5BC00647101 /* Frameworks */, 54899CCE1B20D5BC00647101 /* Resources */, + 54DD12C722989E1000D5D2BF /* ShellScript */, ); buildRules = ( ); @@ -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; diff --git a/Finicky/Finicky/AppDelegate.swift b/Finicky/Finicky/AppDelegate.swift index 1f4cf03..5af92ba 100644 --- a/Finicky/Finicky/AppDelegate.swift +++ b/Finicky/Finicky/AppDelegate.swift @@ -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) @@ -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) { @@ -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 @@ -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 } diff --git a/Finicky/Finicky/Config.swift b/Finicky/Finicky/Config.swift index 41631aa..c758771 100644 --- a/Finicky/Finicky/Config.swift +++ b/Finicky/Finicky/Config.swift @@ -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) { diff --git a/Finicky/Finicky/Info.plist b/Finicky/Finicky/Info.plist index 688dbd1..4400616 100644 --- a/Finicky/Finicky/Info.plist +++ b/Finicky/Finicky/Info.plist @@ -40,7 +40,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 2.0-RC1 + v2.0-rc.2 CFBundleSignature ???? CFBundleURLTypes @@ -67,9 +67,9 @@ CFBundleVersion - 1 + 123 LSApplicationCategoryType - + public.app-category.utilities LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright diff --git a/Finicky/Finicky/ShortUrlResolver.swift b/Finicky/Finicky/ShortUrlResolver.swift index 7c0b745..8889b3b 100644 --- a/Finicky/Finicky/ShortUrlResolver.swift +++ b/Finicky/Finicky/ShortUrlResolver.swift @@ -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 }