Skip to content

Commit 8261b05

Browse files
committed
Swift 4.0 and High Sierra support
1 parent 1822e20 commit 8261b05

File tree

6 files changed

+60
-55
lines changed

6 files changed

+60
-55
lines changed

Screen on Screen.xcodeproj/project.pbxproj

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,15 @@
5656
E2E48A531B1E96E70023D48D /* Screen on Screen */ = {
5757
isa = PBXGroup;
5858
children = (
59-
E2D428CC1B21A336002E1F7C /* Screen on Screen.entitlements */,
6059
E2E48A561B1E96E70023D48D /* AppDelegate.swift */,
6160
E2E48A581B1E96E70023D48D /* ViewController.swift */,
6261
E2889C9B1B1F006C003D59A1 /* Utility.swift */,
6362
E2E48A5A1B1E96E70023D48D /* Images.xcassets */,
6463
E2E48A5C1B1E96E70023D48D /* Main.storyboard */,
65-
E2E48A541B1E96E70023D48D /* Supporting Files */,
66-
);
67-
path = "Screen on Screen";
68-
sourceTree = "<group>";
69-
};
70-
E2E48A541B1E96E70023D48D /* Supporting Files */ = {
71-
isa = PBXGroup;
72-
children = (
7364
E2E48A551B1E96E70023D48D /* Info.plist */,
65+
E2D428CC1B21A336002E1F7C /* Screen on Screen.entitlements */,
7466
);
75-
name = "Supporting Files";
67+
path = "Screen on Screen";
7668
sourceTree = "<group>";
7769
};
7870
/* End PBXGroup section */
@@ -103,13 +95,13 @@
10395
attributes = {
10496
LastSwiftMigration = 0720;
10597
LastSwiftUpdateCheck = 0700;
106-
LastUpgradeCheck = 0800;
98+
LastUpgradeCheck = 0900;
10799
ORGANIZATIONNAME = "Shandong University";
108100
TargetAttributes = {
109101
E2E48A501B1E96E70023D48D = {
110102
CreatedOnToolsVersion = 6.3.2;
111103
DevelopmentTeam = 5Z4L8A2TF8;
112-
LastSwiftMigration = 0800;
104+
LastSwiftMigration = 0900;
113105
SystemCapabilities = {
114106
com.apple.Sandbox = {
115107
enabled = 1;
@@ -183,14 +175,20 @@
183175
CLANG_CXX_LIBRARY = "libc++";
184176
CLANG_ENABLE_MODULES = YES;
185177
CLANG_ENABLE_OBJC_ARC = YES;
178+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
186179
CLANG_WARN_BOOL_CONVERSION = YES;
180+
CLANG_WARN_COMMA = YES;
187181
CLANG_WARN_CONSTANT_CONVERSION = YES;
188182
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
189183
CLANG_WARN_EMPTY_BODY = YES;
190184
CLANG_WARN_ENUM_CONVERSION = YES;
191185
CLANG_WARN_INFINITE_RECURSION = YES;
192186
CLANG_WARN_INT_CONVERSION = YES;
187+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
188+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
193189
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
190+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
191+
CLANG_WARN_STRICT_PROTOTYPES = YES;
194192
CLANG_WARN_SUSPICIOUS_MOVE = YES;
195193
CLANG_WARN_UNREACHABLE_CODE = YES;
196194
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -229,14 +227,20 @@
229227
CLANG_CXX_LIBRARY = "libc++";
230228
CLANG_ENABLE_MODULES = YES;
231229
CLANG_ENABLE_OBJC_ARC = YES;
230+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
232231
CLANG_WARN_BOOL_CONVERSION = YES;
232+
CLANG_WARN_COMMA = YES;
233233
CLANG_WARN_CONSTANT_CONVERSION = YES;
234234
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
235235
CLANG_WARN_EMPTY_BODY = YES;
236236
CLANG_WARN_ENUM_CONVERSION = YES;
237237
CLANG_WARN_INFINITE_RECURSION = YES;
238238
CLANG_WARN_INT_CONVERSION = YES;
239+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
240+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
239241
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
242+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
243+
CLANG_WARN_STRICT_PROTOTYPES = YES;
240244
CLANG_WARN_SUSPICIOUS_MOVE = YES;
241245
CLANG_WARN_UNREACHABLE_CODE = YES;
242246
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -266,11 +270,12 @@
266270
CODE_SIGN_ENTITLEMENTS = "Screen on Screen/Screen on Screen.entitlements";
267271
CODE_SIGN_IDENTITY = "Mac Developer";
268272
COMBINE_HIDPI_IMAGES = YES;
273+
DEVELOPMENT_TEAM = 5Z4L8A2TF8;
269274
INFOPLIST_FILE = "$(SRCROOT)/Screen on Screen/Info.plist";
270275
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
271276
PRODUCT_BUNDLE_IDENTIFIER = "cn.edu.sdu.$(PRODUCT_NAME:rfc1034identifier)";
272277
PRODUCT_NAME = "Screen on Screen";
273-
SWIFT_VERSION = 3.0;
278+
SWIFT_VERSION = 4.0;
274279
};
275280
name = Debug;
276281
};
@@ -281,11 +286,12 @@
281286
CODE_SIGN_ENTITLEMENTS = "Screen on Screen/Screen on Screen.entitlements";
282287
CODE_SIGN_IDENTITY = "Mac Developer";
283288
COMBINE_HIDPI_IMAGES = YES;
289+
DEVELOPMENT_TEAM = 5Z4L8A2TF8;
284290
INFOPLIST_FILE = "$(SRCROOT)/Screen on Screen/Info.plist";
285291
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
286292
PRODUCT_BUNDLE_IDENTIFIER = "cn.edu.sdu.$(PRODUCT_NAME:rfc1034identifier)";
287293
PRODUCT_NAME = "Screen on Screen";
288-
SWIFT_VERSION = 3.0;
294+
SWIFT_VERSION = 4.0;
289295
};
290296
name = Release;
291297
};

Screen on Screen.xcodeproj/xcuserdata/cc941201.xcuserdatad/xcschemes/Screen on Screen.xcscheme

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0800"
3+
LastUpgradeVersion = "0900"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
language = ""
2930
shouldUseLaunchSchemeArgsEnv = "YES">
3031
<Testables>
3132
</Testables>
@@ -45,6 +46,7 @@
4546
buildConfiguration = "Debug"
4647
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4748
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
49+
language = ""
4850
launchStyle = "0"
4951
useCustomWorkingDirectory = "NO"
5052
ignoresPersistentStateOnLaunch = "NO"

Screen on Screen/AppDelegate.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// AppDelegate.swift
33
// ProjectorViewer
44
//
5-
// Created by 张国晔 on 15/6/3.
6-
// Copyright (c) 2015年 Shandong University. All rights reserved.
5+
// Created by Guoye Zhang on 15/6/3.
6+
// Copyright (c) 2015 Guoye Zhang. All rights reserved.
77
//
88

99
import Cocoa
@@ -21,7 +21,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
2121
self.updateZoom()
2222
}
2323
if Utility.onTop {
24-
onTopMenuItem.state = NSOnState
24+
onTopMenuItem.state = .on
2525
}
2626
}
2727

