Generates SIP002 QR code
This commit is contained in:
@ -241,6 +241,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
|||||||
}
|
}
|
||||||
qrcodeWinCtrl = SWBQRCodeWindowController(windowNibName: "SWBQRCodeWindowController")
|
qrcodeWinCtrl = SWBQRCodeWindowController(windowNibName: "SWBQRCodeWindowController")
|
||||||
qrcodeWinCtrl.qrCode = profile.URL()!.absoluteString
|
qrcodeWinCtrl.qrCode = profile.URL()!.absoluteString
|
||||||
|
qrcodeWinCtrl.legacyQRCode = profile.URL(legacy: true)!.absoluteString
|
||||||
qrcodeWinCtrl.title = profile.title()
|
qrcodeWinCtrl.title = profile.title()
|
||||||
qrcodeWinCtrl.showWindow(self)
|
qrcodeWinCtrl.showWindow(self)
|
||||||
NSApp.activate(ignoringOtherApps: true)
|
NSApp.activate(ignoringOtherApps: true)
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
@interface SWBQRCodeWindowController : NSWindowController
|
@interface SWBQRCodeWindowController : NSWindowController
|
||||||
|
|
||||||
|
@property (nonatomic, copy) NSString *legacyQRCode;
|
||||||
@property (nonatomic, copy) NSString *qrCode;
|
@property (nonatomic, copy) NSString *qrCode;
|
||||||
@property (nonatomic, copy) NSString *title;
|
@property (nonatomic, copy) NSString *title;
|
||||||
|
|
||||||
|
@ -78,4 +78,13 @@
|
|||||||
[pasteboard writeObjects:copiedObjects];
|
[pasteboard writeObjects:copiedObjects];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)flagsChanged:(NSEvent *)event {
|
||||||
|
NSUInteger modifiers = event.modifierFlags & NSDeviceIndependentModifierFlagsMask;
|
||||||
|
if (modifiers & NSAlternateKeyMask) {
|
||||||
|
[self setQRCode:self.legacyQRCode];
|
||||||
|
} else {
|
||||||
|
[self setQRCode:self.qrCode];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -246,7 +246,7 @@ class ServerProfile: NSObject, NSCopying {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func URL() -> Foundation.URL? {
|
private func makeLegacyURL() -> URL? {
|
||||||
var url = URLComponents()
|
var url = URLComponents()
|
||||||
|
|
||||||
url.host = serverHost
|
url.host = serverHost
|
||||||
@ -275,6 +275,38 @@ class ServerProfile: NSObject, NSCopying {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func URL(legacy: Bool = false) -> URL? {
|
||||||
|
// If you want the URL from <= 1.5.1
|
||||||
|
if (legacy) {
|
||||||
|
return self.makeLegacyURL()
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let rawUserInfo = "\(method):\(password)".data(using: .utf8) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
let paddings = CharacterSet(charactersIn: "=")
|
||||||
|
let userInfo = rawUserInfo.base64EncodedString().trimmingCharacters(in: paddings)
|
||||||
|
|
||||||
|
var items = [URLQueryItem(name: "OTA", value: ota.description)]
|
||||||
|
if enabledKcptun {
|
||||||
|
items.append(URLQueryItem(name: "Kcptun", value: enabledKcptun.description))
|
||||||
|
items.append(contentsOf: kcptunProfile.urlQueryItems())
|
||||||
|
}
|
||||||
|
|
||||||
|
var comps = URLComponents()
|
||||||
|
|
||||||
|
comps.scheme = "ss"
|
||||||
|
comps.host = serverHost
|
||||||
|
comps.port = Int(serverPort)
|
||||||
|
comps.user = userInfo
|
||||||
|
comps.fragment = remark
|
||||||
|
comps.queryItems = items
|
||||||
|
|
||||||
|
let url = try? comps.asURL()
|
||||||
|
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
|
||||||
func title() -> String {
|
func title() -> String {
|
||||||
if remark.isEmpty {
|
if remark.isEmpty {
|
||||||
|
Reference in New Issue
Block a user