diff --git a/LiquipediaMenu/Match.swift b/LiquipediaMenu/Match.swift index b1d267b..d26fa14 100644 --- a/LiquipediaMenu/Match.swift +++ b/LiquipediaMenu/Match.swift @@ -8,14 +8,14 @@ import Foundation -struct Match { - var ongoing: Bool - let streamLink: String - let league: String +class Match: NSObject { + var ongoing: Bool = false + var streamLink: String = "" + var league: String = "" - let team1name: String - let team1score: String + var team1name: String = "" + var team1score: String = "" - let team2name: String - let team2score: String + var team2name: String = "" + var team2score: String = "" } diff --git a/LiquipediaMenu/MatchesAPI.swift b/LiquipediaMenu/MatchesAPI.swift index f8e6dc2..fe2c590 100644 --- a/LiquipediaMenu/MatchesAPI.swift +++ b/LiquipediaMenu/MatchesAPI.swift @@ -44,15 +44,15 @@ class MatchesAPI { let leftscore = String(split[0]) let rightscore = String(split[1]) - let newMatch = Match( - ongoing: true, - streamLink: "https://twitch.tv" + (match.getAttributes()?.get(key: "data-stream-twitch"))! , - league: try match.select("tr > td > div > div > a").text(), - team1name: try match.getElementsByClass("team-left").text(), - team1score: leftscore, - team2name: try match.getElementsByClass("team-right").text(), - team2score: rightscore - ) + let newMatch = Match() + newMatch.ongoing = true + newMatch.streamLink = "https://twitch.tv" + (match.getAttributes()?.get(key: "data-stream-twitch"))! + newMatch.league = try match.select("tr > td > div > div > a").text() + newMatch.team1name = try match.getElementsByClass("team-left").text() + newMatch.team1score = leftscore + newMatch.team2name = try match.getElementsByClass("team-right").text() + newMatch.team2score = rightscore + print(newMatch) matches.append(newMatch) } return matches diff --git a/LiquipediaMenu/StatusBarController.swift b/LiquipediaMenu/StatusBarController.swift index e585365..5b2b990 100644 --- a/LiquipediaMenu/StatusBarController.swift +++ b/LiquipediaMenu/StatusBarController.swift @@ -20,23 +20,32 @@ class StatusBarController: NSObject, NSMenuItemValidation { var matches = [Match]() override func awakeFromNib() { - // Set the icon of the statusbar item and put it into the statusbar + // Set the icon of the statusbar item and put it into the statusbar. let icon = NSImage(named: "statusBarIcon") icon?.isTemplate = true statusBarItem.image = icon statusBarItem.menu = statusBar + + // 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 what to select. for item in statusBar.items { item.target = self } + + //-- statusBar.addItem(NSMenuItem.separator()) -// statusBar.insertItem(NSMenuItem.init(title: "Refresh", action: #selector(generateMenu), keyEquivalent: ""), at: 3) + //-- + + statusBar.insertItem(NSMenuItem.init(title: "Refresh", action: #selector(generateMenu), keyEquivalent: ""), at: 3) + performSelector(inBackground: #selector(refreshClicked), with: nil) } - func generateMenu(for matches: [Match]) { + @objc func generateMenu(for matches: [Match]) { for item in statusBar.items { if item.tag == 1 { statusBar.removeItem(item)