Skip to content

Commit

Permalink
Updater.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrFq1 committed Jul 3, 2022
1 parent 84de92d commit b3a39b9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
25 changes: 25 additions & 0 deletions ClashX/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Cocoa
import LetsMove
import RxCocoa
import RxSwift
import SwiftyJSON

private let statusItemLengthWithSpeed: CGFloat = 72

Expand Down Expand Up @@ -792,6 +793,30 @@ extension AppDelegate {
sender.state = newState
MenuItemFactory.hideUnselectable = newState.rawValue
}

@IBAction func checkForUpdate(_ sender: NSMenuItem) {
let unc = NSUserNotificationCenter.default
AF.request("https://api.github.com/repos/MetaCubeX/ClashX.Meta/releases/latest").responseString {
guard $0.error == nil,
let data = $0.data,
let tagName = try? JSON(data: data)["tag_name"].string else {
unc.postUpdateNotice(msg: "Some thing failed.")
return
}

if tagName != AppVersionUtil.currentVersion {
let alert = NSAlert()
alert.messageText = "Open github release page to download \(tagName)"
alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
if alert.runModal() == .alertFirstButtonReturn {
NSWorkspace.shared.open(.init(string: "https://github.com/MetaCubeX/ClashX.Meta/releases/latest")!)
}
} else {
unc.postUpdateNotice(msg: "No new release found.")
}
}
}
}

