Skip to content

Commit

Permalink
Fix screensaver build
Browse files Browse the repository at this point in the history
- Update the config sheet to include all three menus

- Bump the deployment target: this is the minimum to get Swift
  screensavers working

- Save selected stop IDs and FeedInfo (by provider ID) in defaults

Fixes #1
  • Loading branch information
oyamauchi committed May 3, 2021
1 parent cf6c314 commit 97337fc
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 45 deletions.
9 changes: 9 additions & 0 deletions Common/GTFS/FeedInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ class FeedInfo {
return feedInfos[tag]!
}

static func feedInfo(forProviderId providerId: String) -> FeedInfo? {
for feedInfo in feedInfos.values {
if feedInfo.providerId == providerId {
return feedInfo
}
}
return nil
}

func stopMenu(forRouteTag routeTag: Int) -> NSMenu {
stopTagToStopIds.removeAll()

Expand Down
6 changes: 4 additions & 2 deletions SubwayMon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
ONLY_ACTIVE_ARCH = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG LOCAL_SERVER";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand Down Expand Up @@ -471,7 +471,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
};
Expand All @@ -490,6 +490,7 @@
INFOPLIST_FILE = "SubwayMon/SubwayMon-Info.plist";
INSTALL_PATH = "$(HOME)/Library/Screen Savers";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MARKETING_VERSION = 3.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.oyamauchi.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -510,6 +511,7 @@
INFOPLIST_FILE = "SubwayMon/SubwayMon-Info.plist";
INSTALL_PATH = "$(HOME)/Library/Screen Savers";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MARKETING_VERSION = 3.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.oyamauchi.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = saver;
Expand Down
67 changes: 49 additions & 18 deletions SubwayMon/ConfigureSheet.xib
Original file line number Diff line number Diff line change
@@ -1,38 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13771" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15705" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13771"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15705"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="SubwayMonScreenSaverView">
<connections>
<outlet property="configSheet" destination="31" id="o6L-Y6-coz"/>
<outlet property="popupMenu" destination="3" id="kLb-bB-0NR"/>
<outlet property="providerMenu" destination="PAK-Qj-l3j" id="KKp-Im-u7W"/>
<outlet property="routeMenu" destination="p3W-8g-Rhc" id="Jhv-n2-o0s"/>
<outlet property="stopMenu" destination="eWC-YT-KPW" id="2cw-Qx-QIK"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="31" customClass="NSPanel">
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="31" customClass="NSPanel">
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="139" y="81" width="315" height="102"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
<rect key="contentRect" x="139" y="81" width="315" height="164"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
<view key="contentView" id="32">
<rect key="frame" x="0.0" y="0.0" width="315" height="102"/>
<rect key="frame" x="0.0" y="0.0" width="315" height="164"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="3">
<rect key="frame" x="18" y="58" width="280" height="26"/>
<popUpButtonCell key="cell" type="push" title="Bedford Park Blvd - Lehman College" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" autoenablesItems="NO" selectedItem="6" id="4">
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="PAK-Qj-l3j">
<rect key="frame" x="18" y="120" width="280" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" title="Item 1" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="h7U-jL-MiZ" id="v6V-yh-F33">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" title="OtherViews" autoenablesItems="NO" id="5">
<font key="font" metaFont="system"/>
<menu key="menu" id="Sfh-zJ-Ihm">
<items>
<menuItem title="Item 1" state="on" id="h7U-jL-MiZ"/>
<menuItem title="Item 2" id="olZ-YK-d8k"/>
<menuItem title="Item 3" id="PXl-eP-vKq"/>
</items>
</menu>
</popUpButtonCell>
</popUpButton>
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="p3W-8g-Rhc">
<rect key="frame" x="18" y="89" width="280" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" title="Item 1" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="xte-JT-SiM" id="2KT-xK-NKc">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<menu key="menu" id="4ln-6X-u57">
<items>
<menuItem title="Item 1" state="on" id="xte-JT-SiM"/>
<menuItem title="Item 2" id="vbc-L4-ww6"/>
<menuItem title="Item 3" id="mk6-cz-RnH"/>
</items>
</menu>
</popUpButtonCell>
</popUpButton>
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="eWC-YT-KPW">
<rect key="frame" x="18" y="58" width="280" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" title="Item 1" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="rSI-g9-Zry" id="q2S-UQ-IeT">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<menu key="menu" id="muf-AH-wd2">
<items>
<menuItem title="Bedford Park Blvd - Lehman College" state="on" id="6"/>
<menuItem title="Item 2" id="7"/>
<menuItem title="Item 3" id="8"/>
<menuItem title="Item 1" state="on" id="rSI-g9-Zry"/>
<menuItem title="Item 2" id="nVs-ev-SVf"/>
<menuItem title="Item 3" id="Gch-hD-Zuv"/>
</items>
</menu>
</popUpButtonCell>
Expand All @@ -52,13 +85,11 @@ DQ
</button>
</subviews>
<constraints>
<constraint firstItem="3" firstAttribute="top" secondItem="32" secondAttribute="top" constant="20" symbolic="YES" id="34"/>
<constraint firstItem="3" firstAttribute="leading" secondItem="32" secondAttribute="leading" constant="20" symbolic="YES" id="35"/>
<constraint firstAttribute="trailing" secondItem="3" secondAttribute="trailing" constant="20" symbolic="YES" id="36"/>
<constraint firstAttribute="trailing" secondItem="23" secondAttribute="trailing" constant="20" symbolic="YES" id="38"/>
<constraint firstAttribute="bottom" secondItem="23" secondAttribute="bottom" constant="20" symbolic="YES" id="39"/>
</constraints>
</view>
<point key="canvasLocation" x="118.5" y="-15"/>
</window>
</objects>
</document>
2 changes: 1 addition & 1 deletion SubwayMon/SubwayMon-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>2.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
61 changes: 37 additions & 24 deletions SubwayMon/SubwayMonScreenSaverView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@ import ScreenSaver

