Add opening of streamlink
This commit is contained in:
@@ -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 = "<group>"; };
|
||||
3FB6BB4E216B8595000BF5AA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
3FB6BB4F216B8595000BF5AA /* LiquipediaMenu.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = LiquipediaMenu.entitlements; sourceTree = "<group>"; };
|
||||
3FF66CDE21DE80BA005A93D0 /* MatchMenuItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchMenuItem.swift; sourceTree = "<group>"; };
|
||||
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 = "<group>"; };
|
||||
/* 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 */,
|
||||
);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.18"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
@@ -767,7 +767,7 @@
|
||||
<constraint firstItem="hNo-aO-xJW" firstAttribute="top" secondItem="mdA-hu-Y75" secondAttribute="top" id="z74-pp-2TD"/>
|
||||
</constraints>
|
||||
<connections>
|
||||
<outlet property="league" destination="qq2-vt-ex7" id="MTv-MK-Uj1"/>
|
||||
<outlet property="league" destination="qq2-vt-ex7" id="CDn-fy-VmL"/>
|
||||
<outlet property="ongoing" destination="ku9-TU-97P" id="zpk-DO-9jn"/>
|
||||
<outlet property="team1name" destination="jkF-GR-que" id="pfy-6B-FT2"/>
|
||||
<outlet property="team1score" destination="Z6t-MP-DaY" id="GhS-vL-Guo"/>
|
||||
|
||||
30
LiquipediaMenu/MatchMenuItem.swift
Normal file
30
LiquipediaMenu/MatchMenuItem.swift
Normal file
@@ -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")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user