Skip to content

Commit

Permalink
Resized the view, view will also be hidden when paused
Browse files Browse the repository at this point in the history
  • Loading branch information
Exceen committed Nov 25, 2020
1 parent 96fc9ff commit 9166597
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 22 deletions.
9 changes: 8 additions & 1 deletion Rosco.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
20CE9AB81ADFA7DE00258EDA /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0940;
LastUpgradeCheck = 1220;
ORGANIZATIONNAME = "Evan Robertson";
TargetAttributes = {
20CE9ABF1ADFA7DF00258EDA = {
Expand Down Expand Up @@ -325,6 +325,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down Expand Up @@ -380,6 +381,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down Expand Up @@ -410,6 +412,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = Rosco/Rosco.entitlements;
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
ENABLE_HARDENED_RUNTIME = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -431,7 +434,10 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = Rosco/Rosco.entitlements;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -443,6 +449,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.evanrobertson.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0;
};
name = Release;
Expand Down
3 changes: 3 additions & 0 deletions Rosco/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
statusItem.button?.image = NSImage.init(named: NSImage.Name("status_bar_icon"))
statusItem.menu = menu

menu.items[0].isHidden = true
menu.items[1].isHidden = true

// Set the display style from defaults
let appearanceName = UserDefaults.standard.object(forKey: styleKey) as? NSAppearance.Name
setStyleMenuStates(appearanceName: appearanceName)
Expand Down
24 changes: 12 additions & 12 deletions Rosco/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="17506" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<deployment version="101400" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16097.2"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17506"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -100,30 +100,30 @@
<scene sceneID="hIz-AP-VOD">
<objects>
<viewController id="XfG-lQ-9wD" sceneMemberID="viewController">
<visualEffectView key="view" autoresizesSubviews="NO" horizontalHuggingPriority="1000" verticalHuggingPriority="1000" horizontalCompressionResistancePriority="250" blendingMode="behindWindow" material="underWindowBackground" state="active" id="We8-xt-DPe" customClass="RoscoView" customModule="Rosco" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="249" height="22"/>
<visualEffectView key="view" autoresizesSubviews="NO" horizontalHuggingPriority="1000" verticalHuggingPriority="1000" horizontalCompressionResistancePriority="250" misplaced="YES" blendingMode="behindWindow" material="underWindowBackground" state="active" id="We8-xt-DPe" customClass="RoscoView" customModule="Rosco" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="257" height="20"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField horizontalHuggingPriority="1000" verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="Y79-WG-vdU">
<rect key="frame" x="18" y="3" width="75" height="16"/>
<rect key="frame" x="6" y="3" width="64" height="14"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Not Playing" id="JLY-0g-oWe">
<font key="font" size="14" name="SFCompactDisplay-Medium"/>
<font key="font" metaFont="system" size="11"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="1000" verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="Yqo-zH-NzW">
<rect key="frame" x="94" y="3" width="72" height="16"/>
<textField wantsLayer="YES" horizontalHuggingPriority="1000" verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="Yqo-zH-NzW">
<rect key="frame" x="71" y="3" width="67" height="14"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Artist Name" id="bTm-NM-DLZ">
<font key="font" size="14" name="SFProDisplay-Light"/>
<font key="font" metaFont="system" size="11"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="Yqo-zH-NzW" secondAttribute="trailing" constant="85" id="6Ul-OK-po4"/>
<constraint firstItem="Y79-WG-vdU" firstAttribute="leading" secondItem="We8-xt-DPe" secondAttribute="leading" constant="20" id="E8w-s4-KGY"/>
<constraint firstItem="Y79-WG-vdU" firstAttribute="leading" secondItem="We8-xt-DPe" secondAttribute="leading" constant="8" id="E8w-s4-KGY"/>
<constraint firstItem="Yqo-zH-NzW" firstAttribute="top" secondItem="We8-xt-DPe" secondAttribute="top" constant="3" id="TWo-8T-zu2"/>
<constraint firstItem="Y79-WG-vdU" firstAttribute="top" secondItem="We8-xt-DPe" secondAttribute="top" constant="3" id="hQv-AR-NoS"/>
<constraint firstAttribute="bottom" secondItem="Y79-WG-vdU" secondAttribute="bottom" constant="3" id="k4M-9i-tti"/>
Expand All @@ -138,10 +138,10 @@
</viewController>
<customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="29" y="653.5"/>
<point key="canvasLocation" x="28.5" y="653"/>
</scene>
</scenes>
<resources>
<image name="NSMenuOnStateTemplate" width="12" height="12"/>
<image name="NSMenuOnStateTemplate" width="14" height="13"/>
</resources>
</document>
6 changes: 4 additions & 2 deletions Rosco/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LSUIElement</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand All @@ -24,8 +22,12 @@
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.music</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015 Evan Robertson. All rights reserved.</string>
<key>NSMainStoryboardFile</key>
Expand Down
19 changes: 15 additions & 4 deletions Rosco/NowPlayingService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class NowPlayingService {

var MRMediaRemoteGetNowPlayingInfo : MRMediaRemoteGetNowPlayingInfoFunction?
var lastTrack: Track?

var isPlaying: Bool = false

init () {
// Load framework
let bundle = CFBundleCreate(kCFAllocatorDefault, NSURL(fileURLWithPath: "/System/Library/PrivateFrameworks/MediaRemote.framework"))
Expand Down Expand Up @@ -42,6 +43,8 @@ class NowPlayingService {
NotificationCenter.default.addObserver(self, selector: #selector(infoChanged(_:)), name: Notification.Name("kMRMediaRemoteNowPlayingApplicationClientStateDidChange"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(infoChanged(_:)), name: Notification.Name("kMRNowPlayingPlaybackQueueChangedNotification"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(infoChanged(_:)), name: Notification.Name("kMRPlaybackQueueContentItemsChangedNotification"), object: nil)

NotificationCenter.default.addObserver(self, selector: #selector(infoChanged(_:)), name: Notification.Name("kMRMediaRemoteNowPlayingApplicationIsPlayingDidChangeNotification"), object: nil)
}

func updateInfo() {
Expand All @@ -50,9 +53,13 @@ class NowPlayingService {
}

MRMediaRemoteGetNowPlayingInfo(DispatchQueue.main, { (information) in
if let artist = information["kMRMediaRemoteNowPlayingInfoArtist"] as? String,
let title = information["kMRMediaRemoteNowPlayingInfoTitle"] as? String {
self.sendUpdateTrackNotification(track: Track(name: title, artist: artist))
if (self.isPlaying) {
if let artist = information["kMRMediaRemoteNowPlayingInfoArtist"] as? String,
let title = information["kMRMediaRemoteNowPlayingInfoTitle"] as? String {
self.sendUpdateTrackNotification(track: Track(name: title, artist: artist))
} else {
self.sendNotPlayingNotification()
}
} else {
self.sendNotPlayingNotification()
}
Expand All @@ -72,6 +79,10 @@ class NowPlayingService {
}

@objc func infoChanged(_ notification: Notification) {
// https://github.com/dimitarnestorov/MusicBar/blob/master/macos/GlobalState.m
if let state = notification.userInfo?["kMRMediaRemoteNowPlayingApplicationIsPlayingUserInfoKey"] as? Bool {
self.isPlaying = state
}
updateInfo()
}
}
9 changes: 8 additions & 1 deletion Rosco/RoscoPanelController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ class RoscoPanelController : NSWindowController {
override func windowDidLoad() {
if let window = window as? NSPanel {
window.collectionBehavior = .canJoinAllSpaces
window.isFloatingPanel = true
window.setFrameOrigin(NSPoint(x: 0, y: 0))
window.backgroundColor = NSColor.clear

// window.backgroundColor = NSColor.black
// window.backgroundColor = NSColor.black.withAlphaComponent(0.5)

window.isFloatingPanel = true
window.level = NSWindow.Level(rawValue: NSWindow.Level.normal.rawValue - 1)
window.orderFront(nil)
window.ignoresMouseEvents = true
}
}
}
13 changes: 11 additions & 2 deletions Rosco/RoscoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ class RoscoView : NSVisualEffectView {
required init?(coder: NSCoder) {
super.init(coder: coder)

isHidden = true
window?.backgroundColor = NSColor.clear;

NotificationCenter.default.addObserver(self, selector: #selector(didUpdateTrack(_:)), name: Notification.Name("RoscoUpdateTrack"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(notPlayingNotificationReceived(_:)), name: Notification.Name("RoscoNotPlaying"), object: nil)

maskImage = NSImage(size: NSSize(width: 100, height: 22), flipped: false) { rect in
maskImage = NSImage(size: NSSize(width: 100, height: 20), flipped: false) { rect in

let bezierPath = NSBezierPath()
bezierPath.move(to: NSPoint(x: 0, y: 22))
Expand Down Expand Up @@ -60,11 +63,17 @@ class RoscoView : NSVisualEffectView {
return
}

isHidden = false
window?.backgroundColor = NSColor.black

titleLabel.stringValue = track.name.truncate(length: 32, trailing: "")
artistNameLabel.stringValue = track.artist.truncate(length: 32, trailing: "")
}

@objc func notPlayingNotificationReceived(_ notification: NSNotification) {
notPlaying()
// notPlaying()

isHidden = true
window?.backgroundColor = NSColor.clear
}
}

0 comments on commit 9166597

Please sign in to comment.