Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
Adopt Dark Mode on macOS Mojave and upgrade to Swift 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
LumingYin committed Sep 11, 2018
1 parent 884a746 commit cb3b2f7
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 38 deletions.
5 changes: 3 additions & 2 deletions Sticky Notes.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
TargetAttributes = {
3CCEFB75209D37AB00429258 = {
CreatedOnToolsVersion = 9.3;
LastSwiftMigration = 1000;
};
};
};
Expand Down Expand Up @@ -312,7 +313,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.13;
PRODUCT_BUNDLE_IDENTIFIER = "com.kenny.Sticky-Notes";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -331,7 +332,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.13;
PRODUCT_BUNDLE_IDENTIFIER = "com.kenny.Sticky-Notes";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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>SchemeUserState</key>
<dict>
<key>Sticky Notes.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
14 changes: 7 additions & 7 deletions Sticky Notes/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
// Performs the save action for the application, which is to send the save: message to the application's managed object context. Any encountered errors are presented to the user.
let context = persistentContainer.viewContext

if !context.commitEditing() {
NSLog("\(NSStringFromClass(type(of: self))) unable to commit editing before saving")
}
// if !context.commitEditing() {
// NSLog("\(NSStringFromClass(type(of: self))) unable to commit editing before saving")
// }
if context.hasChanges {
do {
try context.save()
Expand Down Expand Up @@ -165,10 +165,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
// Save changes in the application's managed object context before the application terminates.
let context = persistentContainer.viewContext

if !context.commitEditing() {
NSLog("\(NSStringFromClass(type(of: self))) unable to commit editing to terminate")
return .terminateCancel
}
// if !context.commitEditing() {
// NSLog("\(NSStringFromClass(type(of: self))) unable to commit editing to terminate")
// return .terminateCancel
// }

if !context.hasChanges {
return .terminateNow
Expand Down
9 changes: 4 additions & 5 deletions Sticky Notes/DeleteNoteViewController.xib
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14109" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14313.13.2" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14109"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.13.2"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="box content view" minToolsVersion="7.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
<capability name="system font weights other than Regular or Bold" minToolsVersion="7.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="DeleteNoteViewController" customModule="Sticky_Notes" customModuleProvider="target">
Expand Down Expand Up @@ -116,7 +115,7 @@
</constraints>
</view>
<color key="borderColor" name="gray_dark"/>
<color key="fillColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="fillColor" name="windowBackgroundColor" catalog="System" colorSpace="catalog"/>
</box>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="IJF-R7-b8c">
<rect key="frame" x="18" y="126" width="238" height="19"/>
Expand Down
6 changes: 3 additions & 3 deletions Sticky Notes/FlatButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal extension CALayer {
animation.fromValue = value(forKey: keyPath)
animation.duration = duration
animation.isRemovedOnCompletion = false
animation.fillMode = kCAFillModeForwards
animation.fillMode = CAMediaTimingFillMode.forwards
add(animation, forKey: keyPath)
setValue(color, forKey: keyPath)
}
Expand Down Expand Up @@ -194,7 +194,7 @@ open class FlatButton: NSButton, CALayerDelegate {
}

func positionTitleAndImage() {
let attributes = [NSAttributedStringKey.font: font as Any]
let attributes = [NSAttributedString.Key.font: font as Any]
let titleSize = title.size(withAttributes: attributes)
var titleRect = NSMakeRect(0, 0, titleSize.width, titleSize.height)
var imageRect = iconLayer.frame
Expand Down Expand Up @@ -368,7 +368,7 @@ open class FlatButton: NSButton, CALayerDelegate {
}
}

override open func layer(_ layer: CALayer, shouldInheritContentsScale newScale: CGFloat, from window: NSWindow) -> Bool {
open func layer(_ layer: CALayer, shouldInheritContentsScale newScale: CGFloat, from window: NSWindow) -> Bool {
return true
}

Expand Down
24 changes: 12 additions & 12 deletions Sticky Notes/StickyWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class StickyWindowController: NSWindowController {
var currentColorTag = 0
var deleteVC: DeleteNoteViewController?
var sticky: Sticky?
var tick_black = NSImage(named: NSImage.Name(rawValue: "tick_black"))
var tick_black = NSImage(named: "tick_black")

convenience init() {
self.init(windowNibName: NSNib.Name(rawValue: "StickyWindowController"))
self.init(windowNibName: "StickyWindowController")
}

override func windowWillLoad() {
Expand Down Expand Up @@ -107,7 +107,7 @@ class StickyWindowController: NSWindowController {
updateColorAccordingToTag(tag: sender.tag)
NSAnimationContext.beginGrouping()
NSAnimationContext.current.duration = 0.2
NSAnimationContext.current.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionEaseInEaseOut)
NSAnimationContext.current.timingFunction = CAMediaTimingFunction.init(name: CAMediaTimingFunctionName.easeInEaseOut)
NSAnimationContext.current.completionHandler = {
self.colorBoxTopConstraint.constant = -64
}
Expand Down Expand Up @@ -138,27 +138,27 @@ class StickyWindowController: NSWindowController {

func updateColorAccordingToString(colorName: String) {
if colorName == "yellow" || colorName == "gray" {
plusButton.image = NSImage(named: NSImage.Name(rawValue: "add"))
deleteButton.image = NSImage(named: NSImage.Name(rawValue: "delete"))
moreButton.image = NSImage(named: NSImage.Name(rawValue: "more"))
plusButton.image = NSImage(named: "add")
deleteButton.image = NSImage(named: "delete")
moreButton.image = NSImage(named: "more")
} else {
plusButton.image = NSImage(named: NSImage.Name(rawValue: "add_white"))
deleteButton.image = NSImage(named: NSImage.Name(rawValue: "delete_white"))
moreButton.image = NSImage(named: NSImage.Name(rawValue: "more_white"))
plusButton.image = NSImage(named: "add_white")
deleteButton.image = NSImage(named: "delete_white")
moreButton.image = NSImage(named: "more_white")
}
guard let dark = NSColor(named: NSColor.Name(rawValue: "\(colorName)_dark")), let light = NSColor(named: NSColor.Name(rawValue: "\(colorName)_light")), let medium = NSColor(named: NSColor.Name(rawValue: "\(colorName)_medium")) else {
guard let dark = NSColor(named: "\(colorName)_dark"), let light = NSColor(named: "\(colorName)_light"), let medium = NSColor(named: "\(colorName)_medium") else {
return
}
self.titleBarBox.fillColor = dark
self.colorSelectorBox.fillColor = light
self.contentBox.fillColor = medium

self.contentTextView.insertionPointColor = dark
}

@IBAction func moreColorOptions(_ sender: Any) {
NSAnimationContext.beginGrouping()
NSAnimationContext.current.duration = 0.2
NSAnimationContext.current.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionEaseInEaseOut)
NSAnimationContext.current.timingFunction = CAMediaTimingFunction.init(name: CAMediaTimingFunctionName.easeInEaseOut)
NSAnimationContext.current.completionHandler = {
self.colorBoxTopConstraint.constant = 0
}
Expand Down
19 changes: 10 additions & 9 deletions Sticky Notes/StickyWindowController.xib
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14109" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14313.13.2" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14109"/>
<capability name="box content view" minToolsVersion="7.0"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.13.2"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
<capability name="stacking Non-gravity area distributions on NSStackView" minToolsVersion="7.0" minSystemVersion="10.11"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="StickyWindowController" customModule="Sticky_Notes" customModuleProvider="target">
Expand All @@ -25,11 +24,11 @@
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" animationBehavior="default" tabbingMode="disallowed" titlebarAppearsTransparent="YES" titleVisibility="hidden" id="F0z-JX-Cv5">
<window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" tabbingMode="disallowed" titlebarAppearsTransparent="YES" titleVisibility="hidden" id="F0z-JX-Cv5">
<windowStyleMask key="styleMask" titled="YES" resizable="YES" fullSizeContentView="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="310" height="310"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
<rect key="screenRect" x="0.0" y="0.0" width="2048" height="1129"/>
<value key="minSize" type="size" width="310" height="310"/>
<view key="contentView" wantsLayer="YES" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="0.0" width="310" height="310"/>
Expand All @@ -50,27 +49,29 @@
<textView importsGraphics="NO" verticallyResizable="YES" usesFontPanel="YES" findStyle="panel" continuousSpellChecking="YES" allowsUndo="YES" usesRuler="YES" allowsNonContiguousLayout="YES" quoteSubstitution="YES" dashSubstitution="YES" smartInsertDelete="YES" id="ciy-e5-lp4">
<rect key="frame" x="0.0" y="0.0" width="270" height="231"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" white="1" alpha="0.0" colorSpace="calibratedWhite"/>
<size key="minSize" width="270" height="231"/>
<size key="maxSize" width="480" height="10000000"/>
<attributedString key="textStorage">
<fragment content=" ">
<attributes>
<color key="NSColor" name="textColor" catalog="System" colorSpace="catalog"/>
<font key="NSFont" metaFont="systemLight" size="20"/>
<paragraphStyle key="NSParagraphStyle" alignment="natural" lineBreakMode="wordWrapping" baseWritingDirection="natural" tighteningFactorForTruncation="0.0"/>
</attributes>
</fragment>
</attributedString>
<color key="insertionPointColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
<color key="insertionPointColor" name="textColor" catalog="System" colorSpace="catalog"/>
</textView>
</subviews>
<color key="backgroundColor" white="1" alpha="0.0" colorSpace="calibratedWhite"/>
</clipView>
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="YES" id="55K-8d-o9N">
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="YES" id="55K-8d-o9N">
<rect key="frame" x="-100" y="-100" width="87" height="18"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="BUe-SC-0GM">
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="BUe-SC-0GM">
<rect key="frame" x="254" y="0.0" width="16" height="231"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
Expand Down

0 comments on commit cb3b2f7

Please sign in to comment.