Skip to content

Commit

Permalink
Merge branch 'release/1.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
MainasuK committed Oct 22, 2019
2 parents e3e1978 + 6cf6624 commit d666ea6
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 11 deletions.
12 changes: 8 additions & 4 deletions Song Rating.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
DB95216A22CB186F007FCF40 /* WindowManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB95216922CB186F007FCF40 /* WindowManager.swift */; };
DB95216E22CB1CB8007FCF40 /* AboutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB95216D22CB1CB8007FCF40 /* AboutViewController.swift */; };
DB95217222CB3E68007FCF40 /* PreferencesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB95217122CB3E68007FCF40 /* PreferencesViewController.swift */; };
DB9D9AF0235F7974008C53C3 /* DispatchQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB9D9AEF235F7974008C53C3 /* DispatchQueue.swift */; };
FE421476F34E641428B030E9 /* Pods_Song_Rating.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9DFF0EB36C01E667D4778CCC /* Pods_Song_Rating.framework */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -105,6 +106,7 @@
DB95216922CB186F007FCF40 /* WindowManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowManager.swift; sourceTree = "<group>"; };
DB95216D22CB1CB8007FCF40 /* AboutViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutViewController.swift; sourceTree = "<group>"; };
DB95217122CB3E68007FCF40 /* PreferencesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesViewController.swift; sourceTree = "<group>"; };
DB9D9AEF235F7974008C53C3 /* DispatchQueue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DispatchQueue.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -246,6 +248,7 @@
DB89C9FF22E37826003981F5 /* OSVersionHelper.swift */,
DB05F0852354CA5800CE6DF9 /* NSViewPreview.swift */,
DB05F0872354CA6B00CE6DF9 /* NSViewControllerPreview.swift */,
DB9D9AEF235F7974008C53C3 /* DispatchQueue.swift */,
DB33438A235E103200B45ED0 /* ExceptionCatcher.h */,
DB334388235E102600B45ED0 /* ExceptionCatcher.m */,
DB334387235E102500B45ED0 /* Song Rating-Bridging-Header.h */,
Expand Down Expand Up @@ -485,6 +488,7 @@
DB89C9F322E2D766003981F5 /* MenuBarIcon.swift in Sources */,
DB106CA422CA3C7300502D7C /* Star.swift in Sources */,
DB95216E22CB1CB8007FCF40 /* AboutViewController.swift in Sources */,
DB9D9AF0235F7974008C53C3 /* DispatchQueue.swift in Sources */,
DB424A352307259800230C7E /* iTunesTrack.swift in Sources */,
DB106C4622C53D4B00502D7C /* AppDelegate.swift in Sources */,
DB424A3E2308936F00230C7E /* AutoScrollTextField.swift in Sources */,
Expand Down Expand Up @@ -653,15 +657,15 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5;
CURRENT_PROJECT_VERSION = 6;
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.0;
MARKETING_VERSION = 1.2.1;
PRODUCT_BUNDLE_IDENTIFIER = "com.mainasuk.Song-Rating";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -681,15 +685,15 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5;
CURRENT_PROJECT_VERSION = 6;
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.0;
MARKETING_VERSION = 1.2.1;
PRODUCT_BUNDLE_IDENTIFIER = "com.mainasuk.Song-Rating";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
6 changes: 4 additions & 2 deletions Song Rating/Controllers/PlayerPanelViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Cocoa
import os

