Browse Source

Floating window support

pull/101/head
Abhishek 3 years ago
parent
commit
fdd1a62fa9
  1. 105
      Clocker/Panel/ParentPanelController.swift
  2. 119
      Clocker/Panel/UI/FloatingWindow.xib

105
Clocker/Panel/ParentPanelController.swift

@ -55,20 +55,12 @@ class ParentPanelController: NSWindowController {
@IBOutlet var scrollViewHeight: NSLayoutConstraint!
@IBOutlet var calendarColorView: NSView!
@IBOutlet var futureSliderView: NSView!
@IBOutlet var upcomingEventView: NSView?
@IBOutlet var reviewView: NSView!
@IBOutlet var leftField: NSTextField!
@IBOutlet var nextEventLabel: NSTextField!
@IBOutlet var whiteRemoveButton: NSButton!
@IBOutlet var sharingButton: NSButton!
@IBOutlet var leftButton: NSButton!
@ -81,8 +73,6 @@ class ParentPanelController: NSWindowController {
@IBOutlet var pinButton: NSButton!
@IBOutlet var calendarButton: NSButton!
@IBOutlet var sliderDatePicker: NSDatePicker!
@IBOutlet var roundedDateView: NSView!
@ -170,7 +160,7 @@ class ParentPanelController: NSWindowController {
pinButton.image = sharedThemer.pinImage()
sharingButton.image = sharedThemer.sharingImage()
if let upcomingView = upcomingEventView {
if let upcomingView = upcomingEventContainerView {
upcomingView.setAccessibility("UpcomingEventView")
}
@ -287,9 +277,9 @@ class ParentPanelController: NSWindowController {
let showUpcomingEventView = DataStore.shared().shouldDisplay(ViewType.upcomingEventView)
if showUpcomingEventView == false {
upcomingEventView?.isHidden = true
upcomingEventContainerView?.isHidden = true
} else {
upcomingEventView?.isHidden = false
upcomingEventContainerView?.isHidden = false
setupUpcomingEventView()
eventStoreChangedNotification = NotificationCenter.default.addObserver(forName: NSNotification.Name.EKEventStoreChanged, object: self, queue: OperationQueue.main) { _ in
self.fetchCalendarEvents()
@ -320,13 +310,7 @@ class ParentPanelController: NSWindowController {
if eventCenter.calendarAccessGranted() {
// Nice. Events will be retrieved when we open the panel
} else if eventCenter.calendarAccessNotDetermined() {
if nextEventLabel != nil {
nextEventLabel.stringValue = NSLocalizedString("See your next Calendar event here.",
comment: "Next Event Label for no Calendar access")
setCalendarButtonTitle(buttonTitle: NSLocalizedString("Click here to start.",
comment: "Button Title for no Calendar access"))
calendarColorView.layer?.backgroundColor = NSColor(red: 97 / 255.0, green: 194 / 255.0, blue: 80 / 255.0, alpha: 1.0).cgColor
}
upcomingEventCollectionView.reloadData()
} else {
removeUpcomingEventView()
}
@ -359,8 +343,8 @@ class ParentPanelController: NSWindowController {
@objc func themeChanged() {
let sharedThemer = Themer.shared()
if upcomingEventView?.isHidden == false {
upcomingEventView?.layer?.backgroundColor = NSColor.clear.cgColor
if upcomingEventContainerView?.isHidden == false {
upcomingEventContainerView?.layer?.backgroundColor = NSColor.clear.cgColor
}
shutdownButton.image = sharedThemer.shutdownImage()
@ -382,20 +366,6 @@ class ParentPanelController: NSWindowController {
morePopover = NSPopover()
}
private func setCalendarButtonTitle(buttonTitle: String) {
let style = NSMutableParagraphStyle()
style.alignment = .left
style.lineBreakMode = .byTruncatingTail
if let boldFont = NSFont(name: "Avenir", size: 12) {
let attributes = [NSAttributedString.Key.foregroundColor: NSColor.lightGray, NSAttributedString.Key.paragraphStyle: style, NSAttributedString.Key.font: boldFont]
let attributedString = NSAttributedString(string: buttonTitle, attributes: attributes)
calendarButton.attributedTitle = attributedString
calendarButton.toolTip = attributedString.string
}
}
func screenHeight() -> CGFloat {
guard let main = NSScreen.main else { return 100 }
@ -737,10 +707,6 @@ class ParentPanelController: NSWindowController {
UserDefaults.standard.set("NO", forKey: CLShowUpcomingEventView)
Logger.log(object: ["Removed": "YES"], for: "Removed Upcoming Event View")
}
} else if self.stackView.arrangedSubviews.contains(self.upcomingEventView!), self.upcomingEventView?.isHidden == false {
self.upcomingEventView?.isHidden = true
UserDefaults.standard.set("NO", forKey: CLShowUpcomingEventView)
Logger.log(object: ["Removed": "YES"], for: "Removed Upcoming Event View")
}
}
}
@ -818,8 +784,8 @@ class ParentPanelController: NSWindowController {
func showUpcomingEventView() {
OperationQueue.main.addOperation {
if let upcomingView = self.upcomingEventView, upcomingView.isHidden {
self.upcomingEventView?.isHidden = false
if let upcomingView = self.upcomingEventContainerView, upcomingView.isHidden {
self.upcomingEventContainerView?.isHidden = false
UserDefaults.standard.set("YES", forKey: CLShowUpcomingEventView)
Logger.log(object: ["Shown": "YES"], for: "Added Upcoming Event View")
self.themeChanged()
@ -844,32 +810,6 @@ class ParentPanelController: NSWindowController {
return
}
guard let upcomingEvent = eventCenter.nextOccuring(events) else {
self.setPlaceholdersForUpcomingCalendarView()
if #available(OSX 10.14, *) {
PerfLogger.endMarker("Fetch Calendar Events")
}
return
}
self.calendarColorView.layer?.backgroundColor = upcomingEvent.event.calendar.color.cgColor
self.nextEventLabel.stringValue = upcomingEvent.event.title
self.nextEventLabel.toolTip = upcomingEvent.event.title
if upcomingEvent.isAllDay == true {
let title = events.count == 1 ? "All-Day" : "All Day - Total \(events.count) events today"
self.setCalendarButtonTitle(buttonTitle: title)
if #available(OSX 10.14, *) {
PerfLogger.endMarker("Fetch Calendar Events")
}
return
}
self.setCalendarButtonTitle(buttonTitle: upcomingEvent.metadataForMeeting())
if upcomingEvent.meetingURL != nil {
self.whiteRemoveButton.image = Themer.shared().videoCallImage()
}
if #available(OSX 10.14, *) {
PerfLogger.endMarker("Fetch Calendar Events")
}
@ -880,41 +820,12 @@ class ParentPanelController: NSWindowController {
upcomingEventCollectionView.reloadData()
return
}
setPlaceholdersForUpcomingCalendarView()
if #available(OSX 10.14, *) {
PerfLogger.endMarker("Fetch Calendar Events")
}
}
}
private func setPlaceholdersForUpcomingCalendarView() {
let eventCenter = EventCenter.sharedCenter()
var tomorrow = DateComponents()
tomorrow.day = 1
guard let tomorrowDate = Calendar.autoupdatingCurrent.date(byAdding: tomorrow, to: Date()) else {
setCalendarButtonTitle(buttonTitle: "You have no events scheduled for tomorrow.")
return
}
nextEventLabel.stringValue = NSLocalizedString("No upcoming event.",
comment: "Title when there's no upcoming event")
calendarColorView.layer?.backgroundColor = NSColor(red: 97 / 255.0, green: 194 / 255.0, blue: 80 / 255.0, alpha: 1.0).cgColor
let events = eventCenter.filteredEvents[NSCalendar.autoupdatingCurrent.startOfDay(for: tomorrowDate)]
if let count = events?.count, count > 1 {
let suffix = "events coming up tomorrow."
setCalendarButtonTitle(buttonTitle: "\(count) \(suffix)")
} else if let first = events?.first?.event.title {
setCalendarButtonTitle(buttonTitle: "\(first) coming up.")
} else {
setCalendarButtonTitle(buttonTitle: NSLocalizedString("You have no events scheduled for tomorrow.",
comment: "Title when there's no event scheduled for tomorrow"))
}
}
// If the popover is displayed, close it
// Called when preferences are going to be displayed!
func updatePopoverDisplayState() {

119
Clocker/Panel/UI/FloatingWindow.xib

@ -3,19 +3,17 @@
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="18122"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="FloatingWindowController" customModule="Clocker" customModuleProvider="target">
<connections>
<outlet property="calendarButton" destination="8q4-YZ-gkb" id="jJa-d9-fdQ"/>
<outlet property="calendarColorView" destination="BU6-aE-Les" id="NRS-pe-Oxq"/>
<outlet property="futureSlider" destination="XQc-HF-TrM" id="r17-F5-qEj"/>
<outlet property="futureSliderView" destination="6vv-g2-Z63" id="7ld-Or-ilq"/>
<outlet property="leftButton" destination="7ID-ll-0YN" id="Msx-3N-nDQ"/>
<outlet property="leftField" destination="DHg-ca-UOi" id="eOW-Ml-DE8"/>
<outlet property="mainTableView" destination="3js-Fl-DdU" id="6Lu-oW-cuZ"/>
<outlet property="nextEventLabel" destination="A9a-aM-BNn" id="d2X-dP-Xbi"/>
<outlet property="pinButton" destination="KWj-8n-2K0" id="FUW-0f-glB"/>
<outlet property="preferencesButton" destination="iFk-kj-d5a" id="1bK-Ld-MwV"/>
<outlet property="reviewView" destination="HBv-Eh-z9y" id="vt7-in-yQF"/>
@ -26,8 +24,8 @@
<outlet property="shutdownButton" destination="M9q-iF-MaE" id="43B-sx-8Oh"/>
<outlet property="sliderDatePicker" destination="Ngk-LZ-J2y" id="kfm-g4-diy"/>
<outlet property="stackView" destination="Bn4-fy-Lm6" id="bdu-HH-FT3"/>
<outlet property="upcomingEventView" destination="Z63-pM-8OA" id="8mP-u3-cFx"/>
<outlet property="whiteRemoveButton" destination="0xk-Sz-MQU" id="NVY-9C-W2H"/>
<outlet property="upcomingEventCollectionView" destination="1tF-ue-rfI" id="nkq-Ov-eUj"/>
<outlet property="upcomingEventContainerView" destination="7cF-j3-JRf" id="9M5-NS-aB6"/>
<outlet property="window" destination="1gY-Kq-Pzj" id="aEC-1h-f24"/>
</connections>
</customObject>
@ -38,7 +36,7 @@
<windowCollectionBehavior key="collectionBehavior" moveToActiveSpace="YES" ignoresCycle="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="1000" y="379" width="350" height="460"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1415"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1025"/>
<value key="minSize" type="size" width="150" height="50"/>
<value key="maxSize" type="size" width="350" height="800"/>
<view key="contentView" misplaced="YES" id="qEx-SC-5Qd">
@ -362,78 +360,43 @@
</constraints>
<accessibility description="Review Cell"/>
</customView>
<customView wantsLayer="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Z63-pM-8OA" customClass="UpcomingEventView" customModule="Clocker" customModuleProvider="target">
<rect key="frame" x="0.0" y="40" width="379" height="75"/>
<customView wantsLayer="YES" focusRingType="none" translatesAutoresizingMaskIntoConstraints="NO" id="7cF-j3-JRf" userLabel="Upcoming Event View" customClass="UpcomingEventView" customModule="Clocker" customModuleProvider="target">
<rect key="frame" x="0.0" y="40" width="370" height="75"/>
<subviews>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="PpA-GH-1PV" customClass="ClockerTextBackgroundView" customModule="Clocker" customModuleProvider="target">
<rect key="frame" x="10" y="10" width="359" height="55"/>
<subviews>
<button focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="8q4-YZ-gkb">
<rect key="frame" x="21" y="11" width="298" height="18"/>
<constraints>
<constraint firstAttribute="height" constant="18" id="IIB-zJ-L1u"/>
</constraints>
<buttonCell key="cell" type="bevel" title="All Day Event" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingHead" truncatesLastVisibleLine="YES" state="on" focusRingType="none" imageScaling="proportionallyDown" inset="2" id="URj-5B-okQ">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" size="12" name="Avenir-Heavy"/>
</buttonCell>
<connections>
<action selector="calendarButtonAction:" target="-2" id="9kM-QX-h4O"/>
</connections>
</button>
<customView wantsLayer="YES" focusRingType="none" translatesAutoresizingMaskIntoConstraints="NO" id="BU6-aE-Les">
<rect key="frame" x="10" y="11" width="3" height="34"/>
<constraints>
<constraint firstAttribute="height" constant="34" id="G0S-Au-0t0"/>
<constraint firstAttribute="width" constant="3" id="o03-al-nbF"/>
</constraints>
</customView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="A9a-aM-BNn">
<rect key="frame" x="21" y="26" width="280" height="24"/>
<constraints>
<constraint firstAttribute="height" constant="24" id="Ted-52-5mp"/>
</constraints>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" alignment="left" title="Nandita Jaiswal's 35th birthday" placeholderString="" id="nBm-hz-L5t">
<font key="font" size="14" name="Avenir-Light"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" red="1" green="0.5" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" tag="55" translatesAutoresizingMaskIntoConstraints="NO" id="0xk-Sz-MQU">
<rect key="frame" x="319" y="10" width="35" height="35"/>
<constraints>
<constraint firstAttribute="width" constant="35" id="n4G-W9-0Xp"/>
<constraint firstAttribute="height" constant="35" id="viN-NC-XR0"/>
</constraints>
<buttonCell key="cell" type="bevel" bezelStyle="rounded" image="Remove" imagePosition="only" alignment="center" imageScaling="proportionallyDown" inset="2" id="3iw-XB-l87">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="dismissNextEventLabel:" target="-2" id="Gwd-aN-9CO"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="BU6-aE-Les" firstAttribute="centerY" secondItem="PpA-GH-1PV" secondAttribute="centerY" id="09c-hS-Kdy"/>
<constraint firstItem="0xk-Sz-MQU" firstAttribute="leading" secondItem="A9a-aM-BNn" secondAttribute="trailing" constant="20" id="1KT-TD-KeH"/>
<constraint firstItem="8q4-YZ-gkb" firstAttribute="leading" secondItem="A9a-aM-BNn" secondAttribute="leading" constant="-2" id="4lf-X6-VyZ"/>
<constraint firstItem="A9a-aM-BNn" firstAttribute="leading" secondItem="BU6-aE-Les" secondAttribute="trailing" constant="10" id="4mn-mF-aDr"/>
<constraint firstItem="A9a-aM-BNn" firstAttribute="centerY" secondItem="PpA-GH-1PV" secondAttribute="centerY" constant="-10" id="96S-1w-1cF"/>
<constraint firstItem="8q4-YZ-gkb" firstAttribute="bottom" secondItem="BU6-aE-Les" secondAttribute="bottom" id="JBT-HC-8XD"/>
<constraint firstItem="0xk-Sz-MQU" firstAttribute="centerY" secondItem="PpA-GH-1PV" secondAttribute="centerY" id="U5W-rp-ddf"/>
<constraint firstItem="0xk-Sz-MQU" firstAttribute="leading" secondItem="8q4-YZ-gkb" secondAttribute="trailing" id="csx-qD-s3k"/>
<constraint firstItem="BU6-aE-Les" firstAttribute="leading" secondItem="PpA-GH-1PV" secondAttribute="leading" constant="10" id="u6L-TR-aGX"/>
<constraint firstAttribute="trailing" secondItem="0xk-Sz-MQU" secondAttribute="trailing" constant="5" id="w17-Hh-USc"/>
</constraints>
</customView>
<scrollView wantsLayer="YES" focusRingType="none" borderType="none" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" hasVerticalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="7rh-Lu-bXY">
<rect key="frame" x="0.0" y="0.0" width="370" height="75"/>
<clipView key="contentView" drawsBackground="NO" id="03w-56-nAh">
<rect key="frame" x="0.0" y="0.0" width="370" height="75"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<collectionView id="1tF-ue-rfI">
<rect key="frame" x="0.0" y="0.0" width="370" height="75"/>
<autoresizingMask key="autoresizingMask" heightSizable="YES"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumInteritemSpacing="10" minimumLineSpacing="10" scrollDirection="horizontal" id="8dR-oy-HpS">
<size key="itemSize" width="50" height="50"/>
<edgeInsets key="sectionInset" left="10" right="0.0" top="0.0" bottom="0.0"/>
</collectionViewFlowLayout>
<color key="primaryBackgroundColor" red="0.070588235289999995" green="0.95686274510000002" blue="0.10980392160000001" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
</collectionView>
</subviews>
<color key="backgroundColor" name="Accent Color"/>
</clipView>
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="MFX-8H-T4e">
<rect key="frame" x="-100" y="-100" width="370" height="16"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="Tcm-wM-yRg">
<rect key="frame" x="-100" y="-100" width="16" height="75"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
</subviews>
<constraints>
<constraint firstAttribute="height" constant="75" id="2wB-jF-5u4"/>
<constraint firstItem="PpA-GH-1PV" firstAttribute="top" secondItem="Z63-pM-8OA" secondAttribute="top" constant="10" id="bpv-rJ-2r6"/>
<constraint firstItem="PpA-GH-1PV" firstAttribute="leading" secondItem="Z63-pM-8OA" secondAttribute="leading" constant="10" id="e16-5F-0oB"/>
<constraint firstAttribute="trailing" secondItem="PpA-GH-1PV" secondAttribute="trailing" constant="10" id="nHH-4s-dG2"/>
<constraint firstAttribute="bottom" secondItem="PpA-GH-1PV" secondAttribute="bottom" constant="10" id="tHy-Ku-DWJ"/>
<constraint firstAttribute="height" constant="75" id="5Gb-Xg-seV"/>
<constraint firstItem="7rh-Lu-bXY" firstAttribute="top" secondItem="7cF-j3-JRf" secondAttribute="top" id="Ibp-cf-eH1"/>
<constraint firstAttribute="trailing" secondItem="7rh-Lu-bXY" secondAttribute="trailing" id="cHh-NY-5xT"/>
<constraint firstAttribute="bottom" secondItem="7rh-Lu-bXY" secondAttribute="bottom" id="erG-3T-NxN"/>
<constraint firstItem="7rh-Lu-bXY" firstAttribute="leading" secondItem="7cF-j3-JRf" secondAttribute="leading" id="fPm-mQ-0kM"/>
</constraints>
<accessibility identifier="UpcomingEventView"/>
</customView>
@ -520,8 +483,6 @@
<constraint firstItem="HBv-Eh-z9y" firstAttribute="leading" secondItem="Bn4-fy-Lm6" secondAttribute="leading" id="1gK-nB-cgS"/>
<constraint firstAttribute="trailing" secondItem="khu-OS-PzP" secondAttribute="trailing" id="AgT-oA-uZ1"/>
<constraint firstItem="khu-OS-PzP" firstAttribute="top" secondItem="Bn4-fy-Lm6" secondAttribute="top" id="AxZ-D1-B8f"/>
<constraint firstAttribute="trailing" secondItem="Z63-pM-8OA" secondAttribute="trailing" id="IBs-CV-u71"/>
<constraint firstItem="Z63-pM-8OA" firstAttribute="leading" secondItem="Bn4-fy-Lm6" secondAttribute="leading" id="ev6-Wj-PFx"/>
<constraint firstAttribute="trailing" secondItem="HBv-Eh-z9y" secondAttribute="trailing" id="i0H-Z4-5gF"/>
</constraints>
<visibilityPriorities>
@ -562,7 +523,9 @@
<image name="Float" width="15" height="13"/>
<image name="NSShareTemplate" width="15" height="17"/>
<image name="PowerIcon" width="350" height="350"/>
<image name="Remove" width="700" height="700"/>
<image name="Sunrise" width="700" height="700"/>
<namedColor name="Accent Color">
<color red="0.092000000178813934" green="0.0" blue="0.99900001287460327" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
</resources>
</document>

Loading…
Cancel
Save