Skip to content

Commit

Permalink
Fix #19 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed Aug 9, 2022
1 parent e7ba409 commit e98b90a
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 1 deletion.
10 changes: 10 additions & 0 deletions ssrMac.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
62E2E1991A5AB21E00C9A2E1 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 62E2E1981A5AB21E00C9A2E1 /* SystemConfiguration.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
62E2E19B1A5AB23700C9A2E1 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 62E2E19A1A5AB23700C9A2E1 /* Security.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
62E2E19D1A5ABE5C00C9A2E1 /* abp.js in Resources */ = {isa = PBXBuildFile; fileRef = 62E2E19C1A5ABE5C00C9A2E1 /* abp.js */; };
B6CFA20F28A2BF0900F2C377 /* SettingsController.m in Sources */ = {isa = PBXBuildFile; fileRef = B6CFA20D28A2BF0900F2C377 /* SettingsController.m */; };
B6CFA21028A2BF0900F2C377 /* SettingsController.xib in Resources */ = {isa = PBXBuildFile; fileRef = B6CFA20E28A2BF0900F2C377 /* SettingsController.xib */; };
EB1897A04CF0382A754FE700 /* SWBConfigWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = EB1895348E32ABA4F4F86742 /* SWBConfigWindowController.m */; };
EB1899E6974F61B38B2FFD2C /* ProfileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = EB1892B5027A6B1F1E2CDC12 /* ProfileManager.m */; };
EB189FE30A2E13F4D10D59ED /* SWBApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = EB189ABF1BF9729F1E0E8F72 /* SWBApplication.m */; };
Expand Down Expand Up @@ -334,6 +336,9 @@
62E2E19A1A5AB23700C9A2E1 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/Security.framework; sourceTree = DEVELOPER_DIR; };
62E2E19C1A5ABE5C00C9A2E1 /* abp.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = abp.js; sourceTree = "<group>"; };
96D80C04176CE1D7006C8078 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
B6CFA20C28A2BF0900F2C377 /* SettingsController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SettingsController.h; sourceTree = "<group>"; };
B6CFA20D28A2BF0900F2C377 /* SettingsController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SettingsController.m; sourceTree = "<group>"; };
B6CFA20E28A2BF0900F2C377 /* SettingsController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SettingsController.xib; sourceTree = "<group>"; };
EB189071407B3A2A9B4C83CB /* ProfileManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProfileManager.h; sourceTree = "<group>"; };
EB1891B68FCBD841C5E461B6 /* About.md */ = {isa = PBXFileReference; lastKnownFileType = file.md; path = About.md; sourceTree = SOURCE_ROOT; };
EB1891FD08E70E9E9DC84AFD /* about.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = about.txt; sourceTree = "<group>"; };
Expand Down Expand Up @@ -542,6 +547,8 @@
3AD601372018D47700403182 /* GCDWebServer.xcodeproj */,
627A6E0A18B47E9300493BBC /* SWBAppDelegate.h */,
627A6E0B18B47E9300493BBC /* SWBAppDelegate.m */,
B6CFA20C28A2BF0900F2C377 /* SettingsController.h */,
B6CFA20D28A2BF0900F2C377 /* SettingsController.m */,
627A6E1018B47E9300493BBC /* Images.xcassets */,
627A6DFF18B47E9300493BBC /* Supporting Files */,
EB1895348E32ABA4F4F86742 /* SWBConfigWindowController.m */,
Expand Down Expand Up @@ -580,6 +587,7 @@
6232046F18C0719D001A30B9 /* menu_icon_disabled.png */,
629AC93218B49341001D2771 /* Application.xib */,
3A4AAEB3201B2FB7002F23AF /* ConfigWindow.xib */,
B6CFA20E28A2BF0900F2C377 /* SettingsController.xib */,
627A6E0018B47E9300493BBC /* ssrMac-Info.plist */,
627A6E0118B47E9300493BBC /* InfoPlist.strings */,
627A6E0418B47E9300493BBC /* main.m */,
Expand Down Expand Up @@ -831,6 +839,7 @@
62E27E6418C1F1E30086033D /* LICENSE in Resources */,
6232047718C08C6C001A30B9 /* Localizable.strings in Resources */,
625E5BBA19EA350F007A5124 /* QRCodeWindow.xib in Resources */,
B6CFA21028A2BF0900F2C377 /* SettingsController.xib in Resources */,
629AC93318B49341001D2771 /* Application.xib in Resources */,
3A4AAEB4201B2FB7002F23AF /* ConfigWindow.xib in Resources */,
620530BE18D44FB600887D3E /* install_helper.sh in Resources */,
Expand Down Expand Up @@ -872,6 +881,7 @@
3ABFEC872534AC8100A12D18 /* net_port_is_free.c in Sources */,
625E5BBD19EA36D2007A5124 /* SWBQRCodeWindowController.m in Sources */,
3ACA8CCB2019C17800839E41 /* ShadowsocksRunner.m in Sources */,
B6CFA20F28A2BF0900F2C377 /* SettingsController.m in Sources */,
EB189FE30A2E13F4D10D59ED /* SWBApplication.m in Sources */,
3A40B2D12019E0BC00F33F80 /* qrCodeOnScreen.m in Sources */,
EB1899E6974F61B38B2FFD2C /* ProfileManager.m in Sources */,
Expand Down
1 change: 1 addition & 0 deletions ssrMac/SWBAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@interface SWBAppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@property (nonatomic, strong) NSStatusItem* item;
@property(nonatomic, assign) NSInteger listenPort;
@property(nonatomic, assign) NSInteger workingListenPort;
- (NSInteger) correctListenPort;
- (void) modifySystemProxySettings:(BOOL)useProxy port:(NSInteger)port;
Expand Down
16 changes: 15 additions & 1 deletion ssrMac/SWBAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import <GZIP/GZIP.h>
#import "SWBConfigWindowController.h"
#import "SWBQRCodeWindowController.h"
#import "SettingsController.h"
#import "SWBAppDelegate.h"
#import <GCDWebServers/GCDWebServer.h>
#import <GCDWebServers/GCDWebServerDataResponse.h>
Expand All @@ -28,12 +29,12 @@
@interface SWBAppDelegate () <SWBConfigWindowControllerDelegate>
@property(nonatomic, assign) BOOL useProxy;
@property(nonatomic, strong) NSString *runningMode;
@property(nonatomic, assign) NSInteger listenPort;
@end