protocol PlayerPanelViewControllerDelegate: class {
func playerPanelViewController(_ playerPanelViewController: PlayerPanelViewController, menuButtonPressed button: NSButton)
Expand All @@ -25,7 +26,7 @@ final class PlayerPanelViewController: NSViewController {

var isStop = false {
didSet {
stateDidUpdate(.control)
stateDidUpdate(isStop ? .control : .info)
}
}
var state: State = .info {
Expand All @@ -49,7 +50,7 @@ extension PlayerPanelViewController {

override func viewDidLoad() {
super.viewDidLoad()

playerInfoView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(playerInfoView)
NSLayoutConstraint.activate([
Expand Down Expand Up @@ -120,6 +121,7 @@ extension PlayerPanelViewController {
}

func stateDidUpdate(_ state: State) {
os_log("%{public}s[%{public}ld], %{public}s: %{public}s", ((#file as NSString).lastPathComponent), #line, #function, String(describing: state))
playerControlView.backwardButton.isEnabled = !isStop
playerControlView.forwardButton.isEnabled = !isStop

Expand Down
35 changes: 31 additions & 4 deletions Song Rating/Controls/MenuBarRatingControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ final class MenuBarRatingControl {
updateMenuBar()
}
}
private(set) var playState: PlayInfo.PlayerState? {
private(set) var playState: PlayInfo.PlayerState = .unknown {
didSet {
if playState == .unknown {
undetachedPopover?.close()
Expand Down Expand Up @@ -152,10 +152,11 @@ extension MenuBarRatingControl {
let playingWidth = margin + ratingControl.starsImage.size.width
let pauseWidth = margin + CGFloat(2) * ratingControl.spacing + ratingControl.starSize.width

statusItem.length = !isStop ? playingWidth : pauseWidth
statusItem.length = !isStop ? playingWidth : pauseWidth
statusItem.button?.image = !isStop ? ratingControl.starsImage : menuBarIcon.image
statusItem.button?.setButtonType(!isStop ? .momentaryChange : .onOff)
}

}

extension MenuBarRatingControl {
Expand Down Expand Up @@ -238,8 +239,11 @@ extension MenuBarRatingControl {
return
}

DispatchQueue.once(token: "firstDisplay") {
updateMenuBar()
}

os_log("%{public}s[%{public}ld], %{public}s: window size change to %{public}s", ((#file as NSString).lastPathComponent), #line, #function, window.frame.debugDescription)

}

}
Expand Down Expand Up @@ -268,9 +272,32 @@ extension MenuBarRatingControl {
popover.delegate = popoverProxy

// FIXME: should relative to windows
popover.show(relativeTo: button.bounds, of: button, preferredEdge: .minY)
// popover.show(relativeTo: button.bounds, of: button, preferredEdge: .minY)
popover.contentViewController?.view.window?.makeKey()

// Ref: https://stackoverflow.com/questions/48594212/how-to-open-a-nspopover-at-a-distance-from-the-system-bar/48604455#48604455
// TODO: fix windows leaking issue
let invisibleWindow = NSWindow(contentRect: NSMakeRect(0, 0, 20, 5), styleMask: .borderless, backing: .buffered, defer: false)
invisibleWindow.backgroundColor = .red
invisibleWindow.alphaValue = 0

// find the coordinates of the statusBarItem in screen space
let buttonRect:NSRect = button.convert(button.bounds, to: nil)
let screenRect:NSRect = button.window!.convertToScreen(buttonRect)

// calculate the bottom center position (10 is the half of the window width)
let posX = screenRect.origin.x + (screenRect.width / 2) - 10
let posY = screenRect.origin.y

// position and show the window
invisibleWindow.setFrameOrigin(NSPoint(x: posX, y: posY))
invisibleWindow.makeKeyAndOrderFront(self)
invisibleWindow.level = .floating // make popover always on top

// position and show the NSPopover
popover.show(relativeTo: invisibleWindow.contentView!.frame, of: invisibleWindow.contentView!, preferredEdge: NSRectEdge.minY)
popover.contentViewController?.view.window?.makeKey() // fix popover not get focus issue

undetachedPopover = popover
}

Expand Down
33 changes: 33 additions & 0 deletions Song Rating/Helper/DispatchQueue.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// DispatchQueue.swift
// Song Rating
//
// Created by Cirno MainasuK on 2019-10-23.
// Copyright © 2019 Cirno MainasuK. All rights reserved.
//

import Cocoa

public extension DispatchQueue {

private static var _onceTracker = [String]()

/**
Executes a block of code, associated with a unique token, only once. The code is thread safe and will
only execute the code once even in the presence of multithreaded calls.
- parameter token: A unique reverse DNS style name such as com.vectorform.<name> or a GUID
- parameter block: Block to execute once
*/
class func once(token: String, block: () -> Void) {
objc_sync_enter(self); defer { objc_sync_exit(self) }

if _onceTracker.contains(token) {
return
}

_onceTracker.append(token)
block()
}

}
2 changes: 1 addition & 1 deletion Song Rating/Views/PlayerInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ final class PlayerInfoView: NSView {
captionTextField.translatesAutoresizingMaskIntoConstraints = false
groupView.addSubview(captionTextField)
NSLayoutConstraint.activate([
captionTextField.topAnchor.constraint(equalTo: titleTextField.bottomAnchor),
captionTextField.topAnchor.constraint(equalTo: titleTextField.bottomAnchor, constant: 4), // padding
captionTextField.leadingAnchor.constraint(equalTo: groupView.leadingAnchor),
captionTextField.trailingAnchor.constraint(equalTo: groupView.trailingAnchor),
captionTextField.bottomAnchor.constraint(equalTo: groupView.bottomAnchor)
Expand Down
3 changes: 3 additions & 0 deletions Song Rating/iTunes/iTunesRadioStation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ final class iTunesRadioStation {

var iTunes: iTunesApplication? {
let application = SBApplication(bundleIdentifier: OSVersionHelper.bundleIdentifier)
guard application?.isRunning == true else {
return nil
}
application?.delegate = self
return application
}
Expand Down

0 comments on commit d666ea6

Please sign in to comment.