Skip to content

Commit

Permalink
Improve: Config Generator support keyboard shortcut and rc4md5/chacha…
Browse files Browse the repository at this point in the history
…20 encrypt methods. Feature: add auto start at login
  • Loading branch information
yichengchen committed Jun 14, 2018
1 parent 67a5cd2 commit 302b683
Show file tree
Hide file tree
Showing 12 changed files with 211 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Country.mmdb
Carthage
2 changes: 2 additions & 0 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github "sindresorhus/LaunchAtLogin"

1 change: 1 addition & 0 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github "sindresorhus/LaunchAtLogin" "v2.1.0"
72 changes: 68 additions & 4 deletions ClashX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
4989F98020D01C8F0001E564 /* clash.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4989F97E20D01C8F0001E564 /* clash.a */; };
4989F98420D02D200001E564 /* Country.mmdb in Resources */ = {isa = PBXBuildFile; fileRef = 4989F98320D02D200001E564 /* Country.mmdb */; };
4989F98B20D0AD800001E564 /* SampleConfigViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4989F98920D0AD800001E564 /* SampleConfigViewController.swift */; };
4989F98C20D0AD800001E564 /* SampleConfigViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4989F98A20D0AD800001E564 /* SampleConfigViewController.xib */; };
4989F98E20D0AE990001E564 /* sampleConfig.ini in Resources */ = {isa = PBXBuildFile; fileRef = 4989F98D20D0AE990001E564 /* sampleConfig.ini */; };
4997732520D251A60009B136 /* SWBApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = 4997732320D251A60009B136 /* SWBApplication.m */; };
4997735920D25AB10009B136 /* LaunchAtLogin.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4997735820D25AB10009B136 /* LaunchAtLogin.framework */; };
49CF3B2120CD7463001EBF94 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49CF3B2020CD7463001EBF94 /* AppDelegate.swift */; };
49CF3B2520CD7465001EBF94 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 49CF3B2420CD7465001EBF94 /* Assets.xcassets */; };
49CF3B2820CD7465001EBF94 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 49CF3B2620CD7465001EBF94 /* Main.storyboard */; };
Expand Down Expand Up @@ -41,8 +42,10 @@
4989F97F20D01C8F0001E564 /* clash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = clash.h; sourceTree = "<group>"; };
4989F98320D02D200001E564 /* Country.mmdb */ = {isa = PBXFileReference; lastKnownFileType = file; path = Country.mmdb; sourceTree = "<group>"; };
4989F98920D0AD800001E564 /* SampleConfigViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleConfigViewController.swift; sourceTree = "<group>"; };
4989F98A20D0AD800001E564 /* SampleConfigViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SampleConfigViewController.xib; sourceTree = "<group>"; };
4989F98D20D0AE990001E564 /* sampleConfig.ini */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = sampleConfig.ini; sourceTree = "<group>"; };
4997732320D251A60009B136 /* SWBApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWBApplication.m; sourceTree = "<group>"; };
4997732420D251A60009B136 /* SWBApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWBApplication.h; sourceTree = "<group>"; };
4997735820D25AB10009B136 /* LaunchAtLogin.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = LaunchAtLogin.framework; path = Carthage/Build/Mac/LaunchAtLogin.framework; sourceTree = "<group>"; };
49CF3B1D20CD7463001EBF94 /* ClashX.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ClashX.app; sourceTree = BUILT_PRODUCTS_DIR; };
49CF3B2020CD7463001EBF94 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
49CF3B2420CD7465001EBF94 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand All @@ -67,6 +70,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
4997735920D25AB10009B136 /* LaunchAtLogin.framework in Frameworks */,
4989F98020D01C8F0001E564 /* clash.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -78,16 +82,33 @@
isa = PBXGroup;
children = (
4989F98920D0AD800001E564 /* SampleConfigViewController.swift */,
4989F98A20D0AD800001E564 /* SampleConfigViewController.xib */,
);
path = ViewControllers;
sourceTree = "<group>";
};
4997732220D251A60009B136 /* Basic */ = {
isa = PBXGroup;
children = (
4997732320D251A60009B136 /* SWBApplication.m */,
4997732420D251A60009B136 /* SWBApplication.h */,
);
path = Basic;
sourceTree = "<group>";
};
4997735720D25AB00009B136 /* Frameworks */ = {
isa = PBXGroup;
children = (
4997735820D25AB10009B136 /* LaunchAtLogin.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
49CF3B1420CD7463001EBF94 = {
isa = PBXGroup;
children = (
49CF3B1F20CD7463001EBF94 /* ClashX */,
49CF3B1E20CD7463001EBF94 /* Products */,
4997735720D25AB00009B136 /* Frameworks */,
);
sourceTree = "<group>";
};
Expand All @@ -102,6 +123,7 @@
49CF3B1F20CD7463001EBF94 /* ClashX */ = {
isa = PBXGroup;
children = (
4997732220D251A60009B136 /* Basic */,
4989F98520D0AA300001E564 /* ViewControllers */,
49CF3B5D20CE80D2001EBF94 /* script */,
49CF3B5A20CE8054001EBF94 /* Managers */,
Expand Down Expand Up @@ -185,6 +207,8 @@
49CF3B1920CD7463001EBF94 /* Sources */,
49CF3B1A20CD7463001EBF94 /* Frameworks */,
49CF3B1B20CD7463001EBF94 /* Resources */,
4997735A20D25ACC0009B136 /* ShellScript */,
4997735C20D25AF00009B136 /* ShellScript */,
);
buildRules = (
);
Expand Down Expand Up @@ -264,21 +288,51 @@
49CF3B4020CD7845001EBF94 /* [email protected] in Resources */,
49CF3B3F20CD7845001EBF94 /* menu_icon.png in Resources */,
4989F98420D02D200001E564 /* Country.mmdb in Resources */,
4989F98C20D0AD800001E564 /* SampleConfigViewController.xib in Resources */,
4989F98E20D0AE990001E564 /* sampleConfig.ini in Resources */,
49CF3B6320CED9CF001EBF94 /* check_proxy_helper.sh in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
4997735A20D25ACC0009B136 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "./Carthage/Build/Mac/LaunchAtLogin.framework/Resources/copy-helper.sh";
};
4997735C20D25AF00009B136 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"$(SRCROOT)/Carthage/Build/Mac/LaunchAtLogin.framework",
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "/usr/local/bin/carthage copy-frameworks";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
49CF3B1920CD7463001EBF94 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4989F98B20D0AD800001E564 /* SampleConfigViewController.swift in Sources */,
49CF3B5C20CE8068001EBF94 /* ProxyConfigManager.swift in Sources */,
4997732520D251A60009B136 /* SWBApplication.m in Sources */,
49CF3B2120CD7463001EBF94 /* AppDelegate.swift in Sources */,
49CF3B6520CEE06C001EBF94 /* ConfigManager.swift in Sources */,
);
Expand Down Expand Up @@ -419,6 +473,10 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = MEWHFZ92DY;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Carthage/Build/Mac",
);
INFOPLIST_FILE = ClashX/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -429,6 +487,7 @@
"$(PROJECT_DIR)/ClashX",
"$(PROJECT_DIR)/ClashX/clash",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
PRODUCT_BUNDLE_IDENTIFIER = com.west2online.ClashX;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "ClashX/ClashX-Bridging-Header.h";
Expand All @@ -445,6 +504,10 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = MEWHFZ92DY;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Carthage/Build/Mac",
);
INFOPLIST_FILE = ClashX/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -455,6 +518,7 @@
"$(PROJECT_DIR)/ClashX",
"$(PROJECT_DIR)/ClashX/clash",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
PRODUCT_BUNDLE_IDENTIFIER = com.west2online.ClashX;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "ClashX/ClashX-Bridging-Header.h";
Expand Down
22 changes: 20 additions & 2 deletions ClashX/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
//

