Fix bug #104.
Implement show qrcode by core image generator instead of embed a web view.
This commit is contained in:
@ -30,9 +30,6 @@
|
|||||||
9B3FFF291D08A1DF0019A709 /* user-rule.txt in Resources */ = {isa = PBXBuildFile; fileRef = 9B3FFF281D08A1DF0019A709 /* user-rule.txt */; };
|
9B3FFF291D08A1DF0019A709 /* user-rule.txt in Resources */ = {isa = PBXBuildFile; fileRef = 9B3FFF281D08A1DF0019A709 /* user-rule.txt */; };
|
||||||
9B3FFF321D08CEE40019A709 /* SWBQRCodeWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B3FFF311D08CEE40019A709 /* SWBQRCodeWindowController.m */; };
|
9B3FFF321D08CEE40019A709 /* SWBQRCodeWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B3FFF311D08CEE40019A709 /* SWBQRCodeWindowController.m */; };
|
||||||
9B3FFF341D08CEF70019A709 /* SWBQRCodeWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9B3FFF331D08CEF70019A709 /* SWBQRCodeWindowController.xib */; };
|
9B3FFF341D08CEF70019A709 /* SWBQRCodeWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9B3FFF331D08CEF70019A709 /* SWBQRCodeWindowController.xib */; };
|
||||||
9B3FFF381D08CF110019A709 /* jquery.min.js in Resources */ = {isa = PBXBuildFile; fileRef = 9B3FFF351D08CF110019A709 /* jquery.min.js */; };
|
|
||||||
9B3FFF391D08CF110019A709 /* qrcode.min.js in Resources */ = {isa = PBXBuildFile; fileRef = 9B3FFF361D08CF110019A709 /* qrcode.min.js */; };
|
|
||||||
9B3FFF3A1D08CF110019A709 /* qrcode.htm in Resources */ = {isa = PBXBuildFile; fileRef = 9B3FFF371D08CF110019A709 /* qrcode.htm */; };
|
|
||||||
9B3FFF3E1D08D9910019A709 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9B3FFF3D1D08D9910019A709 /* SystemConfiguration.framework */; };
|
9B3FFF3E1D08D9910019A709 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9B3FFF3D1D08D9910019A709 /* SystemConfiguration.framework */; };
|
||||||
9B3FFF471D09CD3B0019A709 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B3FFF461D09CD3B0019A709 /* main.m */; };
|
9B3FFF471D09CD3B0019A709 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B3FFF461D09CD3B0019A709 /* main.m */; };
|
||||||
9B3FFF4C1D09D8F70019A709 /* install_helper.sh in Resources */ = {isa = PBXBuildFile; fileRef = 9B3FFF4B1D09D8F70019A709 /* install_helper.sh */; };
|
9B3FFF4C1D09D8F70019A709 /* install_helper.sh in Resources */ = {isa = PBXBuildFile; fileRef = 9B3FFF4B1D09D8F70019A709 /* install_helper.sh */; };
|
||||||
@ -140,9 +137,6 @@
|
|||||||
9B3FFF301D08CEE40019A709 /* SWBQRCodeWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWBQRCodeWindowController.h; sourceTree = "<group>"; };
|
9B3FFF301D08CEE40019A709 /* SWBQRCodeWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWBQRCodeWindowController.h; sourceTree = "<group>"; };
|
||||||
9B3FFF311D08CEE40019A709 /* SWBQRCodeWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWBQRCodeWindowController.m; sourceTree = "<group>"; };
|
9B3FFF311D08CEE40019A709 /* SWBQRCodeWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWBQRCodeWindowController.m; sourceTree = "<group>"; };
|
||||||
9B3FFF331D08CEF70019A709 /* SWBQRCodeWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SWBQRCodeWindowController.xib; sourceTree = "<group>"; };
|
9B3FFF331D08CEF70019A709 /* SWBQRCodeWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SWBQRCodeWindowController.xib; sourceTree = "<group>"; };
|
||||||
9B3FFF351D08CF110019A709 /* jquery.min.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = jquery.min.js; sourceTree = "<group>"; };
|
|
||||||
9B3FFF361D08CF110019A709 /* qrcode.min.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = qrcode.min.js; sourceTree = "<group>"; };
|
|
||||||
9B3FFF371D08CF110019A709 /* qrcode.htm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = qrcode.htm; sourceTree = "<group>"; };
|
|
||||||
9B3FFF3B1D08D93B0019A709 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
|
9B3FFF3B1D08D93B0019A709 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
|
||||||
9B3FFF3D1D08D9910019A709 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
|
9B3FFF3D1D08D9910019A709 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
|
||||||
9B3FFF441D09CD3B0019A709 /* proxy_conf_helper */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = proxy_conf_helper; sourceTree = BUILT_PRODUCTS_DIR; };
|
9B3FFF441D09CD3B0019A709 /* proxy_conf_helper */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = proxy_conf_helper; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
@ -241,9 +235,6 @@
|
|||||||
9BE8FBBD1D0B1FB900CAFD01 /* libcrypto.1.0.0.dylib */,
|
9BE8FBBD1D0B1FB900CAFD01 /* libcrypto.1.0.0.dylib */,
|
||||||
9B172A6C1D0ADDDD00B87B9A /* Localizable.strings */,
|
9B172A6C1D0ADDDD00B87B9A /* Localizable.strings */,
|
||||||
9B3FFF4B1D09D8F70019A709 /* install_helper.sh */,
|
9B3FFF4B1D09D8F70019A709 /* install_helper.sh */,
|
||||||
9B3FFF351D08CF110019A709 /* jquery.min.js */,
|
|
||||||
9B3FFF361D08CF110019A709 /* qrcode.min.js */,
|
|
||||||
9B3FFF371D08CF110019A709 /* qrcode.htm */,
|
|
||||||
9B3FFF281D08A1DF0019A709 /* user-rule.txt */,
|
9B3FFF281D08A1DF0019A709 /* user-rule.txt */,
|
||||||
9B3FFF261D0898EB0019A709 /* gfwlist.txt */,
|
9B3FFF261D0898EB0019A709 /* gfwlist.txt */,
|
||||||
9B3FFF221D088E8D0019A709 /* abp.js */,
|
9B3FFF221D088E8D0019A709 /* abp.js */,
|
||||||
@ -489,8 +480,6 @@
|
|||||||
C6D429971DA75988002A5711 /* stop_privoxy.sh in Resources */,
|
C6D429971DA75988002A5711 /* stop_privoxy.sh in Resources */,
|
||||||
C8E42A6E1D4F2CAF0074C7EA /* UserRulesController.xib in Resources */,
|
C8E42A6E1D4F2CAF0074C7EA /* UserRulesController.xib in Resources */,
|
||||||
9BEEF06A1D04D4D500FC52B3 /* start_ss_local.sh in Resources */,
|
9BEEF06A1D04D4D500FC52B3 /* start_ss_local.sh in Resources */,
|
||||||
9B3FFF391D08CF110019A709 /* qrcode.min.js in Resources */,
|
|
||||||
9B3FFF3A1D08CF110019A709 /* qrcode.htm in Resources */,
|
|
||||||
C6D429941DA75988002A5711 /* privoxy in Resources */,
|
C6D429941DA75988002A5711 /* privoxy in Resources */,
|
||||||
C6D429991DA76FBC002A5711 /* privoxy.config.example in Resources */,
|
C6D429991DA76FBC002A5711 /* privoxy.config.example in Resources */,
|
||||||
9BEEF06B1D04D4D500FC52B3 /* stop_ss_local.sh in Resources */,
|
9BEEF06B1D04D4D500FC52B3 /* stop_ss_local.sh in Resources */,
|
||||||
@ -501,7 +490,6 @@
|
|||||||
C6D429951DA75988002A5711 /* reload_conf_privoxy.sh in Resources */,
|
C6D429951DA75988002A5711 /* reload_conf_privoxy.sh in Resources */,
|
||||||
9B0BFFEB1D0460A70040E62B /* Assets.xcassets in Resources */,
|
9B0BFFEB1D0460A70040E62B /* Assets.xcassets in Resources */,
|
||||||
9B2491B71D0ACC3E003BBECC /* AdvPreferencesWindowController.xib in Resources */,
|
9B2491B71D0ACC3E003BBECC /* AdvPreferencesWindowController.xib in Resources */,
|
||||||
9B3FFF381D08CF110019A709 /* jquery.min.js in Resources */,
|
|
||||||
9B3FFF271D0898EB0019A709 /* gfwlist.txt in Resources */,
|
9B3FFF271D0898EB0019A709 /* gfwlist.txt in Resources */,
|
||||||
C6D429931DA75988002A5711 /* install_privoxy.sh in Resources */,
|
C6D429931DA75988002A5711 /* install_privoxy.sh in Resources */,
|
||||||
9BC70EDC1D2E3E3100EDA4CA /* Localizable.strings in Resources */,
|
9BC70EDC1D2E3E3100EDA4CA /* Localizable.strings in Resources */,
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
#import <WebKit/WebKit.h>
|
#import <WebKit/WebKit.h>
|
||||||
|
|
||||||
@interface SWBQRCodeWindowController : NSWindowController <WebFrameLoadDelegate>
|
@interface SWBQRCodeWindowController : NSWindowController
|
||||||
|
|
||||||
@property (nonatomic, strong) IBOutlet WebView *webView;
|
|
||||||
@property (nonatomic, copy) NSString *qrCode;
|
@property (nonatomic, copy) NSString *qrCode;
|
||||||
|
@property (nonatomic, weak) NSImageView *imageView;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "SWBQRCodeWindowController.h"
|
#import "SWBQRCodeWindowController.h"
|
||||||
|
@import CoreImage;
|
||||||
|
|
||||||
@interface SWBQRCodeWindowController ()
|
@interface SWBQRCodeWindowController ()
|
||||||
|
|
||||||
@ -18,18 +19,56 @@
|
|||||||
[super windowDidLoad];
|
[super windowDidLoad];
|
||||||
|
|
||||||
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
|
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
|
||||||
[self.webView.mainFrame loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"qrcode" withExtension:@"htm"]]];
|
[self setQRCode:self.qrCode];
|
||||||
self.webView.frameLoadDelegate = self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
|
- (void)setQRCode:(NSString*) qrCode {
|
||||||
if (self.qrCode) {
|
CGImageRef cgImgRef = [self createQRImageForString:qrCode size:CGSizeMake(250, 250)];
|
||||||
[self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"genCode('%@')", _qrCode]];
|
|
||||||
}
|
NSImage *image = [[NSImage alloc]initWithCGImage:cgImgRef size:CGSizeMake(250, 250)];
|
||||||
|
self.imageView.image = image;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)dealloc {
|
- (CGImageRef)createQRImageForString:(NSString *)string size:(CGSize)size {
|
||||||
self.webView.frameLoadDelegate = nil;
|
// Setup the QR filter with our string
|
||||||
|
CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
|
||||||
|
[filter setDefaults];
|
||||||
|
|
||||||
|
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
|
||||||
|
[filter setValue:data forKey:@"inputMessage"];
|
||||||
|
CIImage *image = [filter valueForKey:@"outputImage"];
|
||||||
|
|
||||||
|
// Calculate the size of the generated image and the scale for the desired image size
|
||||||
|
CGRect extent = CGRectIntegral(image.extent);
|
||||||
|
CGFloat scale = MIN(size.width / CGRectGetWidth(extent), size.height / CGRectGetHeight(extent));
|
||||||
|
|
||||||
|
// Since CoreImage nicely interpolates, we need to create a bitmap image that we'll draw into
|
||||||
|
// a bitmap context at the desired size;
|
||||||
|
size_t width = CGRectGetWidth(extent) * scale;
|
||||||
|
size_t height = CGRectGetHeight(extent) * scale;
|
||||||
|
CGColorSpaceRef cs = CGColorSpaceCreateDeviceGray();
|
||||||
|
CGContextRef bitmapRef = CGBitmapContextCreate(nil, width, height, 8, 0, cs, (CGBitmapInfo)kCGImageAlphaNone);
|
||||||
|
|
||||||
|
#if TARGET_OS_IPHONE
|
||||||
|
CIContext *context = [CIContext contextWithOptions:nil];
|
||||||
|
#else
|
||||||
|
CIContext *context = [CIContext contextWithCGContext:bitmapRef options:nil];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
CGImageRef bitmapImage = [context createCGImage:image fromRect:extent];
|
||||||
|
|
||||||
|
CGContextSetInterpolationQuality(bitmapRef, kCGInterpolationNone);
|
||||||
|
CGContextScaleCTM(bitmapRef, scale, scale);
|
||||||
|
CGContextDrawImage(bitmapRef, extent, bitmapImage);
|
||||||
|
|
||||||
|
// Create an image with the contents of our bitmap
|
||||||
|
CGImageRef scaledImage = CGBitmapContextCreateImage(bitmapRef);
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
CGContextRelease(bitmapRef);
|
||||||
|
CGImageRelease(bitmapImage);
|
||||||
|
|
||||||
|
return scaledImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11201" systemVersion="16A323" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
|
<deployment identifier="macosx"/>
|
||||||
<plugIn identifier="com.apple.WebKitIBPlugin" version="10117"/>
|
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11201"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<objects>
|
<objects>
|
||||||
<customObject id="-2" userLabel="File's Owner" customClass="SWBQRCodeWindowController">
|
<customObject id="-2" userLabel="File's Owner" customClass="SWBQRCodeWindowController">
|
||||||
<connections>
|
<connections>
|
||||||
<outlet property="webView" destination="ojI-LR-jEw" id="bpE-vv-uIe"/>
|
<outlet property="imageView" destination="yRy-QH-TEe" id="aa5-Ri-k04"/>
|
||||||
<outlet property="window" destination="QvC-M9-y7g" id="HLy-eJ-5RD"/>
|
<outlet property="window" destination="QvC-M9-y7g" id="HLy-eJ-5RD"/>
|
||||||
</connections>
|
</connections>
|
||||||
</customObject>
|
</customObject>
|
||||||
@ -16,24 +16,17 @@
|
|||||||
<window title="QR Code" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" oneShot="NO" animationBehavior="default" id="QvC-M9-y7g">
|
<window title="QR Code" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" oneShot="NO" animationBehavior="default" id="QvC-M9-y7g">
|
||||||
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
|
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
|
||||||
<rect key="contentRect" x="566" y="456" width="250" height="250"/>
|
<rect key="contentRect" x="566" y="456" width="250" height="250"/>
|
||||||
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
|
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
|
||||||
<view key="contentView" id="EiT-Mj-1SZ">
|
<view key="contentView" id="EiT-Mj-1SZ">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="250" height="250"/>
|
<rect key="frame" x="0.0" y="0.0" width="250" height="250"/>
|
||||||
<autoresizingMask key="autoresizingMask"/>
|
<autoresizingMask key="autoresizingMask"/>
|
||||||
<subviews>
|
<subviews>
|
||||||
<webView translatesAutoresizingMaskIntoConstraints="NO" id="ojI-LR-jEw">
|
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="yRy-QH-TEe">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="250" height="250"/>
|
<rect key="frame" x="0.0" y="0.0" width="250" height="250"/>
|
||||||
<webPreferences key="preferences" defaultFontSize="12" defaultFixedFontSize="12">
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||||
<nil key="identifier"/>
|
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="iAJ-tw-LNU"/>
|
||||||
</webPreferences>
|
</imageView>
|
||||||
</webView>
|
|
||||||
</subviews>
|
</subviews>
|
||||||
<constraints>
|
|
||||||
<constraint firstAttribute="trailing" secondItem="ojI-LR-jEw" secondAttribute="trailing" id="ImJ-r1-FF9"/>
|
|
||||||
<constraint firstAttribute="bottom" secondItem="ojI-LR-jEw" secondAttribute="bottom" id="LQv-2G-kyf"/>
|
|
||||||
<constraint firstItem="ojI-LR-jEw" firstAttribute="leading" secondItem="EiT-Mj-1SZ" secondAttribute="leading" id="kok-J1-X08"/>
|
|
||||||
<constraint firstItem="ojI-LR-jEw" firstAttribute="top" secondItem="EiT-Mj-1SZ" secondAttribute="top" id="voV-aN-Ggt"/>
|
|
||||||
</constraints>
|
|
||||||
</view>
|
</view>
|
||||||
</window>
|
</window>
|
||||||
</objects>
|
</objects>
|
||||||
|
2
ShadowsocksX-NG/jquery.min.js
vendored
2
ShadowsocksX-NG/jquery.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,28 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<script src="jquery.min.js">
|
|
||||||
</script>
|
|
||||||
<script src="qrcode.min.js">
|
|
||||||
</script>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
padding: 10px;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
#qrcode {
|
|
||||||
width:230px;
|
|
||||||
height:230px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<div id="qrcode"></div>
|
|
||||||
<script type="text/javascript">
|
|
||||||
function genCode(code) {
|
|
||||||
new QRCode("qrcode", {
|
|
||||||
text: code,
|
|
||||||
width: 230,
|
|
||||||
height: 230,
|
|
||||||
colorDark : "#000000",
|
|
||||||
colorLight : "#ffffff",
|
|
||||||
correctLevel : QRCode.CorrectLevel.H
|
|
||||||
});
|
|
||||||
}
|
|
||||||
</script>
|
|
1
ShadowsocksX-NG/qrcode.min.js
vendored
1
ShadowsocksX-NG/qrcode.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user