@implementation SWBAppDelegate {
SWBConfigWindowController *configWindowController;
SWBQRCodeWindowController *qrCodeWindowController;
SettingsController *settingsController;
NSMenuItem *statusMenuItem;
NSMenuItem *enableMenuItem;
NSMenuItem *autoMenuItem;
Expand Down Expand Up @@ -102,6 +103,8 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[menu addItem:[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Import URL from clipboard...", nil) action:@selector(importUrlFromClipboard) keyEquivalent:@""]];
[menu addItem:[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Scan QR Code from Screen...", nil) action:@selector(scanQRCode) keyEquivalent:@""]];
[menu addItem:[NSMenuItem separatorItem]];
[menu addItemWithTitle:NSLocalizedString(@"Settings", nil) action:@selector(showSettingsWindow) keyEquivalent:@""];
[menu addItem:[NSMenuItem separatorItem]];
[menu addItemWithTitle:NSLocalizedString(@"Show Logs...", nil) action:@selector(showLogs) keyEquivalent:@""];
[menu addItemWithTitle:NSLocalizedString(@"Help", nil) action:@selector(showHelp) keyEquivalent:@""];
[menu addItem:[NSMenuItem separatorItem]];
Expand Down Expand Up @@ -385,6 +388,17 @@ - (void)showConfigWindow {
[configWindowController.window makeKeyAndOrderFront:nil];
}

- (void) showSettingsWindow {
if (settingsController) {
[settingsController close];
}
settingsController = [[SettingsController alloc] initWithWindowNibName:@"SettingsController"];
settingsController.appDelegate = self;
[settingsController showWindow:self];
[NSApp activateIgnoringOtherApps:YES];
[settingsController.window makeKeyAndOrderFront:nil];
}

- (void) applicationWillTerminate:(NSNotification *)notification {
NSLog(@"terminating");
if (self.useProxy) {
Expand Down
21 changes: 21 additions & 0 deletions ssrMac/SettingsController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// SettingsController.h
// ssrMac
//
// Created by ssrlive on 2022/8/10.
// Copyright © 2022 ssrLive. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "SWBAppDelegate.h"

NS_ASSUME_NONNULL_BEGIN

@interface SettingsController : NSWindowController
@property (weak) IBOutlet NSTextField *txtPort;

@property(weak) SWBAppDelegate *appDelegate;

@end

NS_ASSUME_NONNULL_END
38 changes: 38 additions & 0 deletions ssrMac/SettingsController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// SettingsController.m
// ssrMac
//
// Created by ssrlive on 2022/8/10.
// Copyright © 2022 ssrLive. All rights reserved.
//

#import "SettingsController.h"

@interface SettingsController ()

@end

@implementation SettingsController

- (void)windowDidLoad {
[super windowDidLoad];

NSString *port = [NSString stringWithFormat:@"%ld", (long)self.appDelegate.listenPort];
[self.txtPort setStringValue:port];
}

- (IBAction) btnOkClicked:(NSButton *)sender {
NSString *s = self.txtPort.stringValue;
NSInteger i = [self integerFromString:s];
self.appDelegate.listenPort = i;
[self.window performClose:self];
}

- (NSInteger) integerFromString:(NSString *)string {
NSNumberFormatter *formatter=[[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber *numberObj = [formatter numberFromString:string];
return [numberObj integerValue];
}

@end
66 changes: 66 additions & 0 deletions ssrMac/SettingsController.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="19529" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="19529"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="SettingsController">
<connections>
<outlet property="txtPort" destination="p9v-zM-5s6" id="Bas-a5-Acg"/>
<outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="796" y="640" width="375" height="179"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1055"/>
<view key="contentView" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="0.0" width="375" height="179"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="jwM-bd-pt8">
<rect key="frame" x="20" y="116" width="93" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Listen Port" id="bSs-Je-WCV">
<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>
<textField identifier="port" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="p9v-zM-5s6">
<rect key="frame" x="119" y="111" width="118" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" id="S3F-Uy-tnH">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button identifier="btnOK" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="XFd-4A-uWc">
<rect key="frame" x="252" y="13" width="110" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="OK" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="mcr-sn-6rs">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<string key="keyEquivalent" base64-UTF8="YES">
DQ
</string>
</buttonCell>
<connections>
<action selector="btnOkClicked:" target="-2" id="YDW-z5-ged"/>
</connections>
</button>
</subviews>
</view>
<connections>
<outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
</connections>
<point key="canvasLocation" x="36" y="-277"/>
</window>
</objects>
</document>

0 comments on commit e98b90a

Please sign in to comment.