class SubwayMonScreenSaverView: ScreenSaverView {
@IBOutlet var configSheet: NSWindow!
@IBOutlet var popupMenu: NSPopUpButton!
@IBOutlet var providerMenu: NSPopUpButton!
@IBOutlet var routeMenu: NSPopUpButton!
@IBOutlet var stopMenu: NSPopUpButton!

private var subwayView: SubwayMonView!
private var menuManager: MenuManager!

private let kSelectedStationKey = "SelectedStation"
private let defaults = ScreenSaverDefaults(forModuleWithName: "com.oyamauchi.SubwayMon")!

@IBAction func closeSheet(sender _: Any) {
let defaults = ScreenSaverDefaults(forModuleWithName: "com.oyamauchi.SubwayMon")!
let stopId = FeedInfo.shared.stopId(forTag: popupMenu.selectedTag())
defaults.set(stopId, forKey: kSelectedStationKey)
defaults.synchronize()
private static let kSelectedProviderIdKey = "SelectedProviderId"
private static let kSelectedStopIdsKey = "SelectedStopIds"

subwayView.selectedStopId = stopId

NSApplication.shared().endSheet(configSheet)
@IBAction func closeSheet(sender _: Any) {
configSheet.sheetParent?.endSheet(configSheet)
}

override init?(frame: NSRect, isPreview: Bool) {
Expand All @@ -33,16 +32,35 @@ class SubwayMonScreenSaverView: ScreenSaverView {

animationTimeInterval = 5.0

let defaults = ScreenSaverDefaults(forModuleWithName: "com.oyamauchi.SubwayMon")!
// Grand Central on the Lex by default
let stopId = defaults.string(forKey: kSelectedStationKey) ?? "631"

subwayView = SubwayMonView(frame: bounds)
subwayView.initialize(stopId: stopId)
addSubview(subwayView)

popupMenu.menu = FeedInfo.shared.menu
popupMenu.selectItem(withTag: FeedInfo.shared.tag(forStopId: stopId))
if let savedStopIds = defaults.stringArray(forKey: SubwayMonScreenSaverView.kSelectedStopIdsKey),
let savedProviderId = defaults.string(forKey: SubwayMonScreenSaverView.kSelectedProviderIdKey),
let feedInfo = FeedInfo.feedInfo(forProviderId: savedProviderId)
{
subwayView.setStopIds(stopIds: savedStopIds, feedInfo: feedInfo)
subwayView.needsDisplay = true
}

menuManager = MenuManager(
defaults: defaults,
providerMenu: providerMenu,
routeMenu: routeMenu,
stopMenu: stopMenu,
onStopIdsSelected: { [unowned self] (stopIds: [StopId], feedInfo: FeedInfo) -> Void in
self.setAndSave(stopIds: stopIds, feedInfo: feedInfo)
}
)
}

func setAndSave(stopIds: [StopId], feedInfo: FeedInfo) {
defaults.set(stopIds, forKey: SubwayMonScreenSaverView.kSelectedStopIdsKey)
defaults.set(feedInfo.providerId, forKey: SubwayMonScreenSaverView.kSelectedProviderIdKey)
defaults.synchronize()

subwayView.setStopIds(stopIds: stopIds, feedInfo: feedInfo)
subwayView.needsDisplay = true
}

required init?(coder: NSCoder) {
Expand All @@ -53,11 +71,6 @@ class SubwayMonScreenSaverView: ScreenSaverView {
needsDisplay = true
}

override func hasConfigureSheet() -> Bool {
return true
}

override func configureSheet() -> NSWindow? {
return configSheet
}
override var hasConfigureSheet: Bool { true }
override var configureSheet: NSWindow? { configSheet }
}

0 comments on commit 97337fc

Please sign in to comment.