Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
6813c33
Modfy codes in order to corresponding to Swift 4.2 in Xcode 10.1.
es-kumagai Nov 28, 2018
5568760
Support Dark mode.
es-kumagai Nov 28, 2018
83463f7
Fix auto layout.
es-kumagai Nov 28, 2018
2a37771
Rename `sharedKeyListener` property.
es-kumagai Nov 28, 2018
fbd865e
Fix detaching HUD window.
es-kumagai Nov 28, 2018
908b493
Refine code around dark mode.
es-kumagai Nov 28, 2018
b5d8a25
To silence warning about type casting, add parenthesis.
es-kumagai Nov 29, 2018
68b408b
Temporarily, replace Pod `SRTabBarController` repository to mine that…
es-kumagai Nov 29, 2018
16ebef9
HUDView supports dark mode. In addition, background drawing codes mov…
es-kumagai Nov 29, 2018
98b0f4b
Modify codes more Cocoa & Swift like style.
es-kumagai Nov 29, 2018
c3ce0cb
Fix issue that HUDView didn't corresponded to dark mode perfectly.
es-kumagai Nov 29, 2018
b58928f
No longer available to assign nil as Realm instance because of no way…
es-kumagai Nov 29, 2018
c82c903
Replace CoreFoundation's types and NS Prefixed types with compatible …
es-kumagai Nov 29, 2018
d0c4b5c
Remove unnecessary `self` keyword.
es-kumagai Nov 29, 2018
a6fabd2
Revert changes that replace `print` with `NSLog`.
es-kumagai Nov 29, 2018
4e28e0a
Replace magic number with the symbol name in order to improve code re…
es-kumagai Nov 29, 2018
c497124
Rename type names and function names with new name which is more fami…
es-kumagai Nov 29, 2018
5f7ad9c
Rename a type constant to get the shared instance to more swift-like …
es-kumagai Nov 29, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ platform :osx, '10.10'
use_frameworks!

target 'QBlocker' do
pod 'SRTabBarController'
pod 'SRTabBarController', :git => 'https://github.com/es-kumagai/SRTabBarController', :branch => 'swift-4.2'
pod 'DevMateKit'
pod 'RealmSwift'
end
40 changes: 29 additions & 11 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
PODS:
- DevMateKit (1.7.1)
- Realm (0.101.0):
- Realm/Headers (= 0.101.0)
- Realm/Headers (0.101.0)
- RealmSwift (0.101.0):
- Realm (= 0.101.0)
- DevMateKit (1.9.2)
- Realm (3.12.0):
- Realm/Headers (= 3.12.0)
- Realm/Headers (3.12.0)
- RealmSwift (3.12.0):
- Realm (= 3.12.0)
- SRTabBarController (0.1.0)

DEPENDENCIES:
- DevMateKit
- RealmSwift
- SRTabBarController
- SRTabBarController (from `https://github.com/es-kumagai/SRTabBarController`, branch `swift-4.2`)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
- DevMateKit
- Realm
- RealmSwift

EXTERNAL SOURCES:
SRTabBarController:
:branch: swift-4.2
:git: https://github.com/es-kumagai/SRTabBarController

CHECKOUT OPTIONS:
SRTabBarController:
:commit: e8a177411da89eed41ec4192230550a1254598a1
:git: https://github.com/es-kumagai/SRTabBarController

SPEC CHECKSUMS:
DevMateKit: 3ba77083f5faa40266e0d2d70776de2a82c71dd0
Realm: b21596d6d7e1c054f6fae967d27263d2593ca309
RealmSwift: 5247501bcd68b9db3a718cba808e1ce45ba67034
DevMateKit: 7900fa17efc254d318d5637559d96f7769dd0a2e
Realm: cdaef23c4ddb36ab1ddffed23f5a7f3332fc5585
RealmSwift: 5576324033f0aa5ef1e0a839a3da2281dff47a7f
SRTabBarController: aeb73a975a47aff9e14f3546da2394fce8271b09

COCOAPODS: 0.39.0
PODFILE CHECKSUM: 2194d8d8289ce95c05a038fac855c59f7ee0f912

