Skip to content

Commit

Permalink
Merge branch 'release/1.2.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
MainasuK committed Sep 13, 2020
2 parents 0eac1b4 + 625d7e8 commit 7514d17
Show file tree
Hide file tree
Showing 11 changed files with 339 additions and 86 deletions.
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 10e6f5005867dbb3964c6d40690aff5abd64540b

COCOAPODS: 1.9.1
COCOAPODS: 1.9.3
16 changes: 12 additions & 4 deletions Song Rating.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
DB9D9B6B2363FF45008C53C3 /* NotificationName.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB9D9B6A2363FF45008C53C3 /* NotificationName.swift */; };
DB9D9B6C2363FF45008C53C3 /* NotificationName.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB9D9B6A2363FF45008C53C3 /* NotificationName.swift */; };
DB9D9B6F2364288E008C53C3 /* UserDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB9D9B6E2364288E008C53C3 /* UserDefaults.swift */; };
DBD6A936250DA48E002C1B6C /* NSBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBD6A935250DA48E002C1B6C /* NSBox.swift */; };
DBD6A938250E0A1C002C1B6C /* NSImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBD6A937250E0A1C002C1B6C /* NSImage.swift */; };
FE421476F34E641428B030E9 /* Pods_Song_Rating.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9DFF0EB36C01E667D4778CCC /* Pods_Song_Rating.framework */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -136,6 +138,8 @@
DB9D9B682363FD2E008C53C3 /* ServiceManagement.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ServiceManagement.framework; path = System/Library/Frameworks/ServiceManagement.framework; sourceTree = SDKROOT; };
DB9D9B6A2363FF45008C53C3 /* NotificationName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationName.swift; sourceTree = "<group>"; };
DB9D9B6E2364288E008C53C3 /* UserDefaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaults.swift; sourceTree = "<group>"; };
DBD6A935250DA48E002C1B6C /* NSBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSBox.swift; sourceTree = "<group>"; };
DBD6A937250E0A1C002C1B6C /* NSImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSImage.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -346,6 +350,8 @@
children = (
DB9D9AEF235F7974008C53C3 /* DispatchQueue.swift */,
DB9D9B6E2364288E008C53C3 /* UserDefaults.swift */,
DBD6A935250DA48E002C1B6C /* NSBox.swift */,
DBD6A937250E0A1C002C1B6C /* NSImage.swift */,
);
path = Extension;
sourceTree = "<group>";
Expand Down Expand Up @@ -569,10 +575,12 @@
DB89CA0022E37826003981F5 /* OSVersionHelper.swift in Sources */,
DB424A45230D877900230C7E /* PlayerHistoryViewController.swift in Sources */,
DB106CA622CA3EE700502D7C /* Stars.swift in Sources */,
DBD6A938250E0A1C002C1B6C /* NSImage.swift in Sources */,
DB2797732306F0EC00DDE3EB /* iTunesApplication.swift in Sources */,
DB05F08A2354FC7700CE6DF9 /* PlayerControlView.swift in Sources */,
DB424A3C230877F400230C7E /* PlayerViewController.swift in Sources */,
DB95216A22CB186F007FCF40 /* WindowManager.swift in Sources */,
DBD6A936250DA48E002C1B6C /* NSBox.swift in Sources */,
DB05F0652353912500CE6DF9 /* PlayerInfoView.swift in Sources */,
DB9D9B6B2363FF45008C53C3 /* NotificationName.swift in Sources */,
DB95217222CB3E68007FCF40 /* PreferencesViewController.swift in Sources */,
Expand Down Expand Up @@ -768,15 +776,15 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = A8K92XFF77;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "Song Rating/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.2.4;
MARKETING_VERSION = 1.2.5;
PRODUCT_BUNDLE_IDENTIFIER = "com.mainasuk.Song-Rating";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -796,15 +804,15 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = A8K92XFF77;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "Song Rating/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.2.4;
MARKETING_VERSION = 1.2.5;
PRODUCT_BUNDLE_IDENTIFIER = "com.mainasuk.Song-Rating";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1150"
LastUpgradeVersion = "1170"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1150"
LastUpgradeVersion = "1170"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
20 changes: 20 additions & 0 deletions Song Rating/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,33 @@ extension AppDelegate {
let ratingDownShortcut = MASShortcut(keyCode: kVK_ANSI_Comma, modifierFlags: .option)
let ratingUpShortcut = MASShortcut(keyCode: kVK_ANSI_Period, modifierFlags: .option)
let showOrClosePopoverShortcut = MASShortcut(keyCode: kVK_ANSI_Slash, modifierFlags: .option)
let songRating5Shortcut = MASShortcut(keyCode: kVK_ANSI_5, modifierFlags: .option)
let songRating4Shortcut = MASShortcut(keyCode: kVK_ANSI_4, modifierFlags: .option)
let songRating3Shortcut = MASShortcut(keyCode: kVK_ANSI_3, modifierFlags: .option)
let songRating2Shortcut = MASShortcut(keyCode: kVK_ANSI_2, modifierFlags: .option)
let songRating1Shortcut = MASShortcut(keyCode: kVK_ANSI_1, modifierFlags: .option)
let songRating0Shortcut = MASShortcut(keyCode: kVK_ANSI_Grave, modifierFlags: .option)

let ratingDownShortcutData = try NSKeyedArchiver.archivedData(withRootObject: ratingDownShortcut as Any, requiringSecureCoding: false)
let ratingUpShortcutData = try NSKeyedArchiver.archivedData(withRootObject: ratingUpShortcut as Any, requiringSecureCoding: false)
let showOrClosePopoverShortcutData = try NSKeyedArchiver.archivedData(withRootObject: showOrClosePopoverShortcut as Any, requiringSecureCoding: false)
let songRating5ShortcutData = try NSKeyedArchiver.archivedData(withRootObject: songRating5Shortcut as Any, requiringSecureCoding: false)
let songRating4ShortcutData = try NSKeyedArchiver.archivedData(withRootObject: songRating4Shortcut as Any, requiringSecureCoding: false)
let songRating3ShortcutData = try NSKeyedArchiver.archivedData(withRootObject: songRating3Shortcut as Any, requiringSecureCoding: false)
let songRating2ShortcutData = try NSKeyedArchiver.archivedData(withRootObject: songRating2Shortcut as Any, requiringSecureCoding: false)
let songRating1ShortcutData = try NSKeyedArchiver.archivedData(withRootObject: songRating1Shortcut as Any, requiringSecureCoding: false)
let songRating0ShortcutData = try NSKeyedArchiver.archivedData(withRootObject: songRating0Shortcut as Any, requiringSecureCoding: false)

UserDefaults.standard.register(defaults: [
PreferencesViewController.ShortcutKey.songRatingDown.rawValue : ratingDownShortcutData,
PreferencesViewController.ShortcutKey.songRatingUp.rawValue : ratingUpShortcutData,
PreferencesViewController.ShortcutKey.showOrClosePopover.rawValue : showOrClosePopoverShortcutData,
PreferencesViewController.ShortcutKey.songRating5.rawValue: songRating5ShortcutData,
PreferencesViewController.ShortcutKey.songRating4.rawValue: songRating4ShortcutData,
PreferencesViewController.ShortcutKey.songRating3.rawValue: songRating3ShortcutData,
PreferencesViewController.ShortcutKey.songRating2.rawValue: songRating2ShortcutData,
PreferencesViewController.ShortcutKey.songRating1.rawValue: songRating1ShortcutData,
PreferencesViewController.ShortcutKey.songRating0.rawValue: songRating0ShortcutData,
])
} catch {
os_log("%{public}s[%{public}ld], %{public}s: Default shortcut set fail", ((#file as NSString).lastPathComponent), #line, #function)
Expand Down
147 changes: 128 additions & 19 deletions Song Rating/Controllers/PreferencesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import MASShortcut

final class PreferencesViewController: NSViewController {

static var defaultTextFieldFontSize: CGFloat {
return NSTextField(labelWithString: "sample").font!.pointSize
}

lazy var StartupTextField: NSTextField = {
return NSTextField(labelWithString: "Startup: ")
}()
Expand All @@ -20,6 +24,34 @@ final class PreferencesViewController: NSViewController {
lazy var songRatingUpTextField: NSTextField = {
return NSTextField(labelWithString: "Song rating up: ")
}()
lazy var songRating5TextField: NSTextField = {
let attributedString = PreferencesViewController.starsAttributedString(count: 5, fontSize: PreferencesViewController.defaultTextFieldFontSize)
attributedString.append(NSAttributedString(string: ": "))
return NSTextField(labelWithAttributedString: attributedString)
}()
lazy var songRating4TextField: NSTextField = {
let attributedString = PreferencesViewController.starsAttributedString(count: 4, fontSize: PreferencesViewController.defaultTextFieldFontSize)
attributedString.append(NSAttributedString(string: ": "))
return NSTextField(labelWithAttributedString: attributedString)
}()
lazy var songRating3TextField: NSTextField = {
let attributedString = PreferencesViewController.starsAttributedString(count: 3, fontSize: PreferencesViewController.defaultTextFieldFontSize)
attributedString.append(NSAttributedString(string: ": "))
return NSTextField(labelWithAttributedString: attributedString)
}()
lazy var songRating2TextField: NSTextField = {
let attributedString = PreferencesViewController.starsAttributedString(count: 2, fontSize: PreferencesViewController.defaultTextFieldFontSize)
attributedString.append(NSAttributedString(string: ": "))
return NSTextField(labelWithAttributedString: attributedString)
}()
lazy var songRating1TextField: NSTextField = {
let attributedString = PreferencesViewController.starsAttributedString(count: 1, fontSize: PreferencesViewController.defaultTextFieldFontSize)
attributedString.append(NSAttributedString(string: ": "))
return NSTextField(labelWithAttributedString: attributedString)
}()
lazy var songRating0TextField: NSTextField = {
return NSTextField(labelWithString: "Remove stars: ")
}()
lazy var showOrClosePopoverTextField: NSTextField = {
return NSTextField(labelWithString: "Show/Close popover: ")
}()
Expand All @@ -37,6 +69,36 @@ final class PreferencesViewController: NSViewController {
shortcutView.associatedUserDefaultsKey = ShortcutKey.songRatingUp.rawValue
return shortcutView
}()
let songRating5ShortcutView: MASShortcutView = {
let shortcutView = MASShortcutView()
shortcutView.associatedUserDefaultsKey = ShortcutKey.songRating5.rawValue
return shortcutView
}()
let songRating4ShortcutView: MASShortcutView = {
let shortcutView = MASShortcutView()
shortcutView.associatedUserDefaultsKey = ShortcutKey.songRating4.rawValue
return shortcutView
}()
let songRating3ShortcutView: MASShortcutView = {
let shortcutView = MASShortcutView()
shortcutView.associatedUserDefaultsKey = ShortcutKey.songRating3.rawValue
return shortcutView
}()
let songRating2ShortcutView: MASShortcutView = {
let shortcutView = MASShortcutView()
shortcutView.associatedUserDefaultsKey = ShortcutKey.songRating2.rawValue
return shortcutView
}()
let songRating1ShortcutView: MASShortcutView = {
let shortcutView = MASShortcutView()
shortcutView.associatedUserDefaultsKey = ShortcutKey.songRating1.rawValue
return shortcutView
}()
let songRating0ShortcutView: MASShortcutView = {
let shortcutView = MASShortcutView()
shortcutView.associatedUserDefaultsKey = ShortcutKey.songRating0.rawValue
return shortcutView
}()
let showOrClosePopoverShortcutView: MASShortcutView = {
let shortcutView = MASShortcutView()
shortcutView.associatedUserDefaultsKey = ShortcutKey.showOrClosePopover.rawValue
Expand All @@ -49,54 +111,95 @@ final class PreferencesViewController: NSViewController {

lazy var gridView: NSGridView = {
let empty = NSGridCell.emptyContentView
let line = NSBox()
line.boxType = .separator

let gridView = NSGridView(views: [
[StartupTextField, launchAtLoginCheckboxButton],
[line],
[NSBox.separatorLine],
[songRatingDownTextField, songRatingDownShortcutView],
[songRatingUpTextField, songRatingUpShortcutView],
[showOrClosePopoverTextField, showOrClosePopoverShortcutView],
[NSBox.separatorLine],
[songRating0TextField, songRating0ShortcutView],
[songRating1TextField, songRating1ShortcutView],
[songRating2TextField, songRating2ShortcutView],
[songRating3TextField, songRating3ShortcutView],
[songRating4TextField, songRating4ShortcutView],
[songRating5TextField, songRating5ShortcutView],
[leadingPaddingView, trailingPaddingView]
])

gridView.row(at: 0).rowAlignment = .lastBaseline

gridView.column(at: 0).xPlacement = .trailing
gridView.column(at: 1).xPlacement = .leading
gridView.rowSpacing = 8

let lineRow = gridView.cell(for: line)?.row
lineRow?.mergeCells(in: NSMakeRange(0, 2))
lineRow?.topPadding = 8
lineRow?.bottomPadding = 8
let lines = gridView.subviews.filter { ($0 as? NSBox)?.boxType == .separator }
for line in lines {
guard let lineRow = gridView.cell(for: line)?.row else {
continue
}
lineRow.mergeCells(in: NSMakeRange(0, 2))
lineRow.topPadding = 8
lineRow.bottomPadding = 8
}

return gridView
}()

var launchAtLoginObservation: NSKeyValueObservation?

override func loadView() {
self.view = NSView()
}

deinit {
launchAtLoginObservation?.invalidate()
}

}

extension PreferencesViewController {

private static func starsAttributedString(count: Int, fontSize: CGFloat) -> NSMutableAttributedString {
let font = NSFont.systemFont(ofSize: fontSize)
let stars = Stars(
stars: Array(repeating: Star(size: CGSize(width: fontSize, height: fontSize), fill: true), count: count),
spacing: 3
)
var image = stars.image
image.isTemplate = true
image = image.withTintColor(.labelColor)

let attachment = NSTextAttachment()
attachment.image = image
// center vertical image
attachment.bounds = CGRect(
x: 0,
y: (font.capHeight - image.size.height) * 0.5,
width: image.size.width,
height: image.size.height
)

let attributedString = NSMutableAttributedString()
let attachmentAttributedString = NSAttributedString(attachment: attachment)
attributedString.append(attachmentAttributedString)
// not works. use tinted image workaround it
attributedString.addAttribute(.foregroundColor, value: NSColor.labelColor, range: NSRange(location: 0, length: attributedString.length))

return attributedString
}
}

extension PreferencesViewController {

@objc private func launchAtLoginCheckboxButtonChanged(_ sender: NSButton) {
UserDefaults.standard.launchAtLogin = sender.state == .on
}

}

extension PreferencesViewController {

func setupWindow() {
view.window?.styleMask.remove(.resizable)
}
Expand All @@ -120,14 +223,14 @@ extension PreferencesViewController {
leadingPaddingView.widthAnchor.constraint(equalTo: trailingPaddingView.widthAnchor, multiplier: 1.0),
gridView.widthAnchor.constraint(greaterThanOrEqualToConstant: 420), // magic width
])

launchAtLoginCheckboxButton.target = self
launchAtLoginCheckboxButton.action = #selector(PreferencesViewController.launchAtLoginCheckboxButtonChanged(_:))
launchAtLoginObservation = UserDefaults.standard.observe(\.launchAtLogin, options: [.initial, .new]) { [weak self] defaults, launchAtLogin in
self?.launchAtLoginCheckboxButton.state = defaults.launchAtLogin ? .on : .off
}
}

override func viewDidAppear() {
setupWindow()
}
Expand All @@ -140,22 +243,28 @@ extension PreferencesViewController {
case songRatingDown
case songRatingUp
case showOrClosePopover
case songRating5
case songRating4
case songRating3
case songRating2
case songRating1
case songRating0
}

}

#if canImport(SwiftUI) && DEBUG
import SwiftUI

@available(macOS 10.15.0, *)
struct PreferencesViewController_Preview: PreviewProvider {

static var previews: some View {
NSViewControllerPreview {
return PreferencesViewController()
}
}

}

#endif
Loading

0 comments on commit 7514d17

Please sign in to comment.