import Cocoa


import LaunchAtLogin

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
Expand All @@ -18,6 +17,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {

@IBOutlet weak var statusMenu: NSMenu!
@IBOutlet weak var proxySettingMenuItem: NSMenuItem!
@IBOutlet weak var autoStartMenuItem: NSMenuItem!

let ssQueue = DispatchQueue(label: "com.w2fzu.ssqueue", attributes: .concurrent)

Expand All @@ -44,6 +44,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {

func updateMenuItem(){
proxySettingMenuItem.state = ConfigManager.proxyPortAutoSet ? .on : .off
autoStartMenuItem.state = LaunchAtLogin.isEnabled ? .on:.off

}

func startProxy() {
Expand Down Expand Up @@ -83,6 +85,22 @@ class AppDelegate: NSObject, NSApplicationDelegate {
pasteboard.setString("export https_proxy=http://127.0.0.1:\(ConfigManager.httpProxyPort);export http_proxy=http://127.0.0.1:\(ConfigManager.httpProxyPort)", forType: .string)
}

@IBAction func actionStartAtLogin(_ sender: NSMenuItem) {
LaunchAtLogin.isEnabled = !LaunchAtLogin.isEnabled
updateMenuItem()
}

var genConfigWindow:NSWindowController?=nil
@IBAction func actionGenConfig(_ sender: Any) {
let ctrl = NSStoryboard(name: NSStoryboard.Name(rawValue: "Main"), bundle: nil)
.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier(rawValue: "sampleConfigGenerator")) as! NSWindowController
genConfigWindow?.close()
genConfigWindow=ctrl
ctrl.showWindow(nil)
NSApp.activate(ignoringOtherApps: true)
ctrl.window?.makeKeyAndOrderFront(self)

}

@IBAction func openConfigFolder(_ sender: Any) {
let path = (NSHomeDirectory() as NSString).appendingPathComponent("/.config/clash/config.ini")
Expand Down
17 changes: 9 additions & 8 deletions ClashX/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</application>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="ClashX" customModuleProvider="target">
<connections>
<outlet property="autoStartMenuItem" destination="B1J-XB-BiZ" id="xaS-h5-qd0"/>
<outlet property="proxySettingMenuItem" destination="8se-yr-wmp" id="yvm-QP-yoA"/>
<outlet property="statusMenu" destination="Afa-lD-EbR" id="cov-E9-WrO"/>
</connections>
Expand All @@ -30,6 +31,9 @@
</menuItem>
<menuItem title="start at login" id="B1J-XB-BiZ">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="actionStartAtLogin:" target="Voe-Tx-rLC" id="aie-1F-HjZ"/>
</connections>
</menuItem>
<menuItem title="copy export command" id="Jmb-PK-rMW">
<modifierMask key="keyEquivalentModifierMask"/>
Expand All @@ -44,25 +48,22 @@
<menuItem title="generate config" id="5Ab-VJ-iIm">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<segue destination="Byh-1P-5fs" kind="show" id="mVy-i5-se3"/>
<action selector="actionGenConfig:" target="Voe-Tx-rLC" id="SBd-vV-e1R"/>
</connections>
</menuItem>
<menuItem title="open Config Folder" id="DwE-WX-ETZ">
<menuItem title="edit config" id="DwE-WX-ETZ">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="openConfigFolder:" target="Voe-Tx-rLC" id="6Ke-Bi-AAZ"/>
</connections>
</menuItem>
<menuItem title="update config" id="q3G-VH-eyy">
<menuItem title="reload config" id="q3G-VH-eyy">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="actionUpdateConfig:" target="Voe-Tx-rLC" id="oW5-Ll-SY8"/>
</connections>
</menuItem>
<menuItem title="import Config" id="GRE-Ra-Pkx">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="reload Config" id="MKB-4v-QNy">
<menuItem title="import config" id="GRE-Ra-Pkx">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
Expand All @@ -84,7 +85,7 @@
<!--Window Controller-->
<scene sceneID="seD-T7-5qr">
<objects>
<windowController id="Byh-1P-5fs" sceneMemberID="viewController">
<windowController storyboardIdentifier="sampleConfigGenerator" id="Byh-1P-5fs" sceneMemberID="viewController">
<window key="window" title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" id="q8i-4q-6dO">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
Expand Down
11 changes: 11 additions & 0 deletions ClashX/Basic/SWBApplication.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// Created by clowwindy on 3/1/14.
// Copyright (c) 2014 clowwindy. All rights reserved.
//

#import <Foundation/Foundation.h>
@import AppKit;


@interface SWBApplication : NSApplication
@end
49 changes: 49 additions & 0 deletions ClashX/Basic/SWBApplication.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// Created by clowwindy on 3/1/14.
// Copyright (c) 2014 clowwindy. All rights reserved.
//

#import "SWBApplication.h"


@implementation SWBApplication {

}

// Enable Key Shortcuts
// http://stackoverflow.com/questions/970707/cocoa-keyboard-shortcuts-in-dialog-without-an-edit-menu
- (void) sendEvent:(NSEvent *)event {
if ([event type] == NSKeyDown) {
if (([event modifierFlags] & NSDeviceIndependentModifierFlagsMask) == NSCommandKeyMask) {
if ([[event charactersIgnoringModifiers] isEqualToString:@"x"]) {
if ([self sendAction:@selector(cut:) to:nil from:self])
return;
}
else if ([[event charactersIgnoringModifiers] isEqualToString:@"c"]) {
if ([self sendAction:@selector(copy:) to:nil from:self])
return;
}
else if ([[event charactersIgnoringModifiers] isEqualToString:@"v"]) {
if ([self sendAction:@selector(paste:) to:nil from:self])
return;
}
else if ([[event charactersIgnoringModifiers] isEqualToString:@"z"]) {
if ([self sendAction:@selector(undo) to:nil from:self])
return;
}
else if ([[event charactersIgnoringModifiers] isEqualToString:@"a"]) {
if ([self sendAction:@selector(selectAll:) to:nil from:self])
return;
}
}
else if (([event modifierFlags] & NSDeviceIndependentModifierFlagsMask) == (NSCommandKeyMask | NSShiftKeyMask)) {
if ([[event charactersIgnoringModifiers] isEqualToString:@"Z"]) {
if ([self sendAction:@selector(redo) to:nil from:self])
return;
}
}
}
[super sendEvent:event];
}

@end
2 changes: 1 addition & 1 deletion ClashX/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
<key>NSMainStoryboardFile</key>
<string>Main</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<string>SWBApplication</string>
</dict>
</plist>
Loading

0 comments on commit 302b683

Please sign in to comment.