@@ -33,55 +33,55 @@ class AppDelegate: NSObject, NSApplicationDelegate {
3333
updateDisplays()
3434
}
3535

36-
func display(_ sender: NSMenuItem) {
37-
screenMenu.item(at: Utility.displayNo)?.state = NSOffState
36+
@objc func display(_ sender: NSMenuItem) {
37+
screenMenu.item(at: Utility.displayNo)?.state = .off
3838
Utility.displayNo = sender.tag
39-
screenMenu.item(at: Utility.displayNo)?.state = NSOnState
39+
screenMenu.item(at: Utility.displayNo)?.state = .on
4040
}
4141

4242
@IBAction func zoom(_ sender: NSMenuItem) {
4343
Utility.scale = Double(sender.tag) / 100
4444
}
4545

4646
@IBAction func top(_ sender: NSMenuItem) {
47-
if sender.state == NSOffState {
47+
if sender.state == .off {
4848
Utility.onTop = true
49-
sender.state = NSOnState
49+
sender.state = .on
5050
} else {
5151
Utility.onTop = false
52-
sender.state = NSOffState
52+
sender.state = .off
5353
}
5454
}
5555

56-
func updateDisplays() {
56+
private func updateDisplays() {
5757
Utility.updateDisplays()
5858
screenMenu.removeAllItems()
5959
let displayNo = Utility.displayNo
6060
for index in Utility.displays.indices {
6161
let item = NSMenuItem(title: "\(index)", action: #selector(AppDelegate.display(_:)), keyEquivalent: "")
6262
item.tag = index
6363
if index == displayNo {
64-
item.state = NSOnState
64+
item.state = .on
6565
}
6666
screenMenu.addItem(item)
6767
}
6868
}
6969

70-
func updateZoom() {
70+
private func updateZoom() {
7171
for item in zoomMenu.items {
72-
item.state = NSOffState
72+
item.state = .off
7373
}
7474
switch Utility.scale {
7575
case 1:
76-
zoomMenu.item(at: 0)!.state = NSOnState
76+
zoomMenu.item(at: 0)!.state = .on
7777
case 0.75:
78-
zoomMenu.item(at: 1)!.state = NSOnState
78+
zoomMenu.item(at: 1)!.state = .on
7979
case 0.5:
80-
zoomMenu.item(at: 2)!.state = NSOnState
80+
zoomMenu.item(at: 2)!.state = .on
8181
case 0.33:
82-
zoomMenu.item(at: 3)!.state = NSOnState
82+
zoomMenu.item(at: 3)!.state = .on
8383
case 0.25:
84-
zoomMenu.item(at: 4)!.state = NSOnState
84+
zoomMenu.item(at: 4)!.state = .on
8585
default: break
8686
}
8787
}

Screen on Screen/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
<key>CFBundlePackageType</key>
1616
<string>APPL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0.2</string>
18+
<string>1.0.3</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>
22-
<string>2</string>
22+
<string>3</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.utilities</string>
2525
<key>LSMinimumSystemVersion</key>

Screen on Screen/Utility.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Utility.swift
33
// ProjectorViewer
44
//
5-
// Created by 张国晔 on 15/6/3.
6-
// Copyright (c) 2015年 Shandong University. All rights reserved.
5+
// Created by Guoye Zhang on 15/6/3.
6+
// Copyright (c) 2015 Guoye Zhang. All rights reserved.
77
//
88

99
import Cocoa
@@ -51,8 +51,7 @@ struct Utility {
5151
}
5252

5353
static func updateDisplays() {
54-
let screens = NSScreen.screens() ?? []
55-
displays = screens.map { ($0.deviceDescription["NSScreenNumber"] as! NSNumber).uint32Value }
54+
displays = NSScreen.screens.flatMap { $0.deviceDescription[NSDeviceDescriptionKey("NSScreenNumber")] as? CGDirectDisplayID }
5655
if displays.count > 1 && displayNo == 0 {
5756
displayNo = 1
5857
} else {

Screen on Screen/ViewController.swift

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// ViewController.swift
33
// ProjectorViewer
44
//
5-
// Created by 张国晔 on 15/6/3.
6-
// Copyright (c) 2015年 Shandong University. All rights reserved.
5+
// Created by Guoye Zhang on 15/6/3.
6+
// Copyright (c) 2015 Guoye Zhang. All rights reserved.
77
//
88

99
import Cocoa
1010
import AVFoundation
1111

1212
class ViewController: NSViewController {
13-
var captureLayer: CALayer? {
13+
private var captureLayer: CALayer? {
1414
didSet {
1515
oldValue?.removeFromSuperlayer()
1616
if let captureLayer = captureLayer {
@@ -19,7 +19,7 @@ class ViewController: NSViewController {
1919
}
2020
}
2121
}
22-
var captureSession: AVCaptureSession? {
22+
private var captureSession: AVCaptureSession? {
2323
didSet {
2424
oldValue?.stopRunning()
2525
if let captureSession = captureSession {
@@ -30,15 +30,12 @@ class ViewController: NSViewController {
3030
}
3131
}
3232
}
33-
var displaySize: NSSize? {
33+
private var displaySize: NSSize? {
3434
didSet {
35-
if let displaySize = displaySize {
36-
preferredContentSize = displaySize
37-
updateSize()
38-
}
35+
updateSize()
3936
}
4037
}
41-
var displayID: CGDirectDisplayID? {
38+
private var displayID: CGDirectDisplayID? {
4239
didSet {
4340
if let displayID = displayID {
4441
let captureSession = AVCaptureSession()
@@ -56,7 +53,7 @@ class ViewController: NSViewController {
5653
override func viewWillAppear() {
5754
super.viewWillAppear()
5855
view.window!.isMovableByWindowBackground = true
59-
view.layer!.backgroundColor = NSColor.black.cgColor
56+
view.layer!.backgroundColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
6057
NotificationCenter.default.addObserver(forName: .displayChange, object: nil, queue: nil) { _ in
6158
if self.displayID != Utility.displayID {
6259
self.displayID = Utility.displayID
@@ -67,10 +64,10 @@ class ViewController: NSViewController {
6764
self.updateSize()
6865
}
6966
if Utility.onTop {
70-
view.window!.level = Int(CGWindowLevelForKey(.floatingWindow))
67+
view.window!.level = .floating
7168
}
7269
NotificationCenter.default.addObserver(forName: .onTopChange, object: nil, queue: nil) { _ in
73-
self.view.window!.level = Int(CGWindowLevelForKey(Utility.onTop ? .floatingWindow : .normalWindow))
70+
self.view.window!.level = Utility.onTop ? .floating : .normal
7471
}
7572
}
7673

@@ -81,14 +78,15 @@ class ViewController: NSViewController {
8178
CATransaction.commit()
8279
}
8380

84-
func updateSize() {
81+
private func updateSize() {
8582
if let displaySize = displaySize {
86-
view.window?.setContentSize(displaySize * CGFloat(Utility.scale))
83+
view.window!.setContentSize(displaySize * CGFloat(Utility.scale))
8784
}
8885
}
8986

9087
@IBAction func scale(_ sender: NSMagnificationGestureRecognizer) {
91-
Utility.scale += Double(sender.magnification) / 50
88+
Utility.scale += Double(sender.magnification) / 5
89+
sender.magnification = 0
9290
}
9391
}
9492

0 commit comments

Comments
 (0)