Skip to content

Commit

Permalink
v1.1.1으로 업데이트
Browse files Browse the repository at this point in the history
- 아이콘/이미지 리소스 추가 (Icon designed by rorysee)
- 로그인을 시도할 때 아이콘 애니메이션
  • Loading branch information
taggon committed Jan 5, 2017
1 parent 87a80cc commit 943c700
Show file tree
Hide file tree
Showing 18 changed files with 136 additions and 9 deletions.
6 changes: 4 additions & 2 deletions Coffeefy.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,12 @@
baseConfigurationReference = 3C84D6F33407824D39B927AE /* Pods-Coffeefy.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_IDENTITY = "";
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = PJ627876A5;
INFOPLIST_FILE = Coffeefy/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.12;
PRODUCT_BUNDLE_IDENTIFIER = kim.taegon.Coffeefy;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
Expand All @@ -370,11 +371,12 @@
baseConfigurationReference = 0356958897CBA1B6DE6A3E02 /* Pods-Coffeefy.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_IDENTITY = "";
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = PJ627876A5;
INFOPLIST_FILE = Coffeefy/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.12;
PRODUCT_BUNDLE_IDENTIFIER = kim.taegon.Coffeefy;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
Expand Down
10 changes: 9 additions & 1 deletion Coffeefy/AboutPreferencesView.xib
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<rect key="frame" x="199" y="92" width="163" height="35"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Coffeefy" id="Rcj-1S-SKX">
<font key="font" size="28" name="MarkerFelt-Thin"/>
<font key="font" size="28" name="Helvetica-Bold"/>
<color key="textColor" red="0.57986560880829008" green="0.4407564513348734" blue="0.26992281138207724" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
Expand All @@ -52,6 +52,11 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="aFB-AK-fPE">
<rect key="frame" x="40" y="28" width="110" height="110"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" image="coffeefy3" id="PHv-7b-vKz"/>
</imageView>
</subviews>
</view>
<color key="borderColor" name="selectedTextColor" catalog="System" colorSpace="catalog"/>
Expand Down Expand Up @@ -109,4 +114,7 @@
</textFieldCell>
</textField>
</objects>
<resources>
<image name="coffeefy3" width="512" height="512"/>
</resources>
</document>
45 changes: 43 additions & 2 deletions Coffeefy/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import MASPreferences
import ReachabilitySwift
import CoreWLAN

public let StopAnimationNotification = NSNotification.Name("StopAnimationNotification")

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

@IBOutlet weak var statusMenu: NSMenu!
var statusItem: NSStatusItem = NSStatusBar.system().statusItem(withLength: NSVariableStatusItemLength)
var statusItem: NSStatusItem = NSStatusBar.system().statusItem(withLength: NSSquareStatusItemLength)

var _prefWindowController: NSWindowController?
var prefWindowController: NSWindowController! {
Expand All @@ -33,12 +35,17 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}

var currentIconIndex = 3
var animTimer: Timer?

let reachability = Reachability()!
let bot = LoginBot()

func applicationDidFinishLaunching(_ aNotification: Notification) {
statusItem.image = NSImage(named: NSImageNameMenuOnStateTemplate)
statusItem.menu = statusMenu
loadStatusImage(name: "coffeefy3")

NotificationCenter.default.addObserver(self, selector: #selector(self.stopAnimation), name: StopAnimationNotification, object: nil)

// start watching wifi connection status
NotificationCenter.default.addObserver(self, selector: #selector(self.reachabilityChanged),name: ReachabilityChangedNotification,object: reachability)
Expand All @@ -61,11 +68,45 @@ class AppDelegate: NSObject, NSApplicationDelegate {
// 스타벅스 SSID일 때만 반응
let ssid = CWWiFiClient()?.interface(withName: nil)?.ssid() ?? ""
if ssid.lowercased().contains("starbucks") {
startAnimatingStatusImage()
bot.login()
} else {
NSLog("This application works only with Starbucks Wifi network")
}
}

func stopAnimation(note: NSNotification) {
stopAnimatingStatusImage()
}

func loadStatusImage(name: String) {
if let button = statusItem.button {
let size = NSMakeSize(18.0, 18.0)
button.image = NSImage(named: name)
button.image!.size = size
}
}

func startAnimatingStatusImage() {
currentIconIndex = 0
updateStatusImage(index: 0)

animTimer = Timer.scheduledTimer(withTimeInterval: 4.0/15.0, repeats: true){ timer in
self.currentIconIndex = ( self.currentIconIndex + 1 ) % 4
self.updateStatusImage(index: self.currentIconIndex)
}
}

func stopAnimatingStatusImage() {
animTimer?.invalidate()
animTimer = nil

updateStatusImage(index: 3)
}

func updateStatusImage(index: Int) {
loadStatusImage(name: "coffeefy\(currentIconIndex)")
}

@IBAction func openPreference(sender: AnyObject?) {
prefWindowController.showWindow(self)
Expand Down
9 changes: 6 additions & 3 deletions Coffeefy/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "256x256",
"idiom" : "mac",
"filename" : "coffeefy_512.png",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "512x512",
"idiom" : "mac",
"filename" : "coffeefy.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "512x512",
"idiom" : "mac",
"filename" : "[email protected]",
"scale" : "2x"
}
],
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions Coffeefy/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
15 changes: 15 additions & 0 deletions Coffeefy/Assets.xcassets/coffeefy0.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "coffeefy0.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.
15 changes: 15 additions & 0 deletions Coffeefy/Assets.xcassets/coffeefy1.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "coffeefy1.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.
15 changes: 15 additions & 0 deletions Coffeefy/Assets.xcassets/coffeefy2.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "coffeefy2.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.
15 changes: 15 additions & 0 deletions Coffeefy/Assets.xcassets/coffeefy3.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "coffeefy4.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.
2 changes: 1 addition & 1 deletion Coffeefy/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.1</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationCategoryType</key>
Expand Down
7 changes: 7 additions & 0 deletions Coffeefy/LoginBot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class LoginBot: NSObject, WKScriptMessageHandler, WKNavigationDelegate {
}

NSLog("This application works only with Startbucks Wifi network.")
self.stopAnimation()
}
}

Expand Down Expand Up @@ -93,6 +94,10 @@ class LoginBot: NSObject, WKScriptMessageHandler, WKNavigationDelegate {
NSUserNotificationCenter.default.scheduleNotification(noti)
}

func stopAnimation() {
NotificationCenter.default.post(name: StopAnimationNotification, object: nil)
}

func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
let body = message.body as! String

Expand All @@ -104,6 +109,7 @@ class LoginBot: NSObject, WKScriptMessageHandler, WKNavigationDelegate {
} else if body.hasPrefix("alert:") {
let errorMessage = body.substring(from: body.characters.index(body.characters.startIndex, offsetBy: 6))
notify(title: "인증 에러", subtitle: errorMessage, informativeText: nil)
stopAnimation()
}
}

Expand All @@ -116,6 +122,7 @@ class LoginBot: NSObject, WKScriptMessageHandler, WKNavigationDelegate {
if host == "www.istarbucks.co.kr" || host.hasPrefix("www.google.") {
webView.stopLoading()
notify(title: "접속 성공", subtitle: "이제 스타벅스 와이파이를 사용할 수 있습니다.", informativeText: nil)
stopAnimation()
}
}
}
Expand Down

0 comments on commit 943c700

Please sign in to comment.