Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

add hotkey for load/unload core #242

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions V2RayX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
objects = {

/* Begin PBXBuildFile section */
215E5632224A2BC1003C451D /* MASShortcut.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21DCD445224A27940096141C /* MASShortcut.framework */; };
215E5633224A2BC1003C451D /* MASShortcut.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 21DCD445224A27940096141C /* MASShortcut.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
21DCD442224A25260096141C /* ToastWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 21DCD43F224A25260096141C /* ToastWindowController.m */; };
21DCD443224A25260096141C /* ShortcutsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 21DCD440224A25260096141C /* ShortcutsController.m */; };
21DCD444224A25260096141C /* ToastWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 21DCD441224A25260096141C /* ToastWindowController.xib */; };
21DCD446224A27940096141C /* MASShortcut.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21DCD445224A27940096141C /* MASShortcut.framework */; };
9504C07D1C662C3000352520 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 9504C07C1C662C3000352520 /* AppDelegate.m */; };
9504C0801C662C3000352520 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9504C07F1C662C3000352520 /* main.m */; };
9504C0821C662C3000352520 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9504C0811C662C3000352520 /* Assets.xcassets */; };
Expand Down Expand Up @@ -62,6 +68,17 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
215E5634224A2BC1003C451D /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
215E5633224A2BC1003C451D /* MASShortcut.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
9504C0C41C662DB400352520 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -83,6 +100,12 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
21DCD43D224A25260096141C /* ShortcutsController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShortcutsController.h; sourceTree = "<group>"; };
21DCD43E224A25260096141C /* ToastWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ToastWindowController.h; sourceTree = "<group>"; };
21DCD43F224A25260096141C /* ToastWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ToastWindowController.m; sourceTree = "<group>"; };
21DCD440224A25260096141C /* ShortcutsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShortcutsController.m; sourceTree = "<group>"; };
21DCD441224A25260096141C /* ToastWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ToastWindowController.xib; sourceTree = "<group>"; };
21DCD445224A27940096141C /* MASShortcut.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = MASShortcut.framework; sourceTree = "<group>"; };
9504C0781C662C3000352520 /* V2RayX.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = V2RayX.app; sourceTree = BUILT_PRODUCTS_DIR; };
9504C07B1C662C3000352520 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
9504C07C1C662C3000352520 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -162,7 +185,9 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
21DCD446224A27940096141C /* MASShortcut.framework in Frameworks */,
95A143CC1C87FCDC008756B9 /* Cocoa.framework in Frameworks */,
215E5632224A2BC1003C451D /* MASShortcut.framework in Frameworks */,
9504C0C11C662D9400352520 /* libz.tbd in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -209,6 +234,11 @@
9504C07A1C662C3000352520 /* V2RayX */ = {
isa = PBXGroup;
children = (
21DCD43D224A25260096141C /* ShortcutsController.h */,
21DCD440224A25260096141C /* ShortcutsController.m */,
21DCD43E224A25260096141C /* ToastWindowController.h */,
21DCD43F224A25260096141C /* ToastWindowController.m */,
21DCD441224A25260096141C /* ToastWindowController.xib */,
9DBF54CD221615AD00B61D55 /* NSData+AES256Encryption.h */,
9DBF54CE221615AD00B61D55 /* NSData+AES256Encryption.m */,
9577E1921C6B065D00093BD3 /* GCDWebServer */,
Expand Down Expand Up @@ -326,6 +356,7 @@
95FCB2451C688BB20081B6FD /* Frameworks */ = {
isa = PBXGroup;
children = (
21DCD445224A27940096141C /* MASShortcut.framework */,
95A143CA1C87FC6E008756B9 /* Cocoa.framework */,
9504C0C01C662D9400352520 /* libz.tbd */,
);
Expand Down Expand Up @@ -364,6 +395,7 @@
9DB94D77209D273A0001E9DD /* Run Script */,
953B60541DB3E31D00D40654 /* Run Script */,
9504C0761C662C3000352520 /* Resources */,
215E5634224A2BC1003C451D /* Embed Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -435,6 +467,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand All @@ -458,6 +491,7 @@
9D5EAC151FDCD70300C14B46 /* geoip.dat in Resources */,
9D5EAC161FDCD70300C14B46 /* geosite.dat in Resources */,
9D3CEE6F209E070F0077CCFE /* AdvancedWindow.xib in Resources */,
21DCD444224A25260096141C /* ToastWindowController.xib in Resources */,
9D5EAC171FDCD70300C14B46 /* v2ctl in Resources */,
9D5EAC181FDCD70300C14B46 /* v2ray in Resources */,
9DB4FE951F205BEB00CCEE5F /* config-sample.plist in Resources */,
Expand Down Expand Up @@ -516,12 +550,14 @@
9504C0901C662CBF00352520 /* ConfigWindowController.m in Sources */,
9577E1B81C6B065E00093BD3 /* GCDWebServerFileRequest.m in Sources */,
9577E1BE1C6B065E00093BD3 /* GCDWebServerStreamedResponse.m in Sources */,
21DCD442224A25260096141C /* ToastWindowController.m in Sources */,
9DDC059121CA8CFF00C6C2D7 /* TransportWindowController.m in Sources */,
9504C0801C662C3000352520 /* main.m in Sources */,
9577E1BB1C6B065E00093BD3 /* GCDWebServerDataResponse.m in Sources */,
9577E1BA1C6B065E00093BD3 /* GCDWebServerURLEncodedFormRequest.m in Sources */,
9577E1B71C6B065E00093BD3 /* GCDWebServerDataRequest.m in Sources */,
9577E1BC1C6B065E00093BD3 /* GCDWebServerErrorResponse.m in Sources */,
21DCD443224A25260096141C /* ShortcutsController.m in Sources */,
9577E1BD1C6B065E00093BD3 /* GCDWebServerFileResponse.m in Sources */,
9DBF54CF221615AD00B61D55 /* NSData+AES256Encryption.m in Sources */,
9DEB294D21CB64CF0052D2BB /* AdvancedWindowController.m in Sources */,
Expand Down Expand Up @@ -679,6 +715,10 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
COMBINE_HIDPI_IMAGES = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/V2RayX",
);
INFOPLIST_FILE = V2RayX/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = cenmrev.V2RayX;
Expand All @@ -691,6 +731,10 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
COMBINE_HIDPI_IMAGES = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/V2RayX",
);
INFOPLIST_FILE = V2RayX/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = cenmrev.V2RayX;
Expand Down
31 changes: 31 additions & 0 deletions V2RayX/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#import "MutableDeepCopying.h"
#import "ConfigImporter.h"
#import "NSData+AES256Encryption.h"
#import "ShortcutsController.h"
#import "ToastWindowController.h"

#define kUseAllServer -10

Expand All @@ -29,6 +31,7 @@ @interface AppDelegate () {
FSEventStreamRef fsEventStream;

NSData* v2rayJSONconfig;
ToastWindowController *tosat;
}

@end
Expand Down Expand Up @@ -140,6 +143,10 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// resume the service when mac wakes up
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(didChangeStatus:) name:NSWorkspaceDidWakeNotification object:NULL];

