Skip to content

Commit

Permalink
修改文件名
Browse files Browse the repository at this point in the history
改进了Launchpad和MissionControl的检测逻辑
  • Loading branch information
Caldis committed Mar 24, 2017
1 parent a4feae7 commit c0a1c60
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 28 deletions.
8 changes: 4 additions & 4 deletions Mos.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
22003C6E1E8555F0001220BC /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22003C6D1E8555F0001220BC /* Utils.swift */; };
22142DA41E25344E00E4BFBF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22142DA31E25344E00E4BFBF /* AppDelegate.swift */; };
22142DA61E25344E00E4BFBF /* ScrollMonitorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22142DA51E25344E00E4BFBF /* ScrollMonitorViewController.swift */; };
22142DA81E25344E00E4BFBF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 22142DA71E25344E00E4BFBF /* Assets.xcassets */; };
Expand All @@ -27,7 +28,6 @@
22937B091E3B657600A45C1D /* PreferencesDonateViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22937B081E3B657600A45C1D /* PreferencesDonateViewController.swift */; };
22A32B331E334B2E00A5CF38 /* PreferencesAboutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22A32B321E334B2E00A5CF38 /* PreferencesAboutViewController.swift */; };
22A32B381E334B4300A5CF38 /* PreferencesUpdatesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22A32B361E334B4300A5CF38 /* PreferencesUpdatesViewController.swift */; };
22DFD03B1E840DFA00B1E366 /* LaunchStarter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22DFD03A1E840DFA00B1E366 /* LaunchStarter.swift */; };
22F4EFEF1E325C36009EED31 /* PreferencesTabViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22F4EFEE1E325C36009EED31 /* PreferencesTabViewController.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -100,6 +100,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
22003C6D1E8555F0001220BC /* Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = "<group>"; };
22142DA01E25344E00E4BFBF /* Mos.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Mos.app; sourceTree = BUILT_PRODUCTS_DIR; };
22142DA31E25344E00E4BFBF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
22142DA51E25344E00E4BFBF /* ScrollMonitorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollMonitorViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -134,7 +135,6 @@
2295D8271E40542B00054A5C /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Main.strings"; sourceTree = "<group>"; };
22A32B321E334B2E00A5CF38 /* PreferencesAboutViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreferencesAboutViewController.swift; sourceTree = "<group>"; };
22A32B361E334B4300A5CF38 /* PreferencesUpdatesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreferencesUpdatesViewController.swift; sourceTree = "<group>"; };
22DFD03A1E840DFA00B1E366 /* LaunchStarter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LaunchStarter.swift; sourceTree = "<group>"; };
22F4EFEE1E325C36009EED31 /* PreferencesTabViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreferencesTabViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -190,7 +190,7 @@
children = (
22142DA31E25344E00E4BFBF /* AppDelegate.swift */,
2291A8A21E2A5400004181B8 /* ScrollCore.swift */,
22DFD03A1E840DFA00B1E366 /* LaunchStarter.swift */,
22003C6D1E8555F0001220BC /* Utils.swift */,
22A32B3B1E334B7A00A5CF38 /* ScrollMonitorPanel */,
22A32B3A1E334B5900A5CF38 /* PreferencesPanel */,
22A32B3C1E334B9700A5CF38 /* StatusMenu */,
Expand Down Expand Up @@ -474,9 +474,9 @@
22A32B381E334B4300A5CF38 /* PreferencesUpdatesViewController.swift in Sources */,
226A2E6E1E2E68620035F1A6 /* MouseEvent.m in Sources */,
22937B091E3B657600A45C1D /* PreferencesDonateViewController.swift in Sources */,
22DFD03B1E840DFA00B1E366 /* LaunchStarter.swift in Sources */,
22816CFF1E2B31020020D6B1 /* ScrollMonitorWindowController.swift in Sources */,
22F4EFEF1E325C36009EED31 /* PreferencesTabViewController.swift in Sources */,
22003C6E1E8555F0001220BC /* Utils.swift in Sources */,
22142DA61E25344E00E4BFBF /* ScrollMonitorViewController.swift in Sources */,
2278EE991E3DF770000AB25B /* PreferencesIgnoreViewController.swift in Sources */,
22816D011E2B47FB0020D6B1 /* StatusMenuController.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Mos/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.5.0</string>
<key>CFBundleVersion</key>
<string>20170303</string>
<string>20170324</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
53 changes: 37 additions & 16 deletions Mos/ScrollCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -482,35 +482,56 @@ class ScrollCore: NSObject {
}
return false
}
// TODO: 节流处理
// 判断 LaunchPad 是否激活
static var launchpadActiveCache = false
static var launchpadLastDetectTime = 0.0
static func launchpadIsActive() -> Bool {
let windowInfoList = CGWindowListCopyWindowInfo(CGWindowListOption.optionOnScreenOnly, CGWindowID(0)) as [AnyObject]!
for windowInfo in windowInfoList! {
let windowName = windowInfo[kCGWindowName]!
if windowName != nil && windowName as! String == "LPSpringboard" {
return true
// 如果距离上次检测时间大于500ms, 则重新检测一遍, 否则直接返回上次的结果
let nowTime = NSDate().timeIntervalSince1970
if nowTime - missioncontrolLastDetectTime > 0.5 {
ScrollCore.missioncontrolLastDetectTime = nowTime
let windowInfoList = CGWindowListCopyWindowInfo(CGWindowListOption.optionOnScreenOnly, CGWindowID(0)) as [AnyObject]!
for windowInfo in windowInfoList! {
let windowName = windowInfo[kCGWindowName]!
if windowName != nil && windowName as! String == "LPSpringboard" {
ScrollCore.launchpadActiveCache = true
return true
}
}
ScrollCore.launchpadActiveCache = false
return false
} else {
ScrollCore.missioncontrolLastDetectTime = nowTime
return ScrollCore.launchpadActiveCache
}
return false
}
// TODO: 节流处理
// 判断 MissionControl 是否激活
static var missioncontrolActiveCache = false
static var missioncontrolLastDetectTime = 0.0
static func missioncontrolIsActive() -> Bool {
let windowInfoList = CGWindowListCopyWindowInfo(CGWindowListOption.optionOnScreenOnly, CGWindowID(0)) as [AnyObject]!
for windowInfo in windowInfoList! {
let windowOwnerName = windowInfo[kCGWindowOwnerName]!
if windowOwnerName != nil && windowOwnerName as! String == "Dock" {
if windowInfo[kCGWindowName]! == nil {
return true
// 如果距离上次检测时间大于500ms, 则重新检测一遍, 否则直接返回上次的结果
let nowTime = NSDate().timeIntervalSince1970
if nowTime - missioncontrolLastDetectTime > 0.5 {
ScrollCore.missioncontrolLastDetectTime = nowTime
let windowInfoList = CGWindowListCopyWindowInfo(CGWindowListOption.optionOnScreenOnly, CGWindowID(0)) as [AnyObject]!
for windowInfo in windowInfoList! {
let windowOwnerName = windowInfo[kCGWindowOwnerName]!
if windowOwnerName != nil && windowOwnerName as! String == "Dock" {
if windowInfo[kCGWindowName]! == nil {
ScrollCore.missioncontrolActiveCache = true
return true
}
}
}
ScrollCore.missioncontrolActiveCache = false
return false
} else {
ScrollCore.missioncontrolLastDetectTime = nowTime
return ScrollCore.missioncontrolActiveCache
}
return false
}



// 打印Log
static func printLog(of event: CGEvent) {
print(ScrollCore.getScrollLog(of: event))
Expand Down
20 changes: 13 additions & 7 deletions Mos/LaunchStarter.swift → Mos/Utils.swift
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
//
// LaunchStarter.swift
// Utils.swift
// Mos
// 用于管理开机启动项
// Created by Cb on 2017/3/23.
// 常用工具类
// Created by Cb on 2017/3/24.
// Copyright © 2017年 Cb. All rights reserved.
//
// With help from: https://gist.github.com/plapier/f8e1dde1b1624dfbb3e4

import Foundation


//
// 用于管理开机启动项
// Created by Cb on 2017/3/23.
// Copyright © 2017年 Cb. All rights reserved.
// With help from: https://gist.github.com/plapier/f8e1dde1b1624dfbb3e4
//
@available(*, deprecated, message:"LSSharedFileList will deprecated in feature.")
class LaunchStarter {

static func applicationIsInStartUpItems() -> Bool {
return (LaunchStarter.itemReferencesInLoginItems().existingReference != nil)
}

static func itemReferencesInLoginItems() -> (existingReference: LSSharedFileListItem?, lastReference: LSSharedFileListItem?) {
if let appURL : NSURL = NSURL.fileURL(withPath: Bundle.main.bundlePath) as NSURL? {
if let loginItemsRef = LSSharedFileListCreate(nil, kLSSharedFileListSessionLoginItems.takeRetainedValue(), nil).takeRetainedValue() as LSSharedFileList? {
Expand All @@ -35,7 +41,7 @@ class LaunchStarter {
}
return (nil, nil)
}

// 切换是否开机加入LoginItems
static func toggleLaunchAtStartup() {
let itemReferences = LaunchStarter.itemReferencesInLoginItems()
Expand All @@ -56,7 +62,7 @@ class LaunchStarter {
}
}
}

// 从LoginItems移除
static func disableLaunchAtStartup() {
let itemReferences = LaunchStarter.itemReferencesInLoginItems()
Expand Down

0 comments on commit c0a1c60

Please sign in to comment.