From 7e28b2b3754121c26d5b9cf0338f9cd123b0385d Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Fri, 14 Jun 2019 20:27:24 +0200 Subject: [PATCH] addded about window --- Stats.xcodeproj/project.pbxproj | 4 + Stats/AppDelegate.swift | 27 ++++ Stats/MenuBar.swift | 10 ++ Stats/Supporting Files/About.storyboard | 183 ++++++++++++++++++++++++ 4 files changed, 224 insertions(+) create mode 100644 Stats/Supporting Files/About.storyboard diff --git a/Stats.xcodeproj/project.pbxproj b/Stats.xcodeproj/project.pbxproj index f7169d29..c32ab0d9 100755 --- a/Stats.xcodeproj/project.pbxproj +++ b/Stats.xcodeproj/project.pbxproj @@ -27,6 +27,7 @@ 9AFA402822AE49A200FE90BC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9AFA402622AE49A200FE90BC /* Main.storyboard */; }; 9AFA402F22AE49AE00FE90BC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AFA402E22AE49AE00FE90BC /* AppDelegate.swift */; }; 9AFA403022AE49DD00FE90BC /* StatsLauncher.app in Copy Files */ = {isa = PBXBuildFile; fileRef = 9AFA401E22AE49A100FE90BC /* StatsLauncher.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + 9AFFCB3B22B3FD0500B0E6D8 /* About.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9AFFCB3A22B3FD0500B0E6D8 /* About.storyboard */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -71,6 +72,7 @@ 9AFA402922AE49A200FE90BC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 9AFA402A22AE49A200FE90BC /* StatsLauncher.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = StatsLauncher.entitlements; sourceTree = ""; }; 9AFA402E22AE49AE00FE90BC /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 9AFFCB3A22B3FD0500B0E6D8 /* About.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = About.storyboard; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -126,6 +128,7 @@ isa = PBXGroup; children = ( 9A6CFC0022A1C9F5001E782D /* Assets.xcassets */, + 9AFFCB3A22B3FD0500B0E6D8 /* About.storyboard */, 9A1410FE229E721200D29793 /* Main.storyboard */, 9A141101229E721200D29793 /* Info.plist */, 9A141102229E721200D29793 /* Stats.entitlements */, @@ -286,6 +289,7 @@ files = ( 9A7B8F5B22A290A200DEB352 /* CPU.xib in Resources */, 9A6CFC0122A1C9F5001E782D /* Assets.xcassets in Resources */, + 9AFFCB3B22B3FD0500B0E6D8 /* About.storyboard in Resources */, 9A7B8F6722A2C1B900DEB352 /* Disk.xib in Resources */, 9A7B8F6522A2C19D00DEB352 /* Memory.xib in Resources */, 9A141100229E721200D29793 /* Main.storyboard in Resources */, diff --git a/Stats/AppDelegate.swift b/Stats/AppDelegate.swift index ab732e83..ccfd8469 100755 --- a/Stats/AppDelegate.swift +++ b/Stats/AppDelegate.swift @@ -54,3 +54,30 @@ class AppDelegate: NSObject, NSApplicationDelegate { } } } + +class AboutVC: NSViewController { + @IBOutlet weak var versionLabel: NSTextField! + + override func viewDidLoad() { + super.viewDidLoad() + self.view.wantsLayer = true + } + + @IBAction func openLink(_ sender: Any) { + NSWorkspace.shared.open(URL(string: "https://github.com/exelban/stats")!) + } + + @IBAction func exit(_ sender: Any) { + self.view.window?.close() + } + + override func awakeFromNib() { + if self.view.layer != nil { + self.view.window?.backgroundColor = .white + self.view.layer?.backgroundColor = .white + + let versionNumber = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String + versionLabel.stringValue = "Version \(versionNumber)" + } + } +} diff --git a/Stats/MenuBar.swift b/Stats/MenuBar.swift index a367a5ab..39989158 100644 --- a/Stats/MenuBar.swift +++ b/Stats/MenuBar.swift @@ -64,11 +64,21 @@ class MenuBar { menu.addItem(preferences) menu.addItem(NSMenuItem.separator()) + let aboutMenu = NSMenuItem(title: "About Stats", action: #selector(openAbout), keyEquivalent: "") + aboutMenu.target = self + menu.addItem(aboutMenu) menu.addItem(NSMenuItem(title: "Quit Stats", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "")) return menu } + @objc func openAbout(_ sender : NSMenuItem) { + let aboutVC: NSWindowController? = NSStoryboard(name: "About", bundle: nil).instantiateController(withIdentifier: "AboutVC") as? NSWindowController + aboutVC?.window?.center() + aboutVC?.window?.level = .floating + aboutVC!.showWindow(self) + } + @objc func toggleMenu(_ sender : NSMenuItem) { let launcherId = "eu.exelban.StatsLauncher" let status = sender.state != NSControl.StateValue.on diff --git a/Stats/Supporting Files/About.storyboard b/Stats/Supporting Files/About.storyboard new file mode 100644 index 00000000..ca836869 --- /dev/null +++ b/Stats/Supporting Files/About.storyboard @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +