From 72527c823225f1e09bbf48e4d0873061d5b0bb9e Mon Sep 17 00:00:00 2001 From: vouv Date: Fri, 1 Jan 2021 02:50:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SrunBar.xcodeproj/project.pbxproj | 10 ++++- SrunBar/AboutWindow.swift | 9 ++++- SrunBar/AboutWindow.xib | 2 +- SrunBar/AppDelegate.swift | 16 ++++++-- SrunBar/Base.lproj/MainMenu.xib | 17 +++++--- SrunBar/ConfigWindow.swift | 27 +++++++++---- SrunBar/InfoView.swift | 7 ++++ SrunBar/StatusMenuController.swift | 31 +++++++++++---- SrunBar/UpdateWindow.swift | 29 ++++++++++++++ SrunBar/UpdateWindow.xib | 62 +++++++++++++++++++++++++++++ SrunBar/srun/Hash.swift | 7 ++++ SrunBar/srun/Request.swift | 7 ++++ SrunBar/srun/SrunAPI.swift | 7 ++++ SrunBar/srun/model.swift | 7 ++++ SrunBarTests/SrunBarTests.swift | 7 ++++ SrunBarUITests/SrunBarUITests.swift | 7 ++++ 16 files changed, 225 insertions(+), 27 deletions(-) create mode 100644 SrunBar/UpdateWindow.swift create mode 100644 SrunBar/UpdateWindow.xib diff --git a/SrunBar.xcodeproj/project.pbxproj b/SrunBar.xcodeproj/project.pbxproj index 48764ab..9104f11 100644 --- a/SrunBar.xcodeproj/project.pbxproj +++ b/SrunBar.xcodeproj/project.pbxproj @@ -9,6 +9,8 @@ /* Begin PBXBuildFile section */ 0E4165442593AC4E00B48231 /* SrunAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E4165432593AC4E00B48231 /* SrunAPI.swift */; }; 0E4165492595114200B48231 /* Hash.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E4165482595114200B48231 /* Hash.swift */; }; + 0E731AF1259E44180032ECD4 /* UpdateWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0E731AF0259E44180032ECD4 /* UpdateWindow.xib */; }; + 0E731AF6259E44C80032ECD4 /* UpdateWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E731AF5259E44C80032ECD4 /* UpdateWindow.swift */; }; 0E76EEBE2597103900A24BC8 /* model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E76EEBD2597103900A24BC8 /* model.swift */; }; 0E76EECF2597175300A24BC8 /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E76EECE2597175300A24BC8 /* Request.swift */; }; 0E76EEEF2597AEB700A24BC8 /* AboutWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E76EEEE2597AEB700A24BC8 /* AboutWindow.swift */; }; @@ -44,6 +46,8 @@ /* Begin PBXFileReference section */ 0E4165432593AC4E00B48231 /* SrunAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SrunAPI.swift; sourceTree = ""; }; 0E4165482595114200B48231 /* Hash.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Hash.swift; sourceTree = ""; }; + 0E731AF0259E44180032ECD4 /* UpdateWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = UpdateWindow.xib; sourceTree = ""; }; + 0E731AF5259E44C80032ECD4 /* UpdateWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateWindow.swift; sourceTree = ""; }; 0E76EEBD2597103900A24BC8 /* model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = model.swift; sourceTree = ""; }; 0E76EECE2597175300A24BC8 /* Request.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Request.swift; sourceTree = ""; }; 0E76EEEE2597AEB700A24BC8 /* AboutWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutWindow.swift; sourceTree = ""; }; @@ -130,9 +134,11 @@ 0E76EEEE2597AEB700A24BC8 /* AboutWindow.swift */, 0E76EEBC2597102C00A24BC8 /* srun */, A21862A01BCDEA2E00770E87 /* ConfigWindow.swift */, + 0E731AF5259E44C80032ECD4 /* UpdateWindow.swift */, A2DEB1511BC9980E004AAEB3 /* MainMenu.xib */, A21862A11BCDEA2E00770E87 /* ConfigWindow.xib */, 0E76EEF62597AFC900A24BC8 /* AboutWindow.xib */, + 0E731AF0259E44180032ECD4 /* UpdateWindow.xib */, A2DEB14F1BC9980E004AAEB3 /* Assets.xcassets */, A2DEB1541BC9980E004AAEB3 /* Info.plist */, ); @@ -220,7 +226,7 @@ isa = PBXProject; attributes = { LastUpgradeCheck = 1230; - ORGANIZATIONNAME = Etsy; + ORGANIZATIONNAME = Vouv; TargetAttributes = { A2DEB1491BC9980E004AAEB3 = { CreatedOnToolsVersion = 7.0.1; @@ -267,6 +273,7 @@ A2DEB1501BC9980E004AAEB3 /* Assets.xcassets in Resources */, A21862A31BCDEA2E00770E87 /* ConfigWindow.xib in Resources */, A2DEB1531BC9980E004AAEB3 /* MainMenu.xib in Resources */, + 0E731AF1259E44180032ECD4 /* UpdateWindow.xib in Resources */, 0E76EEF72597AFC900A24BC8 /* AboutWindow.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -300,6 +307,7 @@ A2DEB14E1BC9980E004AAEB3 /* AppDelegate.swift in Sources */, 0E76EECF2597175300A24BC8 /* Request.swift in Sources */, 0E76EEBE2597103900A24BC8 /* model.swift in Sources */, + 0E731AF6259E44C80032ECD4 /* UpdateWindow.swift in Sources */, A2B4247D1BCDE3D300887CB2 /* InfoView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/SrunBar/AboutWindow.swift b/SrunBar/AboutWindow.swift index 1a7a1a6..816e5c4 100644 --- a/SrunBar/AboutWindow.swift +++ b/SrunBar/AboutWindow.swift @@ -1,3 +1,10 @@ +// +// AboutWindow.swift +// SrunBar +// +// Created by vouv on 2021/1/1. +// Copyright © 2021 Vouv. All rights reserved. +// import Cocoa @@ -5,7 +12,7 @@ class AboutWindow: NSWindowController, NSWindowDelegate { @IBOutlet weak var versionLabel: NSTextField! - let version = "v0.2.7" + let version = "v0.2.8" let link = "https://github.com/vouv/SrunBar" override var windowNibName : String! { "AboutWindow" } diff --git a/SrunBar/AboutWindow.xib b/SrunBar/AboutWindow.xib index a083ccd..caceeff 100644 --- a/SrunBar/AboutWindow.xib +++ b/SrunBar/AboutWindow.xib @@ -64,7 +64,7 @@ - + diff --git a/SrunBar/AppDelegate.swift b/SrunBar/AppDelegate.swift index d4a07e6..e653d1a 100644 --- a/SrunBar/AppDelegate.swift +++ b/SrunBar/AppDelegate.swift @@ -1,3 +1,10 @@ +// +// AppDelegate.swift +// SrunBar +// +// Created by vouv on 2021/1/1. +// Copyright © 2021 Vouv. All rights reserved. +// import Cocoa @@ -6,15 +13,16 @@ class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ aNotification: Notification) { // Insert code here to initialize your application + // check update + // 每天执行一次更新 +// let al = NSAlert.init(); +// al.messageText = "update!" +// al.runModal() } - - func applicationWillTerminate(_ aNotification: Notification) { // Insert code here to tear down your application } - - } diff --git a/SrunBar/Base.lproj/MainMenu.xib b/SrunBar/Base.lproj/MainMenu.xib index ce63342..6476e6a 100644 --- a/SrunBar/Base.lproj/MainMenu.xib +++ b/SrunBar/Base.lproj/MainMenu.xib @@ -36,22 +36,29 @@ + + + + + + - + + - + - + - + - + diff --git a/SrunBar/ConfigWindow.swift b/SrunBar/ConfigWindow.swift index 3aa8258..60f2434 100644 --- a/SrunBar/ConfigWindow.swift +++ b/SrunBar/ConfigWindow.swift @@ -1,12 +1,15 @@ +// +// ConfigWindow.swift +// SrunBar +// +// Created by vouv on 2021/1/1. +// Copyright © 2021 Vouv. All rights reserved. +// import Cocoa -protocol PreferencesWindowDelegate { - func preferencesDidUpdate() -} class ConfigWindow: NSWindowController, NSWindowDelegate { -// var delegate: PreferencesWindowDelegate? @IBOutlet weak var usernameField: NSTextField! @IBOutlet weak var passwordField: NSSecureTextField! @@ -17,9 +20,17 @@ class ConfigWindow: NSWindowController, NSWindowDelegate { @IBAction func saveClicked(_ sender: NSButton) { let defaults = UserDefaults.standard - defaults.setValue(usernameField.stringValue, forKey: "username") - defaults.setValue(passwordField.stringValue, forKey: "password") -// delegate?.preferencesDidUpdate() + let username = usernameField.stringValue + let password = passwordField.stringValue + defaults.setValue(username, forKey: "username") + defaults.setValue(password, forKey: "password") + + if username != "" && password != "" { + // 执行登录 + DispatchQueue.global().async(){ + NotificationCenter.default.post(name: NSNotification.Name("login"), object: nil) + } + } self.window?.close() } @@ -35,6 +46,6 @@ class ConfigWindow: NSWindowController, NSWindowDelegate { } func windowWillClose(_ notification: Notification) { - + } } diff --git a/SrunBar/InfoView.swift b/SrunBar/InfoView.swift index 3f54dab..efc006f 100644 --- a/SrunBar/InfoView.swift +++ b/SrunBar/InfoView.swift @@ -1,3 +1,10 @@ +// +// InfoView.swift +// SrunBar +// +// Created by vouv on 2021/1/1. +// Copyright © 2021 Vouv. All rights reserved. +// import Cocoa diff --git a/SrunBar/StatusMenuController.swift b/SrunBar/StatusMenuController.swift index c22c294..6a6c22c 100644 --- a/SrunBar/StatusMenuController.swift +++ b/SrunBar/StatusMenuController.swift @@ -1,3 +1,10 @@ +// +// StatusMenuController.swift +// SrunBar +// +// Created by vouv on 2021/1/1. +// Copyright © 2021 Vouv. All rights reserved. +// import Cocoa @@ -9,6 +16,7 @@ class StatusMenuController: NSObject, NSMenuDelegate { var configWindow: ConfigWindow! var aboutWindow: AboutWindow! + var updateWindow: UpdateWindow! @IBOutlet weak var loginItem: NSMenuItem! @@ -37,6 +45,7 @@ class StatusMenuController: NSObject, NSMenuDelegate { // 两个基本页面 configWindow = ConfigWindow() aboutWindow = AboutWindow() + updateWindow = UpdateWindow() // 注册监听 NotificationCenter.default.addObserver(forName: NSNotification.Name("login"), object: nil, queue: nil) { (notice) in @@ -67,7 +76,7 @@ class StatusMenuController: NSObject, NSMenuDelegate { }else if let res = res { if res.access_token.count > 0 { self.notify(title: "登录成功", subtitle: "账号:\(res.username)") - }else if res.error_msg == "Arrearage users" { + }else if res.error_msg.contains("Arrearage users") { self.notify(title: "已欠费", subtitle: "登录失败") }else { self.notify(title: "登录异常", subtitle: "\(res.error_msg)") @@ -115,18 +124,22 @@ class StatusMenuController: NSObject, NSMenuDelegate { // 打开view自动更新info func menuWillOpen(_ menu: NSMenu) { - NotificationCenter.default.post(name: NSNotification.Name("info"), object: nil) + DispatchQueue.global().async(){ + NotificationCenter.default.post(name: NSNotification.Name("info"), object: nil) + } } - - + @IBAction func loginClicked(_ sender: NSMenuItem) { - NotificationCenter.default.post(name: NSNotification.Name("login"), object: nil) + DispatchQueue.global().async(){ + NotificationCenter.default.post(name: NSNotification.Name("login"), object: nil) + } } @IBAction func logoutClicked(_ sender: NSMenuItem) { - NotificationCenter.default.post(name: NSNotification.Name("logout"), object: nil) + DispatchQueue.global().async(){ + NotificationCenter.default.post(name: NSNotification.Name("logout"), object: nil) + } } - private func notify(title: String, subtitle: String) { let nty = NSUserNotification.init() @@ -148,6 +161,10 @@ class StatusMenuController: NSObject, NSMenuDelegate { NSApp.activate(ignoringOtherApps: true) } + @IBAction func updateClicked(_ sender: NSMenuItem) { + self.updateWindow.showWindow(nil) + NSApp.activate(ignoringOtherApps: true) + } @IBAction func quitClicked(_ sender: NSMenuItem) { NSApplication.shared.terminate(self) } diff --git a/SrunBar/UpdateWindow.swift b/SrunBar/UpdateWindow.swift new file mode 100644 index 0000000..8a7733e --- /dev/null +++ b/SrunBar/UpdateWindow.swift @@ -0,0 +1,29 @@ +// +// UpdateWindow.swift +// SrunBar +// +// Created by vouv on 2021/1/1. +// Copyright © 2021 Vouv. All rights reserved. +// + +import Cocoa + +class UpdateWindow: NSWindowController, NSWindowDelegate { + + @IBOutlet weak var progressBar: NSProgressIndicator! + + override var windowNibName : String! { "UpdateWindow" } + + override func windowDidLoad() { + super.windowDidLoad() + self.window?.center() + self.window?.makeKeyAndOrderFront(nil) + NSApp.activate(ignoringOtherApps: true) + self.progressBar.startAnimation(nil) + } + + func windowWillClose(_ notification: Notification) { + + } + +} diff --git a/SrunBar/UpdateWindow.xib b/SrunBar/UpdateWindow.xib new file mode 100644 index 0000000..bdd72fd --- /dev/null +++ b/SrunBar/UpdateWindow.xib @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SrunBar/srun/Hash.swift b/SrunBar/srun/Hash.swift index cb7c16b..81dc30f 100644 --- a/SrunBar/srun/Hash.swift +++ b/SrunBar/srun/Hash.swift @@ -1,3 +1,10 @@ +// +// Hash.swift +// SrunBar +// +// Created by vouv on 2021/1/1. +// Copyright © 2021 Vouv. All rights reserved. +// import Cocoa import CryptoKit diff --git a/SrunBar/srun/Request.swift b/SrunBar/srun/Request.swift index 93fbd0c..b156c53 100644 --- a/SrunBar/srun/Request.swift +++ b/SrunBar/srun/Request.swift @@ -1,3 +1,10 @@ +// +// Request.swift +// SrunBar +// +// Created by vouv on 2021/1/1. +// Copyright © 2021 Vouv. All rights reserved. +// import Cocoa diff --git a/SrunBar/srun/SrunAPI.swift b/SrunBar/srun/SrunAPI.swift index 95593b2..0dd9502 100644 --- a/SrunBar/srun/SrunAPI.swift +++ b/SrunBar/srun/SrunAPI.swift @@ -1,3 +1,10 @@ +// +// SrunAPI.swift +// SrunBar +// +// Created by vouv on 2021/1/1. +// Copyright © 2021 Vouv. All rights reserved. +// import Cocoa diff --git a/SrunBar/srun/model.swift b/SrunBar/srun/model.swift index 1cbc7e1..47ae139 100644 --- a/SrunBar/srun/model.swift +++ b/SrunBar/srun/model.swift @@ -1,3 +1,10 @@ +// +// model.swift +// SrunBar +// +// Created by vouv on 2021/1/1. +// Copyright © 2021 Vouv. All rights reserved. +// import Cocoa diff --git a/SrunBarTests/SrunBarTests.swift b/SrunBarTests/SrunBarTests.swift index 5ec847b..3c562d5 100644 --- a/SrunBarTests/SrunBarTests.swift +++ b/SrunBarTests/SrunBarTests.swift @@ -1,3 +1,10 @@ +// +// SrunBarTests.swift +// SrunBarTests +// +// Created by vouv on 2021/1/1. +// Copyright © 2021 Vouv. All rights reserved. +// import XCTest @testable import SrunBar diff --git a/SrunBarUITests/SrunBarUITests.swift b/SrunBarUITests/SrunBarUITests.swift index 3af178c..3cf4de2 100644 --- a/SrunBarUITests/SrunBarUITests.swift +++ b/SrunBarUITests/SrunBarUITests.swift @@ -1,3 +1,10 @@ +// +// SrunBarUITests.swift +// SrunBarUITests +// +// Created by vouv on 2021/1/1. +// Copyright © 2021 Vouv. All rights reserved. +// import XCTest