// Register global hotkey
[ShortcutsController bindShortcuts];
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(hotkeyChangeProxyMode) name:@"NOTIFY_LOAD_UNLOAD_SHORTCUT" object:nil];

// initialize UI
_statusBarItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[_statusBarItem setHighlightMode:YES];
Expand Down Expand Up @@ -846,6 +853,30 @@ -(void)toggleCore {
// });
}

- (void)hotkeyChangeProxyMode {

dispatch_async(dispatch_get_main_queue(), ^{
[self didChangeStatus:self->_enableV2rayItem];
if(self->proxyState == YES) {
[self makeToast:@"V2Ray Load Core"];
}
else {
[self makeToast:@"V2Ray Unload Core"];
}
});
}

- (void)makeToast:(NSString *)message {
if (tosat) {
[tosat close];
}
tosat = [[ToastWindowController alloc] initWithWindowNibName:@"ToastWindowController"];
tosat.message = message;
[tosat showWindow:self];
[tosat fadeInHud];

}

- (IBAction)showConfigWindow:(id)sender {
if (configWindowController) {
[configWindowController close];
Expand Down
24 changes: 20 additions & 4 deletions V2RayX/ConfigWindow.xib
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.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand Down Expand Up @@ -34,7 +34,7 @@
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="551" height="474"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1057"/>
<view key="contentView" id="EiT-Mj-1SZ">
<rect key="frame" x="0.0" y="0.0" width="551" height="474"/>
<autoresizingMask key="autoresizingMask"/>
Expand Down Expand Up @@ -585,6 +585,22 @@ Gw
<action selector="showLog:" target="-2" id="y4o-h5-PjK"/>
</connections>
</button>
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Kda-s5-ofw" customClass="MASShortcutView">
<rect key="frame" x="373" y="404" width="115" height="23"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="associatedUserDefaultsKey" value="LoadUnloadCore"/>
</userDefinedRuntimeAttributes>
</customView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="JbH-Q2-TUw">
<rect key="frame" x="239" y="405" width="114" height="17"/>
<autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Load/Unload Core" id="JWV-p1-hs8">
<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>
</subviews>
</view>
<point key="canvasLocation" x="73.5" y="128"/>
Expand Down Expand Up @@ -641,6 +657,6 @@ Gw
<image name="NSAddTemplate" width="11" height="11"/>
<image name="NSRemoveTemplate" width="11" height="11"/>
<image name="NSShareTemplate" width="11" height="16"/>
<image name="config_duplicate" width="24" height="24"/>
<image name="config_duplicate" width="15" height="15"/>
</resources>
</document>
4 changes: 2 additions & 2 deletions V2RayX/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.5.1</string>
<string>1.5.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1297</string>
<string>1319</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
Expand Down
1 change: 1 addition & 0 deletions V2RayX/MASShortcut.framework/Headers
1 change: 1 addition & 0 deletions V2RayX/MASShortcut.framework/MASShortcut
1 change: 1 addition & 0 deletions V2RayX/MASShortcut.framework/Modules
1 change: 1 addition & 0 deletions V2RayX/MASShortcut.framework/Resources
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
extern NSString *const MASDictionaryTransformerName;

/**
Converts shortcuts for storage in user defaults.

User defaults can’t stored custom types directly, they have to
be serialized to `NSData` or some other supported type like an
`NSDictionary`. In Cocoa Bindings, the conversion can be done
using value transformers like this one.

There’s a built-in transformer (`NSKeyedUnarchiveFromDataTransformerName`)
that converts any `NSCoding` types to `NSData`, but with shortcuts
it makes sense to use a dictionary instead – the defaults look better
when inspected with the `defaults` command-line utility and the
format is compatible with an older sortcut library called Shortcut
Recorder.
*/
@interface MASDictionaryTransformer : NSValueTransformer
@end
44 changes: 44 additions & 0 deletions V2RayX/MASShortcut.framework/Versions/A/Headers/MASKeyCodes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#import <Carbon/Carbon.h>
#import <AppKit/AppKit.h>
#import "MASKeyMasks.h"

// These glyphs are missed in Carbon.h
typedef NS_ENUM(unsigned short, kMASShortcutGlyph) {
kMASShortcutGlyphEject = 0x23CF,
kMASShortcutGlyphClear = 0x2715,
kMASShortcutGlyphDeleteLeft = 0x232B,
kMASShortcutGlyphDeleteRight = 0x2326,
kMASShortcutGlyphLeftArrow = 0x2190,
kMASShortcutGlyphRightArrow = 0x2192,
kMASShortcutGlyphUpArrow = 0x2191,
kMASShortcutGlyphDownArrow = 0x2193,
kMASShortcutGlyphEscape = 0x238B,
kMASShortcutGlyphHelp = 0x003F,
kMASShortcutGlyphPageDown = 0x21DF,
kMASShortcutGlyphPageUp = 0x21DE,
kMASShortcutGlyphTabRight = 0x21E5,
kMASShortcutGlyphReturn = 0x2305,
kMASShortcutGlyphReturnR2L = 0x21A9,
kMASShortcutGlyphPadClear = 0x2327,
kMASShortcutGlyphNorthwestArrow = 0x2196,
kMASShortcutGlyphSoutheastArrow = 0x2198,
};

NS_INLINE NSString* NSStringFromMASKeyCode(unsigned short ch)
{
return [NSString stringWithFormat:@"%C", ch];
}

NS_INLINE NSUInteger MASPickCocoaModifiers(NSUInteger flags)
{
return (flags & (NSEventModifierFlagControl | NSEventModifierFlagShift | NSEventModifierFlagOption | NSEventModifierFlagCommand));
}

NS_INLINE UInt32 MASCarbonModifiersFromCocoaModifiers(NSUInteger cocoaFlags)
{
return
(cocoaFlags & NSEventModifierFlagCommand ? cmdKey : 0)
| (cocoaFlags & NSEventModifierFlagOption ? optionKey : 0)
| (cocoaFlags & NSEventModifierFlagControl ? controlKey : 0)
| (cocoaFlags & NSEventModifierFlagShift ? shiftKey : 0);
}
18 changes: 18 additions & 0 deletions V2RayX/MASShortcut.framework/Versions/A/Headers/MASKeyMasks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#import <Availability.h>

// https://github.com/shpakovski/MASShortcut/issues/99
//
// Long story short: NSControlKeyMask and friends were replaced with NSEventModifierFlagControl
// and similar in macOS Sierra. The project builds fine & clean, but including MASShortcut in
// a project with deployment target set to 10.12 results in several deprecation warnings because
// of the control masks. Simply replacing the old symbols with the new ones isn’t an option,
// since it breaks the build on older SDKs – in Travis, for example.
//
// It should be safe to remove this whole thing once the 10.12 SDK is ubiquitous.

#if __MAC_OS_X_VERSION_MAX_ALLOWED < 101200
#define NSEventModifierFlagCommand NSCommandKeyMask
#define NSEventModifierFlagControl NSControlKeyMask
#define NSEventModifierFlagOption NSAlternateKeyMask
#define NSEventModifierFlagShift NSShiftKeyMask
#endif
Loading