COCOAPODS: 1.5.3
126 changes: 97 additions & 29 deletions QBlocker.xcodeproj/project.pbxproj
100755 → 100644

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
8 changes: 8 additions & 0 deletions QBlocker.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
9 changes: 3 additions & 6 deletions QBlocker/AccessibilityViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,19 @@ import Cocoa

class AccessibilityViewController: NSViewController {

@IBAction func openPreferences(sender: AnyObject) {
@IBAction func openPreferences(_ sender: AnyObject) {

guard let scriptPath = NSBundle.mainBundle().pathForResource("OpenPreferences", ofType: "scpt") else {
guard let scriptPath = Bundle.main.path(forResource: "OpenPreferences", ofType: "scpt") else {
print("Could not find applescript")
return
}

let task = NSTask()
let task = Process()
task.launchPath = "/usr/bin/osascript"
task.arguments = [scriptPath]
task.launch()

// Quit the app
NSApp.terminate(self)
}



}
4 changes: 1 addition & 3 deletions QBlocker/AccessibilityWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class AccessibilityWindowController: NSWindowController {
override func windowDidLoad() {
super.windowDidLoad()

window?.level = Int(CGWindowLevelForKey(CGWindowLevelKey.PopUpMenuWindowLevelKey))
window?.level = NSWindow.Level(.popUpMenuWindow)
window?.titlebarAppearsTransparent = true
window?.backgroundColor = NSColor(calibratedHue:0.00, saturation:0.00, brightness:0.90, alpha:1.00)
}

}
6 changes: 3 additions & 3 deletions QBlocker/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import RealmSwift
class App: Object {

/// The name of the app that will be displayed as a label
dynamic var name = ""
@objc dynamic var name = ""

/// The bundle ID of the app. e.g. uk.co.wearecocoon.QBlocker
dynamic var bundleID = ""
@objc dynamic var bundleID = ""

override static func primaryKey() -> String? {
return "bundleID"
}

}
}
36 changes: 18 additions & 18 deletions QBlocker/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,47 @@ import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

private var accessibilityWindowController: NSWindowController?
private var accessibilityWindowController: AccessibilityWindowController?
private var firstRunWindowController: NSWindowController?
private lazy var preferencesWindowController: NSWindowController = {
return NSStoryboard(name: "Main", bundle: nil).instantiateControllerWithIdentifier("preferences window") as! NSWindowController
return NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "preferences window") as! NSWindowController
}()

class var sharedDelegate: AppDelegate? {
return NSApplication.sharedApplication().delegate as? AppDelegate
return NSApplication.shared.delegate as? AppDelegate
}

// MARK: - Instantiation

