Skip to content

Commit

Permalink
Merge branch 'release/0.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
TUNER88 committed Sep 6, 2015
2 parents 60757a7 + 1c37131 commit 5eb2673
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 38 deletions.
20 changes: 16 additions & 4 deletions TramReminder.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
8E211F361B9C78D8004F2FF1 /* DetailsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E211F301B9C78D8004F2FF1 /* DetailsViewController.swift */; };
8E211F371B9C78D8004F2FF1 /* DetailsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8E211F311B9C78D8004F2FF1 /* DetailsViewController.xib */; };
8E211F381B9C78D8004F2FF1 /* Trip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E211F321B9C78D8004F2FF1 /* Trip.swift */; };
8E31973F1B9CC70E00530CF8 /* EventMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E31973E1B9CC70E00530CF8 /* EventMonitor.swift */; };
8E941D091B9CF52D00976B95 /* AboutWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E941D071B9CF52D00976B95 /* AboutWindow.swift */; };
8E941D0A1B9CF52D00976B95 /* AboutWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8E941D081B9CF52D00976B95 /* AboutWindow.xib */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -48,6 +51,9 @@
8E211F301B9C78D8004F2FF1 /* DetailsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DetailsViewController.swift; sourceTree = "<group>"; };
8E211F311B9C78D8004F2FF1 /* DetailsViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DetailsViewController.xib; sourceTree = "<group>"; };
8E211F321B9C78D8004F2FF1 /* Trip.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Trip.swift; sourceTree = "<group>"; };
8E31973E1B9CC70E00530CF8 /* EventMonitor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventMonitor.swift; sourceTree = "<group>"; };
8E941D071B9CF52D00976B95 /* AboutWindow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AboutWindow.swift; sourceTree = "<group>"; };
8E941D081B9CF52D00976B95 /* AboutWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AboutWindow.xib; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -101,15 +107,18 @@
8E211F0D1B9C7580004F2FF1 /* TramReminder */ = {
isa = PBXGroup;
children = (
8E941D071B9CF52D00976B95 /* AboutWindow.swift */,
8E941D081B9CF52D00976B95 /* AboutWindow.xib */,
8E211F101B9C7580004F2FF1 /* AppDelegate.swift */,
8E211F2D1B9C78D8004F2FF1 /* PreferencesWindow.swift */,
8E211F2E1B9C78D8004F2FF1 /* PreferencesWindow.xib */,
8E211F2F1B9C78D8004F2FF1 /* WebClient.swift */,
8E31973E1B9CC70E00530CF8 /* EventMonitor.swift */,
8E211F301B9C78D8004F2FF1 /* DetailsViewController.swift */,
8E211F311B9C78D8004F2FF1 /* DetailsViewController.xib */,
8E211F141B9C7580004F2FF1 /* MainMenu.xib */,
8E211F2D1B9C78D8004F2FF1 /* PreferencesWindow.swift */,
8E211F2E1B9C78D8004F2FF1 /* PreferencesWindow.xib */,
8E211F321B9C78D8004F2FF1 /* Trip.swift */,
8E211F2F1B9C78D8004F2FF1 /* WebClient.swift */,
8E211F121B9C7580004F2FF1 /* Images.xcassets */,
8E211F141B9C7580004F2FF1 /* MainMenu.xib */,
8E211F0E1B9C7580004F2FF1 /* Supporting Files */,
);
path = TramReminder;
Expand Down Expand Up @@ -233,6 +242,7 @@
files = (
8E211F131B9C7580004F2FF1 /* Images.xcassets in Resources */,
8E211F341B9C78D8004F2FF1 /* PreferencesWindow.xib in Resources */,
8E941D0A1B9CF52D00976B95 /* AboutWindow.xib in Resources */,
8E211F161B9C7580004F2FF1 /* MainMenu.xib in Resources */,
8E211F371B9C78D8004F2FF1 /* DetailsViewController.xib in Resources */,
);
Expand Down Expand Up @@ -303,7 +313,9 @@
8E211F381B9C78D8004F2FF1 /* Trip.swift in Sources */,
8E211F331B9C78D8004F2FF1 /* PreferencesWindow.swift in Sources */,
8E211F111B9C7580004F2FF1 /* AppDelegate.swift in Sources */,
8E31973F1B9CC70E00530CF8 /* EventMonitor.swift in Sources */,
8E211F351B9C78D8004F2FF1 /* WebClient.swift in Sources */,
8E941D091B9CF52D00976B95 /* AboutWindow.swift in Sources */,
8E211F361B9C78D8004F2FF1 /* DetailsViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
24 changes: 24 additions & 0 deletions TramReminder/AboutWindow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// AboutWindow.swift
// TramReminder
//
// Created by Anton Pauli on 07.09.15.
// Copyright (c) 2015 Anton Pauli. All rights reserved.
//

import Cocoa

class AboutWindow: NSWindowController {

override func windowDidLoad() {
super.windowDidLoad()

self.window?.center()
self.window?.makeKeyAndOrderFront(nil)
NSApp.activateIgnoringOtherApps(true)
}

override var windowNibName : String! {
return "AboutWindow"
}
}
85 changes: 85 additions & 0 deletions TramReminder/AboutWindow.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7706" systemVersion="14F27" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7706"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="AboutWindow" customModule="TramReminder" customModuleProvider="target">
<connections>
<outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="About" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" animationBehavior="default" id="F0z-JX-Cv5">
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="380" height="178"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1057"/>
<view key="contentView" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="5" width="380" height="178"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Cid-zk-q7Y">
<rect key="frame" x="18" y="136" width="344" height="22"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="TramReminder" id="TJI-bd-SQr">
<font key="font" metaFont="system" size="18"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<scrollView fixedFrame="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="5Ub-sp-S7z">
<rect key="frame" x="20" y="20" width="340" height="100"/>
<clipView key="contentView" misplaced="YES" id="Tdo-HU-OpG">
<rect key="frame" x="1" y="1" width="223" height="133"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView editable="NO" importsGraphics="NO" richText="NO" baseWritingDirection="leftToRight" findStyle="panel" continuousSpellChecking="YES" usesRuler="YES" usesFontPanel="YES" verticallyResizable="YES" allowsNonContiguousLayout="YES" quoteSubstitution="YES" dashSubstitution="YES" spellingCorrection="YES" smartInsertDelete="YES" id="N8P-fP-2Uv">
<rect key="frame" x="0.0" y="0.0" width="223" height="133"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<size key="minSize" width="323" height="98"/>
<size key="maxSize" width="463" height="10000000"/>
<attributedString key="textStorage">
<fragment>
<string key="content">Author: anton.pauli@gmail.com
Source: https://github.com/TUNER88/TramReminder
License: MIT

Tram Icon desgined by Freepik
</string>
<attributes>
<font key="NSFont" size="12" name="HelveticaNeue"/>
<real key="NSKern" value="0.0"/>
<paragraphStyle key="NSParagraphStyle" alignment="left" lineBreakMode="wordWrapping" baseWritingDirection="leftToRight" minimumLineHeight="16" defaultTabInterval="36">
<tabStops/>
</paragraphStyle>
<color key="NSStrokeColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
</attributes>
</fragment>
</attributedString>
<color key="insertionPointColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<size key="minSize" width="323" height="98"/>
<size key="maxSize" width="463" height="10000000"/>
</textView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</clipView>
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="YES" id="0Ti-wJ-Lzy">
<rect key="frame" x="-100" y="-100" width="87" height="18"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="7eb-fz-lXy">
<rect key="frame" x="224" y="1" width="15" height="133"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
</subviews>
</view>
<connections>
<outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
</connections>
<point key="canvasLocation" x="612" y="175"/>
</window>
</objects>
</document>
63 changes: 46 additions & 17 deletions TramReminder/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, PreferencesWindowDelegate {
class AppDelegate: NSObject, NSApplicationDelegate {

@IBOutlet weak var window: NSWindow!

let menu = NSMenu()
let popover = NSPopover()
var eventMonitor: EventMonitor?
let statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(-1)
var rides = NSMutableArray()
let detailViewController = DetailsViewController(nibName: "DetailsViewController", bundle: nil)
Expand All @@ -28,51 +29,77 @@ class AppDelegate: NSObject, NSApplicationDelegate, PreferencesWindowDelegate {
// Jena, Stadtzentrum, Löbdergraben
// Jena, Lobeda-West
var vc = WebClient(origin: "", destination: "")


func applicationDidFinishLaunching(aNotification: NSNotification) {
NSApplication.sharedApplication().hide(nil)

//NSApp.activateIgnoringOtherApps(true)

loadConfigs()

// listen to PreferencesDidChangeNotification
NSNotificationCenter.defaultCenter().addObserver(
self,
selector:
"preferencesDidChange:",
name:"PreferencesDidChangeNotification",
object: nil)

// add statusbar button / icon
if let button = statusItem.button {
button.image = NSImage(named: "StatusBarIcon")
button.action = Selector("togglePopover:")
}

statusItem.title = "Loading..."
popover.contentViewController = self.detailViewController

self.viewRefreshTimer = NSTimer.scheduledTimerWithTimeInterval(viewRefreshInterval, target: self, selector: Selector("refreshViews"), userInfo: nil, repeats: true)
self.dataRefreshTimer = NSTimer.scheduledTimerWithTimeInterval(dataRefreshInterval, target: self, selector: Selector("reloadRides"), userInfo: nil, repeats: true)
// load origin and destination
loadConfigs()

// add popover controller
popover.contentViewController = self.detailViewController
eventMonitor = EventMonitor(mask: .LeftMouseDownMask | .RightMouseDownMask) { [unowned self] event in
if self.popover.shown {
self.closePopover(event)
}
}
eventMonitor?.start()

// load data
self.reloadRides()

}

func preferencesDidUpdate() {
func preferencesDidChange(aNotification: NSNotification) {
loadConfigs()
reloadRides()
}

func loadConfigs(){
statusItem.title = "Loading..."

let defaults = NSUserDefaults.standardUserDefaults()
vc.origin = defaults.stringForKey("origin") ?? ""
vc.destination = defaults.stringForKey("destination") ?? ""

// refresh timers
if(defaults.objectForKey("updateInterval") != nil){
dataRefreshInterval = defaults.doubleForKey("updateInterval") * 60
}

viewRefreshTimer.invalidate()
dataRefreshTimer.invalidate()

viewRefreshTimer = NSTimer.scheduledTimerWithTimeInterval(viewRefreshInterval, target: self, selector: Selector("refreshViews"), userInfo: nil, repeats: true)

if(dataRefreshInterval != 0) {
dataRefreshTimer = NSTimer.scheduledTimerWithTimeInterval(dataRefreshInterval, target: self, selector: Selector("reloadRides"), userInfo: nil, repeats: true)
}
}

func reloadRides(){
self.vc.loadRides({ (data) -> Void in
self.rides = data;
self.refreshViews()

println("ok")
println("ok")
}, failure: {
println("NOT OK")
})
}
)
}

func refreshViews(){
Expand Down Expand Up @@ -119,10 +146,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, PreferencesWindowDelegate {
if let button = statusItem.button {
popover.showRelativeToRect(button.bounds, ofView: button, preferredEdge: NSMinYEdge)
}
eventMonitor?.start()
}

func closePopover(sender: AnyObject?) {
popover.performClose(sender)
eventMonitor?.stop()
}

func togglePopover(sender: AnyObject?) {
Expand Down
2 changes: 2 additions & 0 deletions TramReminder/DetailsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class DetailsViewController: NSViewController {

rideDescriptions.stringValue = text
}


@IBAction func preferencesClicked(sender: NSButtonCell) {
preferencesWindow.showWindow(nil)
}
Expand Down
35 changes: 35 additions & 0 deletions TramReminder/EventMonitor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// EventMonitor.swift
// TramReminder
//
// Created by Anton Pauli on 06.09.15.
// Copyright (c) 2015 Anton Pauli. All rights reserved.
//

import Cocoa

public class EventMonitor {
private var monitor: AnyObject?
private let mask: NSEventMask
private let handler: NSEvent? -> ()

public init(mask: NSEventMask, handler: NSEvent? -> ()) {
self.mask = mask
self.handler = handler
}

deinit {
stop()
}

public func start() {
monitor = NSEvent.addGlobalMonitorForEventsMatchingMask(mask, handler: handler)
}

public func stop() {
if monitor != nil {
NSEvent.removeMonitor(monitor!)
monitor = nil
}
}
}
4 changes: 2 additions & 2 deletions TramReminder/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015 Anton Pauli. All rights reserved. Tram Icon desgined by Freepik</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>LSUIElement</key>
<true/>
</dict>
</plist>
16 changes: 10 additions & 6 deletions TramReminder/PreferencesWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

import Cocoa

protocol PreferencesWindowDelegate {
func preferencesDidUpdate()
}

class PreferencesWindow: NSWindowController, NSWindowDelegate {

@IBOutlet weak var originTextField: NSTextField!
Expand All @@ -21,7 +17,8 @@ class PreferencesWindow: NSWindowController, NSWindowDelegate {
@IBOutlet weak var updateIntervalSlider: NSSlider!
@IBOutlet weak var statusBarItemLimitSlider: NSSlider!

var delegate: PreferencesWindowDelegate?
var aboutWindow: AboutWindow!


override func windowDidLoad() {
super.windowDidLoad()
Expand Down Expand Up @@ -68,7 +65,8 @@ class PreferencesWindow: NSWindowController, NSWindowDelegate {
defaults.setValue(updateIntervalSlider.doubleValue, forKey: "updateInterval")
defaults.setValue(statusBarItemLimitSlider.doubleValue, forKey: "statusBarItems")

delegate?.preferencesDidUpdate()
NSNotificationCenter.defaultCenter().postNotificationName("PreferencesDidChangeNotification", object: nil)
println("Fire setting changed notification")
}

@IBAction func updateIntervalChanged(sender: NSSlider) {
Expand All @@ -91,4 +89,10 @@ class PreferencesWindow: NSWindowController, NSWindowDelegate {
statusBarItemLimitValueLabel.stringValue = "\(value)"
}

@IBAction func showAboutWindow(sender: NSButton) {
if(aboutWindow == nil) {
aboutWindow = AboutWindow()
}
aboutWindow.showWindow(nil)
}
}
Loading

0 comments on commit 5eb2673

Please sign in to comment.