Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
vouv committed Dec 31, 2020
1 parent 979c600 commit 72527c8
Show file tree
Hide file tree
Showing 16 changed files with 225 additions and 27 deletions.
10 changes: 9 additions & 1 deletion SrunBar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -44,6 +46,8 @@
/* Begin PBXFileReference section */
0E4165432593AC4E00B48231 /* SrunAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SrunAPI.swift; sourceTree = "<group>"; };
0E4165482595114200B48231 /* Hash.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Hash.swift; sourceTree = "<group>"; };
0E731AF0259E44180032ECD4 /* UpdateWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = UpdateWindow.xib; sourceTree = "<group>"; };
0E731AF5259E44C80032ECD4 /* UpdateWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateWindow.swift; sourceTree = "<group>"; };
0E76EEBD2597103900A24BC8 /* model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = model.swift; sourceTree = "<group>"; };
0E76EECE2597175300A24BC8 /* Request.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Request.swift; sourceTree = "<group>"; };
0E76EEEE2597AEB700A24BC8 /* AboutWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutWindow.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
);
Expand Down Expand Up @@ -220,7 +226,7 @@
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1230;
ORGANIZATIONNAME = Etsy;
ORGANIZATIONNAME = Vouv;
TargetAttributes = {
A2DEB1491BC9980E004AAEB3 = {
CreatedOnToolsVersion = 7.0.1;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion SrunBar/AboutWindow.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
//
// AboutWindow.swift
// SrunBar
//
// Created by vouv on 2021/1/1.
// Copyright © 2021 Vouv. All rights reserved.
//

import Cocoa

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" }
Expand Down
2 changes: 1 addition & 1 deletion SrunBar/AboutWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</constraints>
</view>
<connections>
<outlet property="delegate" destination="-2" id="Lkf-8i-QkW"/>
<outlet property="delegate" destination="-2" id="i2N-vn-MiK"/>
</connections>
<point key="canvasLocation" x="137" y="171"/>
</window>
Expand Down
16 changes: 12 additions & 4 deletions SrunBar/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// AppDelegate.swift
// SrunBar
//
// Created by vouv on 2021/1/1.
// Copyright © 2021 Vouv. All rights reserved.
//

import Cocoa

Expand All @@ -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
}



}

17 changes: 12 additions & 5 deletions SrunBar/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,29 @@
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="9Bi-wd-Y5L"/>
<menuItem title="账号设置..." keyEquivalent="," id="gjQ-IK-ro7">
<connections>
<action selector="configClicked:" target="sS3-a3-GGc" id="tJf-2E-Oae"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="GMS-xY-bdJ"/>
<menuItem title="Info" id="d2M-wS-o1T">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem isSeparatorItem="YES" id="nf3-SP-UCH"/>
<menuItem title="账号设置" id="gjQ-IK-ro7">
<menuItem title="关于..." id="qwZ-1E-LEa">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="configClicked:" target="sS3-a3-GGc" id="tJf-2E-Oae"/>
<action selector="aboutClicked:" target="sS3-a3-GGc" id="b4U-I2-a2y"/>
</connections>
</menuItem>
<menuItem title="关于" keyEquivalent="a" id="qwZ-1E-LEa">
<menuItem title="检查更新..." keyEquivalent="u" id="dq6-WX-TYa">
<connections>
<action selector="aboutClicked:" target="sS3-a3-GGc" id="b4U-I2-a2y"/>
<action selector="updateClicked:" target="sS3-a3-GGc" id="lzb-is-TMb"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="tro-Jg-9xJ"/>
<menuItem title="退出" keyEquivalent="q" id="k4N-2W-XAy">
<menuItem title="退出 Srun" keyEquivalent="q" id="k4N-2W-XAy">
<connections>
<action selector="quitClicked:" target="sS3-a3-GGc" id="Eue-jt-z1Q"/>
</connections>
Expand Down
27 changes: 19 additions & 8 deletions SrunBar/ConfigWindow.swift
Original file line number Diff line number Diff line change
@@ -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!
Expand All @@ -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()
}

Expand All @@ -35,6 +46,6 @@ class ConfigWindow: NSWindowController, NSWindowDelegate {
}

func windowWillClose(_ notification: Notification) {

}
}
7 changes: 7 additions & 0 deletions SrunBar/InfoView.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// InfoView.swift
// SrunBar
//
// Created by vouv on 2021/1/1.
// Copyright © 2021 Vouv. All rights reserved.
//

import Cocoa

Expand Down
31 changes: 24 additions & 7 deletions SrunBar/StatusMenuController.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// StatusMenuController.swift
// SrunBar
//
// Created by vouv on 2021/1/1.
// Copyright © 2021 Vouv. All rights reserved.
//

import Cocoa

Expand All @@ -9,6 +16,7 @@ class StatusMenuController: NSObject, NSMenuDelegate {

var configWindow: ConfigWindow!
var aboutWindow: AboutWindow!
var updateWindow: UpdateWindow!

@IBOutlet weak var loginItem: NSMenuItem!

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)")
Expand Down Expand Up @@ -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()
Expand All @@ -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)
}
Expand Down
29 changes: 29 additions & 0 deletions SrunBar/UpdateWindow.swift
Original file line number Diff line number Diff line change
@@ -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) {

}

}
62 changes: 62 additions & 0 deletions SrunBar/UpdateWindow.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="17701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17701"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="UpdateWindow" customModule="SrunBar" customModuleProvider="target">
<connections>
<outlet property="progressBar" destination="QFg-b5-cbZ" id="meh-y8-6W4"/>
<outlet property="window" destination="QvC-M9-y7g" id="c9W-pm-b1G"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="正在检查更新" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="QvC-M9-y7g">
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="410" height="118"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="900"/>
<view key="contentView" wantsLayer="YES" id="EiT-Mj-1SZ">
<rect key="frame" x="0.0" y="0.0" width="410" height="118"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="mrg-bD-8Op">
<rect key="frame" x="20" y="50" width="48" height="18"/>
<constraints>
<constraint firstAttribute="width" constant="48" id="95e-2g-hwA"/>
<constraint firstAttribute="height" constant="18" id="XRi-HE-LBe"/>
</constraints>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="statusIcon" id="li7-om-MnZ"/>
</imageView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="afR-TM-FhD">
<rect key="frame" x="163" y="91" width="4" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="clipping" id="sSX-M7-QYg">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<progressIndicator fixedFrame="YES" maxValue="100" indeterminate="YES" style="bar" translatesAutoresizingMaskIntoConstraints="NO" id="QFg-b5-cbZ">
<rect key="frame" x="81" y="49" width="248" height="20"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</progressIndicator>
</subviews>
<constraints>
<constraint firstItem="mrg-bD-8Op" firstAttribute="leading" secondItem="EiT-Mj-1SZ" secondAttribute="leading" constant="20" id="6ah-zp-ozW"/>
<constraint firstItem="mrg-bD-8Op" firstAttribute="centerY" secondItem="EiT-Mj-1SZ" secondAttribute="centerY" id="a7L-cJ-lB8"/>
</constraints>
</view>
<connections>
<outlet property="delegate" destination="-2" id="w7b-gh-yV4"/>
</connections>
<point key="canvasLocation" x="-58" y="138"/>
</window>
</objects>
<resources>
<image name="statusIcon" width="27" height="27"/>
</resources>
</document>
7 changes: 7 additions & 0 deletions SrunBar/srun/Hash.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// Hash.swift
// SrunBar
//
// Created by vouv on 2021/1/1.
// Copyright © 2021 Vouv. All rights reserved.
//

import Cocoa
import CryptoKit
Expand Down
Loading

0 comments on commit 72527c8

Please sign in to comment.