override init() {
super.init()
NSUserDefaults.standardUserDefaults().registerDefaults([
UserDefaults.standard.register(defaults: [
"accidentalQuits": 0,
"firstRunComplete": false,
"listMode": 0,
"listMode": ListMode.blacklist.rawValue,
"delay": 4
])
}

// MARK: - NSApplicationDelegate

func applicationDidFinishLaunching(aNotification: NSNotification) {
func applicationDidFinishLaunching(_ notification: Notification) {

setupDevMate()

let promptFlag = kAXTrustedCheckOptionPrompt.takeRetainedValue() as NSString
let myDict: CFDictionary = [promptFlag: false]
let promptFlag = kAXTrustedCheckOptionPrompt.takeRetainedValue()
let myDict = [promptFlag: false] as CFDictionary
if AXIsProcessTrustedWithOptions(myDict) {
do {
try KeyListener.sharedKeyListener.start()
try KeyListener.shared.start()
} catch {
NSLog("Could not launch listener")
print("Could not launch listener")
}

showFirstRunWindowIfRequired()

} else {
if let windowController = NSStoryboard(name: "Main", bundle: nil).instantiateControllerWithIdentifier("accessibility window") as? NSWindowController {
if let windowController = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "accessibility window") as? AccessibilityWindowController {
accessibilityWindowController = windowController
accessibilityWindowController?.showWindow(self)
accessibilityWindowController?.window?.makeKeyAndOrderFront(self)
Expand All @@ -66,25 +66,25 @@ class AppDelegate: NSObject, NSApplicationDelegate {
Show the first run screen if the NSUserDefault stating it has already be run isn't set
*/
func showFirstRunWindowIfRequired() {
guard !NSUserDefaults.standardUserDefaults().boolForKey("firstRunComplete") else {
guard !UserDefaults.standard.bool(forKey: "firstRunComplete") else {
return
}

if let windowController = NSStoryboard(name: "Main", bundle: nil).instantiateControllerWithIdentifier("first run window") as? NSWindowController {
if let windowController = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "first run window") as? NSWindowController {
firstRunWindowController = windowController
firstRunWindowController?.showWindow(self)
firstRunWindowController?.window?.makeKeyAndOrderFront(self)

NSUserDefaults.standardUserDefaults().setBool(true, forKey: "firstRunComplete")
UserDefaults.standard.set(true, forKey: "firstRunComplete")
}
}

/**
Bring the app into foreground and show the preferences window
*/
func showPreferencesWindow() {
NSApplication.sharedApplication().activateIgnoringOtherApps(true)
self.preferencesWindowController.showWindow(nil)
NSApplication.shared.activate(ignoringOtherApps: true)
preferencesWindowController.showWindow(nil)
}

/**
Expand All @@ -93,8 +93,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
func setupDevMate() {
DevMateKit.sendTrackingReport(nil, delegate: nil)
DevMateKit.setupIssuesController(nil, reportingUnhandledIssues: true)
DM_SUUpdater.sharedUpdater().automaticallyChecksForUpdates = true
DM_SUUpdater.sharedUpdater().automaticallyDownloadsUpdates = true
DM_SUUpdater.shared().automaticallyChecksForUpdates = true
DM_SUUpdater.shared().automaticallyDownloadsUpdates = true
}

}
Expand Down
17 changes: 6 additions & 11 deletions QBlocker/AtLogin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,12 @@ struct AtLogin {
/// Whether launch at login is enabled or not
static var enabled: Bool {

if launchItem != nil {
return true
}

return false

return launchItem != nil
}

/// The launch item that's stored in LSSharedFileList
private static var launchItem: LSSharedFileListItem? {
let appUrl = NSURL(fileURLWithPath: NSBundle.mainBundle().bundlePath)
let appUrl = URL(fileURLWithPath: Bundle.main.bundlePath)

guard let loginItemsRef = LSSharedFileListCreate(nil, kLSSharedFileListSessionLoginItems.takeRetainedValue(), nil) else {
return nil
Expand All @@ -36,12 +31,12 @@ struct AtLogin {
for item in loginItems as NSArray {

// Ensure that the item is a LSSharedFileListItem
guard CFGetTypeID(item) == LSSharedFileListItemGetTypeID() else {
guard CFGetTypeID(item as CFTypeRef) == LSSharedFileListItemGetTypeID() else {
continue
}

var error: Unmanaged<CFError>?
let itemUrl = LSSharedFileListItemCopyResolvedURL(item as! LSSharedFileListItem, 0, &error).takeRetainedValue() as NSURL
let itemUrl = LSSharedFileListItemCopyResolvedURL((item as! LSSharedFileListItem), 0, &error).takeRetainedValue() as URL

if itemUrl == appUrl {
return (item as! LSSharedFileListItem)
Expand All @@ -64,10 +59,10 @@ struct AtLogin {
if enabled { // remove it from the startup
LSSharedFileListItemRemove(loginItems.takeRetainedValue(), launchItem)
} else { // add it to the startup
let appUrl = NSURL(fileURLWithPath: NSBundle.mainBundle().bundlePath)
let appUrl = URL(fileURLWithPath: Bundle.main.bundlePath)
LSSharedFileListInsertItemURL(loginItems.takeRetainedValue(), kLSSharedFileListItemBeforeFirst.takeUnretainedValue(), nil, nil, appUrl as CFURL, nil, nil)
}

}

}
}
Loading