// MARK: crash hanlder
Expand Down
34 changes: 17 additions & 17 deletions ClashX/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="19162" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="19162"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -171,7 +171,7 @@
<outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/>
</connections>
</application>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="ClashX" customModuleProvider="target">
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="ClashX_Meta" customModuleProvider="target">
<connections>
<outlet property="allowFromLanMenuItem" destination="Vz8-7n-vx6" id="Fzz-EG-huC"/>
<outlet property="apiPortMenuItem" destination="hwG-qf-DeZ" id="d6K-i7-yCo"/>
Expand Down Expand Up @@ -381,7 +381,7 @@
<menuItem title="Check Update" id="p0T-J8-Emx">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="checkForUpdates:" target="fth-rt-saN" id="gaF-35-d7h"/>
<action selector="checkForUpdate:" target="Voe-Tx-rLC" id="y8T-Su-dgd"/>
</connections>
</menuItem>
<menuItem title="Log level" id="3Da-fL-Mzr">
Expand Down Expand Up @@ -480,7 +480,7 @@
<!--About View Controller-->
<scene sceneID="bW6-wi-r8Q">
<objects>
<viewController showSeguePresentationStyle="single" id="UWQ-O3-RVk" customClass="AboutViewController" customModule="ClashX" customModuleProvider="target" sceneMemberID="viewController">
<viewController showSeguePresentationStyle="single" id="UWQ-O3-RVk" customClass="AboutViewController" customModule="ClashX_Meta" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="JCR-G0-H6V">
<rect key="frame" x="0.0" y="0.0" width="451" height="300"/>
<autoresizingMask key="autoresizingMask"/>
Expand Down Expand Up @@ -556,7 +556,7 @@
<stackView distribution="fill" orientation="vertical" alignment="leading" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="BaZ-rB-g4s">
<rect key="frame" x="118" y="0.0" width="237" height="40"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="q4m-SB-uHV" customClass="HyperlinkTextField" customModule="ClashX" customModuleProvider="target">
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="q4m-SB-uHV" customClass="HyperlinkTextField" customModule="ClashX_Meta" customModuleProvider="target">
<rect key="frame" x="-2" y="24" width="221" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="https://github.com/Dreamacro/clash" id="Bej-j7-KKV">
<font key="font" metaFont="system"/>
Expand All @@ -570,7 +570,7 @@
<userDefinedRuntimeAttribute type="string" keyPath="href" value="https://github.com/Dreamacro/clash"/>
</userDefinedRuntimeAttributes>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="bSi-kz-Dkf" customClass="HyperlinkTextField" customModule="ClashX" customModuleProvider="target">
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="bSi-kz-Dkf" customClass="HyperlinkTextField" customModule="ClashX_Meta" customModuleProvider="target">
<rect key="frame" x="-2" y="0.0" width="241" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="https://github.com/yichengchen/clashX" id="9ox-Fc-Wk3">
<font key="font" metaFont="system"/>
Expand Down Expand Up @@ -653,7 +653,7 @@
<!--Remote Configs-->
<scene sceneID="lXv-k7-YEi">
<objects>
<viewController title="Remote Configs" identifier="RemoteConfigViewController" storyboardIdentifier="RemoteConfigViewController" showSeguePresentationStyle="single" id="6WI-Hi-v9j" customClass="RemoteConfigViewController" customModule="ClashX" customModuleProvider="target" sceneMemberID="viewController">
<viewController title="Remote Configs" identifier="RemoteConfigViewController" storyboardIdentifier="RemoteConfigViewController" showSeguePresentationStyle="single" id="6WI-Hi-v9j" customClass="RemoteConfigViewController" customModule="ClashX_Meta" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="BIo-GY-n0C">
<rect key="frame" x="0.0" y="0.0" width="403" height="256"/>
<autoresizingMask key="autoresizingMask"/>
Expand Down Expand Up @@ -684,7 +684,7 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView identifier="urlCell" id="Nfz-jY-8Of">
<rect key="frame" x="11" y="1" width="181" height="30"/>
<rect key="frame" x="1" y="1" width="181" height="30"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" tag="1" translatesAutoresizingMaskIntoConstraints="NO" id="4q7-nk-ts1">
Expand Down Expand Up @@ -723,7 +723,7 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView identifier="nameCell" id="nJ2-CL-UMO">
<rect key="frame" x="195" y="1" width="86" height="17"/>
<rect key="frame" x="185" y="1" width="86" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" tag="1" translatesAutoresizingMaskIntoConstraints="NO" id="ma1-VU-D1q">
Expand Down Expand Up @@ -762,7 +762,7 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView identifier="timeCell" id="EV1-my-fwa">
<rect key="frame" x="284" y="1" width="56" height="17"/>
<rect key="frame" x="274" y="1" width="56" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" tag="1" translatesAutoresizingMaskIntoConstraints="NO" id="giF-oe-BsQ">
Expand Down Expand Up @@ -885,9 +885,9 @@
<!--External Control-->
<scene sceneID="TO5-jN-VsZ">
<objects>
<viewController title="External Manager" identifier="ExternalControlViewController" storyboardIdentifier="ExternalControlViewController" showSeguePresentationStyle="single" id="s6y-wL-pnr" userLabel="External Control" customClass="ExternalControlViewController" customModule="ClashX" customModuleProvider="target" sceneMemberID="viewController">
<viewController title="External Manager" identifier="ExternalControlViewController" storyboardIdentifier="ExternalControlViewController" showSeguePresentationStyle="single" id="s6y-wL-pnr" userLabel="External Control" customClass="ExternalControlViewController" customModule="ClashX_Meta" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="Gao-fa-Dwr">
<rect key="frame" x="0.0" y="0.0" width="515" height="256"/>
<rect key="frame" x="0.0" y="0.0" width="515" height="268"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<scrollView autohidesScrollers="YES" horizontalLineScroll="30" horizontalPageScroll="10" verticalLineScroll="30" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="h2z-Vu-j5M">
Expand Down Expand Up @@ -919,7 +919,7 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView identifier="nameCell" id="8mR-Pw-M5O">
<rect key="frame" x="11" y="1" width="193" height="28"/>
<rect key="frame" x="1" y="1" width="193" height="28"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" tag="1" translatesAutoresizingMaskIntoConstraints="NO" id="6q3-XW-4SC">
Expand Down Expand Up @@ -964,7 +964,7 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView identifier="urlCell" id="hgu-Ez-7fj">
<rect key="frame" x="207" y="1" width="188" height="28"/>
<rect key="frame" x="197" y="1" width="188" height="28"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" tag="1" translatesAutoresizingMaskIntoConstraints="NO" id="rfv-RN-Pkz">
Expand Down Expand Up @@ -1006,7 +1006,7 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView identifier="secretCell" id="1lj-rr-UvU">
<rect key="frame" x="398" y="1" width="54" height="22"/>
<rect key="frame" x="388" y="1" width="54" height="22"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" tag="1" translatesAutoresizingMaskIntoConstraints="NO" id="T9c-i1-UF2">
Expand Down Expand Up @@ -1057,7 +1057,7 @@
</tableHeaderView>
</scrollView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Apx-gL-RAm">
<rect key="frame" x="18" y="220" width="108" height="16"/>
<rect key="frame" x="18" y="232" width="108" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="External Controls" id="9gE-NX-2wJ">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
Expand Down
4 changes: 4 additions & 0 deletions ClashX/Extensions/NSUserNotificationCenter+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ extension NSUserNotificationCenter {
post(title: NSLocalizedString("System Proxy Changed", comment: ""),
info: NSLocalizedString("Proxy settings are changed by another process. ClashX is no longer the default system proxy.", comment: ""), notiOnly: true)
}

func postUpdateNotice(msg: String) {
postNotificationAlert(title: "Update ClashX Meta", info: msg)
}
}

class UserNotificationCenterDelegate: NSObject, NSUserNotificationCenterDelegate, UNUserNotificationCenterDelegate {
Expand Down

0 comments on commit b3a39b9

Please sign in to comment.