Skip to content

Commit

Permalink
Merge pull request #154 from Clipy/release/v1.1.3
Browse files Browse the repository at this point in the history
Release v1.1.3
  • Loading branch information
Econa77 committed Mar 1, 2017
2 parents 6f1deed + c739c28 commit 40bbc38
Show file tree
Hide file tree
Showing 641 changed files with 20,479 additions and 15,077 deletions.
90 changes: 59 additions & 31 deletions Clipy.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

34 changes: 13 additions & 21 deletions Clipy/Sources/AppDelegate.swift
Expand Up @@ -80,7 +80,7 @@ class AppDelegate: NSObject {
defaults.synchronize()
}

ClipManager.sharedManager.clearAll()
ClipService.shared.clearAll()
}

func selectClipMenuItem(_ sender: NSMenuItem) {
Expand All @@ -97,8 +97,8 @@ class AppDelegate: NSObject {
return
}

PasteboardManager.sharedManager.copyClipToPasteboard(clip)
PasteboardManager.paste()
PasteService.shared.copyToPasteboard(with: clip)
PasteService.shared.paste()
}

func selectSnippetMenuItem(_ sender: AnyObject) {
Expand All @@ -114,8 +114,8 @@ class AppDelegate: NSObject {
NSBeep()
return
}
PasteboardManager.sharedManager.copyStringToPasteboard(snippet.content)
PasteboardManager.paste()
PasteService.shared.copyToPasteboard(with: snippet.content)
PasteService.shared.paste()
}

