Move generateMenu method to async background task.
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
3F49E946216B86150047B0FE /* Match.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F49E945216B86150047B0FE /* Match.swift */; };
|
||||
3F49E948216B862B0047B0FE /* StatusBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F49E947216B862B0047B0FE /* StatusBarController.swift */; };
|
||||
3F49E94A216BE87B0047B0FE /* MatchesAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F49E949216BE87B0047B0FE /* MatchesAPI.swift */; };
|
||||
3F50154321DBD37200AC9639 /* LiquipediaMenuTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F50154221DBD37200AC9639 /* LiquipediaMenuTests.swift */; };
|
||||
3F50154B21DBD43E00AC9639 /* MatchesAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F50154A21DBD43E00AC9639 /* MatchesAPITests.swift */; };
|
||||
3F563E07216E640D00AA3C06 /* MatchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F563E06216E640D00AA3C06 /* MatchView.swift */; };
|
||||
3FB6BB48216B8594000BF5AA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FB6BB47216B8594000BF5AA /* AppDelegate.swift */; };
|
||||
3FB6BB4A216B8595000BF5AA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3FB6BB49216B8595000BF5AA /* Assets.xcassets */; };
|
||||
@@ -17,12 +19,26 @@
|
||||
FB399B52A803D29045E1307F /* Pods_LiquipediaMenu.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 37CBB27C5544ABC18BCC3124 /* Pods_LiquipediaMenu.framework */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
3F50154521DBD37200AC9639 /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = 3FB6BB3C216B8594000BF5AA /* Project object */;
|
||||
proxyType = 1;
|
||||
remoteGlobalIDString = 3FB6BB43216B8594000BF5AA;
|
||||
remoteInfo = LiquipediaMenu;
|
||||
};
|
||||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
1DC0D8B9D836504166CF8796 /* Pods-LiquipediaMenu.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LiquipediaMenu.release.xcconfig"; path = "Pods/Target Support Files/Pods-LiquipediaMenu/Pods-LiquipediaMenu.release.xcconfig"; sourceTree = "<group>"; };
|
||||
37CBB27C5544ABC18BCC3124 /* Pods_LiquipediaMenu.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LiquipediaMenu.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
3F49E945216B86150047B0FE /* Match.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Match.swift; sourceTree = "<group>"; };
|
||||
3F49E947216B862B0047B0FE /* StatusBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusBarController.swift; sourceTree = "<group>"; };
|
||||
3F49E949216BE87B0047B0FE /* MatchesAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchesAPI.swift; sourceTree = "<group>"; };
|
||||
3F50154021DBD37100AC9639 /* LiquipediaMenuTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LiquipediaMenuTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
3F50154221DBD37200AC9639 /* LiquipediaMenuTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiquipediaMenuTests.swift; sourceTree = "<group>"; };
|
||||
3F50154421DBD37200AC9639 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
3F50154A21DBD43E00AC9639 /* MatchesAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchesAPITests.swift; sourceTree = "<group>"; };
|
||||
3F563E06216E640D00AA3C06 /* MatchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchView.swift; sourceTree = "<group>"; };
|
||||
3FB6BB44216B8594000BF5AA /* LiquipediaMenu.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LiquipediaMenu.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
3FB6BB47216B8594000BF5AA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
@@ -34,6 +50,13 @@
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
3F50153D21DBD37100AC9639 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
3FB6BB41216B8594000BF5AA /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
@@ -53,10 +76,21 @@
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
3F50154121DBD37200AC9639 /* LiquipediaMenuTests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
3F50154221DBD37200AC9639 /* LiquipediaMenuTests.swift */,
|
||||
3F50154A21DBD43E00AC9639 /* MatchesAPITests.swift */,
|
||||
3F50154421DBD37200AC9639 /* Info.plist */,
|
||||
);
|
||||
path = LiquipediaMenuTests;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
3FB6BB3B216B8594000BF5AA = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
3FB6BB46216B8594000BF5AA /* LiquipediaMenu */,
|
||||
3F50154121DBD37200AC9639 /* LiquipediaMenuTests */,
|
||||
3FB6BB45216B8594000BF5AA /* Products */,
|
||||
E0B4959D8858F82D9DFC566B /* Pods */,
|
||||
0C5431C5497A988E0E58556D /* Frameworks */,
|
||||
@@ -67,6 +101,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
3FB6BB44216B8594000BF5AA /* LiquipediaMenu.app */,
|
||||
3F50154021DBD37100AC9639 /* LiquipediaMenuTests.xctest */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
@@ -99,6 +134,24 @@
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
3F50153F21DBD37100AC9639 /* LiquipediaMenuTests */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 3F50154921DBD37200AC9639 /* Build configuration list for PBXNativeTarget "LiquipediaMenuTests" */;
|
||||
buildPhases = (
|
||||
3F50153C21DBD37100AC9639 /* Sources */,
|
||||
3F50153D21DBD37100AC9639 /* Frameworks */,
|
||||
3F50153E21DBD37100AC9639 /* Resources */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
3F50154621DBD37200AC9639 /* PBXTargetDependency */,
|
||||
);
|
||||
name = LiquipediaMenuTests;
|
||||
productName = LiquipediaMenuTests;
|
||||
productReference = 3F50154021DBD37100AC9639 /* LiquipediaMenuTests.xctest */;
|
||||
productType = "com.apple.product-type.bundle.unit-test";
|
||||
};
|
||||
3FB6BB43216B8594000BF5AA /* LiquipediaMenu */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 3FB6BB52216B8595000BF5AA /* Build configuration list for PBXNativeTarget "LiquipediaMenu" */;
|
||||
@@ -124,10 +177,14 @@
|
||||
3FB6BB3C216B8594000BF5AA /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 1000;
|
||||
LastSwiftUpdateCheck = 1010;
|
||||
LastUpgradeCheck = 1000;
|
||||
ORGANIZATIONNAME = "Felix Förtsch";
|
||||
TargetAttributes = {
|
||||
3F50153F21DBD37100AC9639 = {
|
||||
CreatedOnToolsVersion = 10.1;
|
||||
TestTargetID = 3FB6BB43216B8594000BF5AA;
|
||||
};
|
||||
3FB6BB43216B8594000BF5AA = {
|
||||
CreatedOnToolsVersion = 10.0;
|
||||
SystemCapabilities = {
|
||||
@@ -152,11 +209,19 @@
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
3FB6BB43216B8594000BF5AA /* LiquipediaMenu */,
|
||||
3F50153F21DBD37100AC9639 /* LiquipediaMenuTests */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXResourcesBuildPhase section */
|
||||
3F50153E21DBD37100AC9639 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
3FB6BB42216B8594000BF5AA /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
@@ -208,6 +273,15 @@
|
||||
/* End PBXShellScriptBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
3F50153C21DBD37100AC9639 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
3F50154B21DBD43E00AC9639 /* MatchesAPITests.swift in Sources */,
|
||||
3F50154321DBD37200AC9639 /* LiquipediaMenuTests.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
3FB6BB40216B8594000BF5AA /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
@@ -222,6 +296,14 @@
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXTargetDependency section */
|
||||
3F50154621DBD37200AC9639 /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
target = 3FB6BB43216B8594000BF5AA /* LiquipediaMenu */;
|
||||
targetProxy = 3F50154521DBD37200AC9639 /* PBXContainerItemProxy */;
|
||||
};
|
||||
/* End PBXTargetDependency section */
|
||||
|
||||
/* Begin PBXVariantGroup section */
|
||||
3FB6BB4B216B8595000BF5AA /* MainMenu.xib */ = {
|
||||
isa = PBXVariantGroup;
|
||||
@@ -234,6 +316,46 @@
|
||||
/* End PBXVariantGroup section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
3F50154721DBD37200AC9639 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
BUNDLE_LOADER = "$(TEST_HOST)";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEVELOPMENT_TEAM = NG5W75WE8U;
|
||||
INFOPLIST_FILE = LiquipediaMenuTests/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/../Frameworks",
|
||||
"@loader_path/../Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = de.felixfoertsch.LiquipediaMenuTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 4.2;
|
||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/LiquipediaMenu.app/Contents/MacOS/LiquipediaMenu";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
3F50154821DBD37200AC9639 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
BUNDLE_LOADER = "$(TEST_HOST)";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEVELOPMENT_TEAM = NG5W75WE8U;
|
||||
INFOPLIST_FILE = LiquipediaMenuTests/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/../Frameworks",
|
||||
"@loader_path/../Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = de.felixfoertsch.LiquipediaMenuTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 4.2;
|
||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/LiquipediaMenu.app/Contents/MacOS/LiquipediaMenu";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
3FB6BB50216B8595000BF5AA /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
@@ -396,6 +518,15 @@
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
3F50154921DBD37200AC9639 /* Build configuration list for PBXNativeTarget "LiquipediaMenuTests" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
3F50154721DBD37200AC9639 /* Debug */,
|
||||
3F50154821DBD37200AC9639 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
3FB6BB3F216B8594000BF5AA /* Build configuration list for PBXProject "LiquipediaMenu" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
|
||||
@@ -23,9 +23,9 @@ class MatchView: NSView {
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,9 +52,11 @@ class MatchesAPI {
|
||||
newMatch.team1score = leftscore
|
||||
newMatch.team2name = try match.getElementsByClass("team-right").text()
|
||||
newMatch.team2score = rightscore
|
||||
print(newMatch)
|
||||
matches.append(newMatch)
|
||||
}
|
||||
if matches.count == 0 {
|
||||
return nil
|
||||
}
|
||||
return matches
|
||||
} catch Exception.Error(_, _) {
|
||||
print("")
|
||||
|
||||
@@ -31,7 +31,7 @@ class StatusBarController: NSObject, NSMenuItemValidation {
|
||||
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.
|
||||
// Set the target to self, so the selectors know where to select.
|
||||
for item in statusBar.items {
|
||||
item.target = self
|
||||
}
|
||||
@@ -40,31 +40,35 @@ class StatusBarController: NSObject, NSMenuItemValidation {
|
||||
statusBar.addItem(NSMenuItem.separator())
|
||||
//--
|
||||
|
||||
statusBar.insertItem(NSMenuItem.init(title: "Refresh", action: #selector(generateMenu), keyEquivalent: ""), at: 3)
|
||||
|
||||
performSelector(inBackground: #selector(refreshClicked), with: nil)
|
||||
}
|
||||
|
||||
@objc func generateMenu(for matches: [Match]) {
|
||||
for item in statusBar.items {
|
||||
if item.tag == 1 {
|
||||
statusBar.removeItem(item)
|
||||
}
|
||||
}
|
||||
for match in matches {
|
||||
let newItem = NSMenuItem.init(title: match.league + match.team1name + match.team1score + ":" + match.team2score + match.team2name, action: nil, keyEquivalent: "")
|
||||
newItem.tag = 1
|
||||
newItem.target = self
|
||||
statusBar.addItem(newItem)
|
||||
}
|
||||
}
|
||||
|
||||
@objc func refreshClicked(_ sender: NSMenuItem) {
|
||||
|
||||
DispatchQueue.global().async {
|
||||
// TODO: Add Spinner to indicate that loading is going on.
|
||||
|
||||
for item in self.statusBar.items {
|
||||
if item.tag == 1 {
|
||||
self.statusBar.removeItem(item)
|
||||
}
|
||||
}
|
||||
|
||||
if let matches = self.matchesAPI.fetchMatches(for: "dota2") {
|
||||
self.generateMenu(for: matches)
|
||||
for match in matches {
|
||||
let newItem = NSMenuItem.init(title: match.league + match.team1name + match.team1score + ":" + match.team2score + match.team2name, action: nil, keyEquivalent: "")
|
||||
newItem.tag = 1
|
||||
newItem.target = self
|
||||
self.statusBar.addItem(newItem)
|
||||
}
|
||||
} else {
|
||||
let newItem = NSMenuItem.init(title: "There was an error receiving ongoing matches.", action: nil, keyEquivalent: "")
|
||||
newItem.tag = 1
|
||||
newItem.target = self
|
||||
self.statusBar.addItem(newItem)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@objc func updateView() {
|
||||
|
||||
22
LiquipediaMenuTests/Info.plist
Normal file
22
LiquipediaMenuTests/Info.plist
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
</plist>
|
||||
33
LiquipediaMenuTests/LiquipediaMenuTests.swift
Normal file
33
LiquipediaMenuTests/LiquipediaMenuTests.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// LiquipediaMenuTests.swift
|
||||
// LiquipediaMenuTests
|
||||
//
|
||||
// Created by Felix Förtsch on 01.01.19.
|
||||
// Copyright © 2019 Felix Förtsch. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
class LiquipediaMenuTests: XCTestCase {
|
||||
|
||||
override func setUp() {
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
func testExample() {
|
||||
// This is an example of a functional test case.
|
||||
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
||||
}
|
||||
|
||||
func testPerformanceExample() {
|
||||
// This is an example of a performance test case.
|
||||
self.measure {
|
||||
// Put the code you want to measure the time of here.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
33
LiquipediaMenuTests/MatchesAPITests.swift
Normal file
33
LiquipediaMenuTests/MatchesAPITests.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// MatchesAPITests.swift
|
||||
// LiquipediaMenuTests
|
||||
//
|
||||
// Created by Felix Förtsch on 01.01.19.
|
||||
// Copyright © 2019 Felix Förtsch. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
class MatchesAPITests: XCTestCase {
|
||||
|
||||
override func setUp() {
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
func testExample() {
|
||||
// This is an example of a functional test case.
|
||||
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
||||
}
|
||||
|
||||
func testPerformanceExample() {
|
||||
// This is an example of a performance test case.
|
||||
self.measure {
|
||||
// Put the code you want to measure the time of here.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user