diff --git a/LiquipediaMenu.xcodeproj/project.pbxproj b/LiquipediaMenu.xcodeproj/project.pbxproj index 2b85fcc..c065cee 100644 --- a/LiquipediaMenu.xcodeproj/project.pbxproj +++ b/LiquipediaMenu.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ 3FB6BB48216B8594000BF5AA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FB6BB47216B8594000BF5AA /* AppDelegate.swift */; }; 3FB6BB4A216B8595000BF5AA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3FB6BB49216B8595000BF5AA /* Assets.xcassets */; }; 3FB6BB4D216B8595000BF5AA /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3FB6BB4B216B8595000BF5AA /* MainMenu.xib */; }; + 3FF66CDF21DE80BA005A93D0 /* MatchMenuItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FF66CDE21DE80BA005A93D0 /* MatchMenuItem.swift */; }; FB399B52A803D29045E1307F /* Pods_LiquipediaMenu.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 37CBB27C5544ABC18BCC3124 /* Pods_LiquipediaMenu.framework */; }; /* End PBXBuildFile section */ @@ -46,6 +47,7 @@ 3FB6BB4C216B8595000BF5AA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; 3FB6BB4E216B8595000BF5AA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 3FB6BB4F216B8595000BF5AA /* LiquipediaMenu.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = LiquipediaMenu.entitlements; sourceTree = ""; }; + 3FF66CDE21DE80BA005A93D0 /* MatchMenuItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchMenuItem.swift; sourceTree = ""; }; F17640390E809B5BAD655536 /* Pods-LiquipediaMenu.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LiquipediaMenu.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LiquipediaMenu/Pods-LiquipediaMenu.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -110,10 +112,11 @@ isa = PBXGroup; children = ( 3FB6BB47216B8594000BF5AA /* AppDelegate.swift */, - 3F49E945216B86150047B0FE /* Match.swift */, - 3F563E06216E640D00AA3C06 /* MatchView.swift */, 3F49E947216B862B0047B0FE /* StatusBarController.swift */, 3F49E949216BE87B0047B0FE /* MatchesAPI.swift */, + 3F49E945216B86150047B0FE /* Match.swift */, + 3FF66CDE21DE80BA005A93D0 /* MatchMenuItem.swift */, + 3F563E06216E640D00AA3C06 /* MatchView.swift */, 3FB6BB49216B8595000BF5AA /* Assets.xcassets */, 3FB6BB4B216B8595000BF5AA /* MainMenu.xib */, 3FB6BB4E216B8595000BF5AA /* Info.plist */, @@ -289,6 +292,7 @@ 3FB6BB48216B8594000BF5AA /* AppDelegate.swift in Sources */, 3F563E07216E640D00AA3C06 /* MatchView.swift in Sources */, 3F49E948216B862B0047B0FE /* StatusBarController.swift in Sources */, + 3FF66CDF21DE80BA005A93D0 /* MatchMenuItem.swift in Sources */, 3F49E94A216BE87B0047B0FE /* MatchesAPI.swift in Sources */, 3F49E946216B86150047B0FE /* Match.swift in Sources */, ); diff --git a/LiquipediaMenu/Base.lproj/MainMenu.xib b/LiquipediaMenu/Base.lproj/MainMenu.xib index 6efd80f..4d20b4c 100644 --- a/LiquipediaMenu/Base.lproj/MainMenu.xib +++ b/LiquipediaMenu/Base.lproj/MainMenu.xib @@ -1,8 +1,8 @@ - + - + @@ -767,7 +767,7 @@ - + diff --git a/LiquipediaMenu/MatchMenuItem.swift b/LiquipediaMenu/MatchMenuItem.swift new file mode 100644 index 0000000..d2efc02 --- /dev/null +++ b/LiquipediaMenu/MatchMenuItem.swift @@ -0,0 +1,30 @@ +// +// MatchMenuItem.swift +// LiquipediaMenu +// +// Created by Felix Förtsch on 03.01.19. +// Copyright © 2019 Felix Förtsch. All rights reserved. +// + +import Cocoa + +class MatchMenuItem: NSMenuItem { + var streamLink = "" + + init(for match: Match, action selector: Selector?) { + // TODO: Add custom view to MatchMenuItem +// let customView = MatchView() +// customView.updateView(for: match) + + super.init(title: match.league + match.team1name + match.team1score + ":" + match.team2score + match.team2name, action: selector, keyEquivalent: "") + self.streamLink = match.streamLink +// self.view = customView + + } + + // TODO: find out what that means + required init(coder decoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + +} diff --git a/LiquipediaMenu/MatchView.swift b/LiquipediaMenu/MatchView.swift index 4fb48be..ba9cc41 100644 --- a/LiquipediaMenu/MatchView.swift +++ b/LiquipediaMenu/MatchView.swift @@ -9,7 +9,7 @@ import Cocoa class MatchView: NSView { - @IBOutlet weak var league: NSTextField! + @IBOutlet var league: NSTextField! @IBOutlet weak var ongoing: NSTextField! @IBOutlet weak var team1name: NSTextField! @IBOutlet weak var team1score: NSTextField! @@ -18,14 +18,14 @@ class MatchView: NSView { func updateView(for match: Match) { DispatchQueue.main.async { - if !match.ongoing { - self.ongoing.isHidden = true - } + + self.league = NSTextField() + self.league.stringValue = match.league + +// self.team1name.stringValue = match.team1name +// self.team1score.stringValue = match.team1score +// self.team2name.stringValue = match.team2name +// self.team2score.stringValue = match.team2score } - - self.team1name.stringValue = match.team1name - self.team1score.stringValue = match.team1score - self.team2name.stringValue = match.team2name - self.team2score.stringValue = match.team2score } } diff --git a/LiquipediaMenu/StatusBarController.swift b/LiquipediaMenu/StatusBarController.swift index 10f2c3c..21168a9 100644 --- a/LiquipediaMenu/StatusBarController.swift +++ b/LiquipediaMenu/StatusBarController.swift @@ -28,7 +28,6 @@ class StatusBarController: NSObject, NSMenuItemValidation { // Add the starting menu items. statusBar.addItem(NSMenuItem.init(title: "Refresh", action: #selector(refreshClicked), keyEquivalent: "")) - statusBar.addItem(NSMenuItem.init(title: "Set MatchView", action: #selector(updateView), keyEquivalent: "")) statusBar.addItem(NSMenuItem.init(title: "Quit", action: #selector(quitClicked), keyEquivalent: "")) // Set the target to self, so the selectors know where to select. @@ -40,12 +39,13 @@ class StatusBarController: NSObject, NSMenuItemValidation { statusBar.addItem(NSMenuItem.separator()) //-- - performSelector(inBackground: #selector(refreshClicked), with: nil) + // TODO: Refresh on Startup } @objc func refreshClicked(_ sender: NSMenuItem) { - DispatchQueue.global().async { + // TODO: Do refresh async +// DispatchQueue.global().async { // TODO: Add Spinner to indicate that loading is going on. for item in self.statusBar.items { @@ -56,7 +56,7 @@ class StatusBarController: NSObject, NSMenuItemValidation { if let matches = self.matchesAPI.fetchMatches(for: "dota2") { for match in matches { - let newItem = NSMenuItem.init(title: match.league + match.team1name + match.team1score + ":" + match.team2score + match.team2name, action: nil, keyEquivalent: "") + let newItem = MatchMenuItem.init(for: match, action: #selector(self.openStreamLink)) newItem.tag = 1 newItem.target = self self.statusBar.addItem(newItem) @@ -67,20 +67,18 @@ class StatusBarController: NSObject, NSMenuItemValidation { newItem.target = self self.statusBar.addItem(newItem) } - } +// } } - @objc func updateView() { - for item in statusBar.items { - if item.tag == 1 { - item.view? = MatchView() - } - } - } - - @objc func quitClicked(_ sender: NSMenuItem) { + @objc func quitClicked() { NSApplication.shared.terminate(self) } + @objc func openStreamLink(_ sender: MatchMenuItem) { + if let url = URL(string: sender.streamLink) { + NSWorkspace.shared.open(url) + } + } + }