func terminateApplication() {
Expand Down Expand Up @@ -168,9 +168,6 @@ extension AppDelegate: NSApplicationDelegate {
// SDKs
CPYUtilities.initSDKs()

// Regist Hotkeys
HotKeyManager.sharedManager.setupDefaultHoyKey()

// Show Login Item
if !defaults.bool(forKey: Constants.UserDefaults.loginItem) && !defaults.bool(forKey: Constants.UserDefaults.suppressAlertForLoginItem) {
promptToAddLoginItems()
Expand All @@ -185,10 +182,14 @@ extension AppDelegate: NSApplicationDelegate {
// Binding Events
bind()

// Services
_ = ClipService.shared
_ = DataCleanService.shared
ExcludeAppService.shared.startAppMonitoring()
HotKeyService.shared.setupDefaultHotKeys()

// Managers
MenuManager.sharedManager.setup()
ClipManager.sharedManager.setup()
HistoryManager.sharedManager.setup()
}

func applicationWillTerminate(_ aNotification: Notification) {
Expand All @@ -202,7 +203,7 @@ fileprivate extension AppDelegate {
// Login Item
defaults.rx.observe(Bool.self, Constants.UserDefaults.loginItem, options: [.new])
.filterNil()
.subscribe(onNext: { [weak self] enabled in
.subscribe(onNext: { [weak self] _ in
self?.toggleLoginItemState()
}).addDisposableTo(disposeBag)
// Observe Screenshot
Expand All @@ -214,16 +215,7 @@ fileprivate extension AppDelegate {
// Observe Screenshot image
screenshotObserver.rx.addedImage
.subscribe(onNext: { image in
ClipManager.sharedManager.createclip(image)
}).addDisposableTo(disposeBag)
// Sleep Notification
NSWorkspace.shared().notificationCenter.rx.notification(.NSWorkspaceWillSleep)
.subscribe(onNext: { notification in
ClipManager.sharedManager.stopTimer()
}).addDisposableTo(disposeBag)
NSWorkspace.shared().notificationCenter.rx.notification(.NSWorkspaceDidWake)
.subscribe(onNext: { notification in
ClipManager.sharedManager.startTimer()
ClipService.shared.create(with: image)
}).addDisposableTo(disposeBag)
}
}
2 changes: 1 addition & 1 deletion Clipy/Sources/Constants.swift
Expand Up @@ -34,7 +34,6 @@ struct Constants {
static let hotKeys = "kCPYPrefHotKeysKey"
static let menuIconSize = "kCPYPrefMenuIconSizeKey"
static let maxHistorySize = "kCPYPrefMaxHistorySizeKey"
static let timeInterval = "kCPYPrefTimeIntervalKey"
static let storeTypes = "kCPYPrefStoreTypesKey"
static let inputPasteCommand = "kCPYPrefInputPasteCommandKey"
static let showIconInTheMenu = "kCPYPrefShowIconInTheMenuKey"
Expand All @@ -60,6 +59,7 @@ struct Constants {
static let suppressAlertForDeleteSnippet = "kCPYSuppressAlertForDeleteSnippet"
static let excludeApplications = "kCPYExcludeApplications"
static let collectCrashReport = "kCPYCollectCrashReport"
static let showColorPreviewInTheMenu = "kCPYPrefShowColorPreviewInTheMenu"
}

struct Beta {
Expand Down
24 changes: 12 additions & 12 deletions Clipy/Sources/Enums/MenuType.swift
Expand Up @@ -9,29 +9,29 @@
import Foundation

enum MenuType: String {
case Main = "ClipMenu"
case History = "HistoryMenu"
case Snippet = "SnippetMenu"
case main = "ClipMenu"
case history = "HistoryMenu"
case snippet = "SnippetMenu"

var userDefaultsKey: String {
switch self {
case .Main:
case .main:
return Constants.HotKey.mainKeyCombo
case .History:
case .history:
return Constants.HotKey.historyKeyCombo
case .Snippet:
case .snippet:
return Constants.HotKey.snippetKeyCombo
}
}

var hotKeySelector: Selector {
switch self {
case .Main:
return #selector(HotKeyManager.popUpClipMenu)
case .History:
return #selector(HotKeyManager.popUpHistoryMenu)
case .Snippet:
return #selector(HotKeyManager.popUpSnippetMenu)
case .main:
return #selector(HotKeyService.popupMainMenu)
case .history:
return #selector(HotKeyService.popupHistoryMenu)
case .snippet:
return #selector(HotKeyService.popUpSnippetMenu)
}
}

Expand Down
15 changes: 15 additions & 0 deletions Clipy/Sources/Extensions/Collection+Safe.swift
@@ -0,0 +1,15 @@
//
// Collection+Safe.swift
// Clipy
//
// Created by 古林俊佑 on 2017/03/01.
// Copyright © 2017年 Shunsuke Furubayashi. All rights reserved.
//

import Foundation

extension Collection {
subscript(safe index: Index) -> _Element? {
return index >= startIndex && index < endIndex ? self[index] : nil
}
}
21 changes: 21 additions & 0 deletions Clipy/Sources/Extensions/NSCoding+Archive.swift
@@ -0,0 +1,21 @@
//
// NSCoding+Archive.swift
// Clipy
//
// Created by 古林俊佑 on 2016/11/19.
// Copyright © 2016年 Shunsuke Furubayashi. All rights reserved.
//

import Foundation

extension NSCoding {
func archive() -> Data {
return NSKeyedArchiver.archivedData(withRootObject: self)
}
}

extension Array where Element: NSCoding {
func archive() -> Data {
return NSKeyedArchiver.archivedData(withRootObject: self)
}
}
70 changes: 70 additions & 0 deletions Clipy/Sources/Extensions/NSColor+Hex.swift
@@ -0,0 +1,70 @@
//
// NSColor+Hex.swift
// Clipy
//
// Created by 古林俊佑 on 2016/11/21.
// Copyright © 2016年 Shunsuke Furubayashi. All rights reserved.
//
// Rewrote it for NSColor with reference to the following
// https://github.com/yeahdongcn/UIColor-Hex-Swift

import Cocoa

extension NSColor {

convenience init(hex3: UInt16, alpha: CGFloat = 1) {
let divisor = CGFloat(16)
let red = CGFloat((hex3 & 0xF00) >> 8) / divisor
let green = CGFloat((hex3 & 0x0F0) >> 4) / divisor
let blue = CGFloat( hex3 & 0x00F ) / divisor
self.init(red: red, green: green, blue: blue, alpha: alpha)
}

convenience init(hex4: UInt16) {
let divisor = CGFloat(15)
let red = CGFloat((hex4 & 0xF000) >> 12) / divisor
let green = CGFloat((hex4 & 0x0F00) >> 8) / divisor
let blue = CGFloat((hex4 & 0x00F0) >> 4) / divisor
let alpha = CGFloat( hex4 & 0x000F ) / divisor
self.init(red: red, green: green, blue: blue, alpha: alpha)
}

public convenience init(hex6: UInt32, alpha: CGFloat = 1) {
let divisor = CGFloat(255)
let red = CGFloat((hex6 & 0xFF0000) >> 16) / divisor
let green = CGFloat((hex6 & 0x00FF00) >> 8) / divisor
let blue = CGFloat( hex6 & 0x0000FF ) / divisor
self.init(red: red, green: green, blue: blue, alpha: alpha)
}

public convenience init(hex8: UInt32) {
let divisor = CGFloat(255)
let red = CGFloat((hex8 & 0xFF000000) >> 24) / divisor
let green = CGFloat((hex8 & 0x00FF0000) >> 16) / divisor
let blue = CGFloat((hex8 & 0x0000FF00) >> 8) / divisor
let alpha = CGFloat( hex8 & 0x000000FF ) / divisor
self.init(red: red, green: green, blue: blue, alpha: alpha)
}

public convenience init?(hex rgba: String) {
guard rgba.hasPrefix("#") else { return nil }

let hexString: String = rgba.substring(from: rgba.characters.index(rgba.startIndex, offsetBy: 1))
var hexValue: UInt32 = 0

guard Scanner(string: hexString).scanHexInt32(&hexValue) else { return nil }

/**
* Images with alpha cannot be previewed and not be created
*/
switch hexString.characters.count {
case 3:
self.init(hex3: UInt16(hexValue))
case 6:
self.init(hex6: hexValue)
default:
return nil
}
}

}
19 changes: 19 additions & 0 deletions Clipy/Sources/Extensions/NSImage+NSColor.swift
@@ -0,0 +1,19 @@
//
// NSImage+NSColor.swift
// Clipy
//
// Created by 古林俊佑 on 2016/11/21.
// Copyright © 2016年 Shunsuke Furubayashi. All rights reserved.
//

import Cocoa

extension NSImage {
static func create(with color: NSColor, size: NSSize) -> NSImage {
let image = NSImage(size: size)
image.lockFocus()
color.drawSwatch(in: NSRect(x: 0, y: 0, width: size.width, height: size.height))
image.unlockFocus()
return image
}
}
2 changes: 1 addition & 1 deletion Clipy/Sources/Extensions/Realm+Migration.swift
Expand Up @@ -11,7 +11,7 @@ import RealmSwift

extension Realm {
static func migration() {
let config = Realm.Configuration(schemaVersion: 6, migrationBlock: { (migration, oldSchemaVersion) in
let config = Realm.Configuration(schemaVersion: 7, migrationBlock: { (migration, oldSchemaVersion) in
if oldSchemaVersion <= 2 {
// Add identifier in CPYSnippet
migration.enumerateObjects(ofType: CPYSnippet.className()) { (_, newObject) in
Expand Down

0 comments on commit 40bbc38

Please sign in to comment.