Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: feat: refactor v2 #37

Open
wants to merge 123 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
d4a0539
refactor: move source file
nuomi1 Mar 28, 2022
48701c9
refactor: use SWIFT_PACKAGE
nuomi1 Mar 28, 2022
d6d4895
refactor: remove path and sources
nuomi1 Mar 28, 2022
7320cbd
refactor: remove Assets
nuomi1 Mar 28, 2022
087b0f8
refactor: ss.source_files
nuomi1 Mar 28, 2022
e30306a
refactor: Vendor path
nuomi1 Mar 28, 2022
f24fdfe
refactor: swiftlint
nuomi1 Mar 28, 2022
fbcd4a3
chore: update Podfile
nuomi1 Mar 28, 2022
e48725f
style: format
nuomi1 Mar 30, 2022
7be7072
feat: add qqImage
nuomi1 Mar 30, 2022
4a4a619
refactor: setup AppState
nuomi1 Mar 31, 2022
e639549
refactor: observeSystem
nuomi1 Mar 31, 2022
7abed68
style: rename Reactive
nuomi1 Mar 31, 2022
7d1847c
refactor: remove NBusTests
nuomi1 Mar 31, 2022
6e16fb9
feat: HandlerBaseTests
nuomi1 Mar 31, 2022
e9d6f05
feat: QQHandlerBaseTests with share test
nuomi1 Mar 31, 2022
84e0c10
feat: QQSDKHandlerTests
nuomi1 Mar 31, 2022
fe54287
feat: removeFirst
nuomi1 Mar 31, 2022
b5dae20
fix: Info.plist
nuomi1 Mar 31, 2022
83cdff2
style: rename function
nuomi1 Apr 1, 2022
9f1b506
feat: QQHandlerBaseTests with oauth test
nuomi1 Apr 1, 2022
024e9eb
refactor: use url
nuomi1 Apr 1, 2022
afbb115
feat: QQHandlerBaseTests with launch test
nuomi1 Apr 1, 2022
1a91f93
refactor: ClearStorage
nuomi1 Apr 1, 2022
082b0fd
refactor: clearStorage
nuomi1 Apr 1, 2022
1e09a14
refactor: AppState Handler
nuomi1 Apr 1, 2022
bc9479e
refactor: setup handler
nuomi1 Apr 1, 2022
0f0741c
feat: wechatImage
nuomi1 Apr 3, 2022
5f5f045
feat: WechatHandlerBaseTests with share test
nuomi1 Apr 3, 2022
66ec226
feat: WechatSDKHandlerTests
nuomi1 Apr 3, 2022
d577b1f
feat: add message
nuomi1 Apr 3, 2022
a4a336f
refactor: use Keypath
nuomi1 Apr 3, 2022
e3c7cf6
fix: test share path
nuomi1 Apr 4, 2022
a42def8
feat: WechatHandlerBaseTests with oauth test
nuomi1 Apr 4, 2022
d8cbf22
feat: WechatHandlerBaseTests with launch test
nuomi1 Apr 4, 2022
6a92dd1
feat: WeiboHandlerBaseTests with share test
nuomi1 Apr 4, 2022
8a1427f
feat: WeiboHandlerBaseTests with oauth test
nuomi1 Apr 4, 2022
557d4b2
feat: WeiboSDKHandlerTests
nuomi1 Apr 4, 2022
326fac7
feat: AppState with Notification
nuomi1 Apr 4, 2022
726eebf
feat: handle openURL and openUserActivity in XCTest
nuomi1 Apr 4, 2022
b25b49e
fix: title and message
nuomi1 Apr 4, 2022
aadde1d
feat: redirectLink mask public
nuomi1 Apr 4, 2022
f5acc2c
fix: privacy agreement
nuomi1 Apr 4, 2022
55bcf73
fix: force unwrap
nuomi1 Apr 4, 2022
6e6bf08
fix: privacy agreement
nuomi1 Apr 4, 2022
3cf993e
feat: BusTests
nuomi1 Apr 4, 2022
b0974a1
feat: BusTests
nuomi1 Apr 4, 2022
40f6c55
refactor: move compute property to HandlerBaseTests
nuomi1 Apr 4, 2022
2cc21de
feat: HandlerBaseTestCase
nuomi1 Apr 5, 2022
7e3bb67
feat: ShareTestCase
nuomi1 Apr 5, 2022
7e02bb5
refactor: QQHandlerBaseTests with ShareTestCase
nuomi1 Apr 5, 2022
9b122ba
refactor: WechatHandlerBaseTests with ShareTestCase
nuomi1 Apr 5, 2022
a43082e
refactor: WeiboHandlerBaseTests with ShareTestCase
nuomi1 Apr 5, 2022
80a6c93
refactor: rename ShareCommonUniversalLinkTestCase
nuomi1 Apr 5, 2022
898771c
refactor: SharePasteboardTestCase
nuomi1 Apr 5, 2022
fd72398
feat: SharePasteboardTestCase with default implement
nuomi1 Apr 5, 2022
26262e7
refactor: QQHandlerBaseTests with SharePasteboardTestCase
nuomi1 Apr 5, 2022
c0c1a07
refactor: WechatHandlerBaseTests with SharePasteboardTestCase
nuomi1 Apr 5, 2022
a3688f5
refactor: WeiboHandlerBaseTests with SharePasteboardTestCase
nuomi1 Apr 5, 2022
10d0245
fix: QQSDKHandler sets empty pasteboard
nuomi1 Apr 5, 2022
17480f5
refactor: move extract pasteboard data and test extra paste data to G…
nuomi1 Apr 6, 2022
7f0085a
style: move test extra pasteboard below the GeneralPasteboardTestCase
nuomi1 Apr 6, 2022
fe05d6b
fix: launch command
nuomi1 Apr 6, 2022
0cc8370
feat: OauthTestCase
nuomi1 Apr 6, 2022
c81c56f
feat: OauthTestCase implementation
nuomi1 Apr 6, 2022
4e6613c
feat: QQHandlerBaseTests with OauthTestCase
nuomi1 Apr 6, 2022
dd154fd
feat: WechatHandlerBaseTests with OauthTestCase
nuomi1 Apr 6, 2022
31f3156
feat: WeiboHandlerBaseTests with OauthTestCase
nuomi1 Apr 6, 2022
bf935c9
fix: skip test pasteboard for oauth qq
nuomi1 Apr 6, 2022
7fd4dde
docs: MARK
nuomi1 Apr 8, 2022
ce5b1ec
feat: LaunchTestCase
nuomi1 Apr 8, 2022
e6947cd
feat: LaunchTestCase implementation
nuomi1 Apr 8, 2022
ef6a3b3
feat: QQHandlerBaseTests with LaunchTestCase
nuomi1 Apr 8, 2022
ab2f167
feat: WechatHandlerBaseTests with LaunchTestCase
nuomi1 Apr 8, 2022
29fdd99
refactor: general test
nuomi1 Apr 10, 2022
605b105
refactor: share test
nuomi1 Apr 10, 2022
b69ed6b
refactor: oauth test
nuomi1 Apr 10, 2022
73c4e28
refactor: launch test
nuomi1 Apr 10, 2022
56a6220
refactor: remove HandlerBaseTestCase.swift
nuomi1 Apr 10, 2022
3eb1af3
fix: import RxCocoa
nuomi1 Apr 10, 2022
1b1bcb2
style: move pasteboard protocol above the SharePasteboardTestCase
nuomi1 Apr 12, 2022
9e1019c
refactor: add underscore to default implementation function and protocol
nuomi1 Apr 13, 2022
6df4d35
feat: test scheme
nuomi1 Apr 13, 2022
caeead8
refactor: use exact verb
nuomi1 Apr 13, 2022
46f25df
refactor: avoid error in share and oauth
nuomi1 Apr 13, 2022
34f05f3
fix: copy WeiboSDK.bundle to app
nuomi1 Apr 15, 2022
484de2e
refactor: defaultPasteboardString
nuomi1 Apr 15, 2022
cf2d5ce
feat: test pasteboard with string
nuomi1 Apr 15, 2022
3a5591e
feat: log url
nuomi1 Apr 15, 2022
38c7a6c
fix: aid could be nil
nuomi1 Apr 15, 2022
46cb8ae
feat: log pasteboard keys
nuomi1 Apr 16, 2022
eef9c65
fix: handle response notification early
nuomi1 Apr 16, 2022
dc7cccd
refactor: exact type
nuomi1 Apr 16, 2022
3c95369
feat: get pasteboard data from SDK
nuomi1 Apr 16, 2022
90fc204
fix: multithread
nuomi1 Apr 16, 2022
49ab8e3
refactor: remove ShareCommonUniversalLinkTestCase and ShareMediaMessa…
nuomi1 Apr 16, 2022
585215d
refactor: remove ShareCommonPasteboardTestCase and ShareMediaMessageP…
nuomi1 Apr 16, 2022
f58a6ad
refactor: test function
nuomi1 Apr 16, 2022
b8a0fce
refactor: rename to BusMockTestSDK
nuomi1 Apr 19, 2022
5e965c6
refactor: AppState+PlatformItem
nuomi1 Apr 20, 2022
96ff4d8
fix: BusMockTestSDK includes AppState.swift
nuomi1 Apr 20, 2022
126677b
refactor: set again pasteboard
nuomi1 Apr 20, 2022
1ff15d9
fix: remove observer after notification
nuomi1 Apr 20, 2022
4735e76
refactor: notification Response
nuomi1 Apr 20, 2022
847f126
feat: BusMockTestSDK adds WoodPeckeriOS
nuomi1 Apr 20, 2022
781a177
fix: declaration
nuomi1 Apr 20, 2022
e2744ba
refactor: change XCTAssertTrue(false) to fatalError()
nuomi1 Apr 20, 2022
8683c4f
refactor: use XCTUnwrap
nuomi1 Apr 20, 2022
70666b3
refactor: Request State
nuomi1 Apr 20, 2022
70ea350
fix: filter general pasteboard
nuomi1 Apr 24, 2022
6ecaf9a
feat: Test share
nuomi1 Apr 24, 2022
6ad5cef
feat: extract url using JSON
nuomi1 Apr 24, 2022
15b906d
feat: test qq share
nuomi1 Apr 24, 2022
be0babe
feat: process response pasteboard
nuomi1 Apr 25, 2022
9bf3b4d
feat: test qq share with response pasteboard
nuomi1 Apr 25, 2022
3b5030a
feat: convert Endpoint to Platform
nuomi1 Apr 26, 2022
b099020
refactor: rename to responseSignToken and sort
nuomi1 Apr 26, 2022
a1842a6
refactor: set shareState in general
nuomi1 Apr 26, 2022
2ca0638
refactor: determine shareState
nuomi1 Apr 26, 2022
b3f6a3c
refactor: GeneralCompletionTestCase
nuomi1 May 16, 2022
e385e5f
fix: cancel share with qq
nuomi1 May 16, 2022
88df857
refactor: GeneralCompletionTestCase with WeiboHandlerBaseTests
nuomi1 May 16, 2022
e6b3f8a
refactor: GeneralCompletionTestCase with WechatHandlerBaseTests
nuomi1 May 23, 2022
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
2 changes: 1 addition & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ identifier_name:

included:
- Example
- NBus
- Sources
- Tests
- Package.swift

Expand Down
83 changes: 11 additions & 72 deletions Example/NBus/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,10 @@ extension AppDelegate {
// swiftlint:disable function_body_length

private func pasteboardItems() -> Observable<[[String]]> {
NotificationCenter.default.rx
.notification(UIPasteboard.changedNotification)
.map { _ -> [[String]] in
let items = UIPasteboard.general.items

return items.enumerated().map { index, item -> [String] in
UIPasteboard.general.rx
.items()
.map { items -> [[String]] in
items.enumerated().map { index, item -> [String] in
item.map { key, value -> String in
let identity: String
let index = "(\(index + 1)/\(items.count))"
Expand Down Expand Up @@ -126,30 +124,6 @@ extension AppDelegate {
}

// swiftlint:enable function_body_length

private func canOpenURL() -> Observable<URL> {
UIApplication.shared.rx
.methodInvoked(#selector(UIApplication.canOpenURL(_:)))
.compactMap { args in
args[0] as? URL
}
}

private func openURL() -> Observable<URL> {
let oldURL = UIApplication.shared.rx
.methodInvoked(#selector(UIApplication.openURL(_:)))
.compactMap { args in
args[0] as? URL
}

let newURL = UIApplication.shared.rx
.methodInvoked(#selector(UIApplication.open(_:options:completionHandler:)))
.compactMap { args in
args[0] as? URL
}

return Observable.merge([oldURL, newURL])
}
}

extension AppDelegate {
Expand All @@ -161,63 +135,28 @@ extension AppDelegate {
})
.disposed(by: disposeBag)

canOpenURL()
UIApplication.shared.rx
.canOpenURL()
.bind(onNext: { url in
logger.debug("\(url)")
})
.disposed(by: disposeBag)

openURL()
UIApplication.shared.rx
.openURL()
.bind(onNext: { url in
logger.debug("\(url)")
})
.disposed(by: disposeBag)
}
}

extension AppDelegate {

private func clearKeychains() {
let items = [
kSecClassGenericPassword,
kSecClassInternetPassword,
kSecClassCertificate,
kSecClassKey,
kSecClassIdentity,
]

let status = items
.map { [kSecClass: $0] as CFDictionary }
.map { SecItemDelete($0) }

assert(status.allSatisfy {
$0 == errSecSuccess || $0 == errSecItemNotFound
})
}

private func clearPasteboard() {
let pasteboard = UIPasteboard.general

pasteboard.items = []

pasteboard.string = "NBus"
}

private func clearUserDefaults() {
let defaults = UserDefaults.standard

for (key, _) in defaults.dictionaryRepresentation() {
defaults.removeObject(forKey: key)
}
}
}

extension AppDelegate {

private func clearStorage() {
clearKeychains()
clearPasteboard()
clearUserDefaults()
// AppState.shared.clearKeychains()
AppState.shared.clearPasteboard(shouldSetString: true)
// AppState.shared.clearUserDefaults()
}
}

Expand Down
86 changes: 86 additions & 0 deletions Example/NBus/AppDelegateSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

#if BusMockTestSDK
var openURLToken: NSObjectProtocol?
var openUserActivityToken: NSObjectProtocol?
#endif

func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
Expand All @@ -44,6 +49,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
#elseif BusMockWeiboSDK
let title = "isWeiboAppInstalled"
let message = "\(WeiboSDK.isWeiboAppInstalled())"
#elseif BusMockTestSDK
let title = "Empty"
let message = "Empty"
#else
#error("ERROR")
let title = "ERROR"
Expand All @@ -64,4 +72,82 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

return true
}

#if BusMockTestSDK
func application(
_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {
let group = DispatchGroup()

var result: Bool!

openURLToken = NotificationCenter.default.addObserver(
forName: AppState.OpenURL.responseName,
object: nil,
queue: nil,
using: { notification in
result = notification.userInfo?[AppState.OpenURL.responseResultKey] as? Bool

group.leave()
}
)

group.enter()

NotificationCenter.default.post(
name: AppState.OpenURL.requestName,
object: nil,
userInfo: [
AppState.OpenURL.requestURLKey: url,
AppState.OpenURL.requestPasteboardKey: UIPasteboard.general.items,
]
)

group.wait()

NotificationCenter.default.removeObserver(openURLToken!)

return result
}

func application(
_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
) -> Bool {
let group = DispatchGroup()

var result: Bool!

openUserActivityToken = NotificationCenter.default.addObserver(
forName: AppState.OpenUserActivity.responseName,
object: nil,
queue: nil,
using: { notification in
result = notification.userInfo?[AppState.OpenUserActivity.responseResultKey] as? Bool

group.leave()
}
)

group.enter()

NotificationCenter.default.post(
name: AppState.OpenUserActivity.requestName,
object: nil,
userInfo: [
AppState.OpenUserActivity.requestUserActivityKey: userActivity,
AppState.OpenUserActivity.requestPasteboardKey: UIPasteboard.general.items,
]
)

group.wait()

NotificationCenter.default.removeObserver(openUserActivityToken!)

return result
}
#endif
}
49 changes: 49 additions & 0 deletions Example/NBus/Model/AppState+ClearStorage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// AppState+ClearStorage.swift
// BusMock
//
// Created by nuomi1 on 2022/4/1.
// Copyright © 2022 nuomi1. All rights reserved.
//

import Foundation
import UIKit

extension AppState {

func clearKeychains() {
let items = [
kSecClassGenericPassword,
kSecClassInternetPassword,
kSecClassCertificate,
kSecClassKey,
kSecClassIdentity,
]

let status = items
.map { [kSecClass: $0] as CFDictionary }
.map { SecItemDelete($0) }

assert(status.allSatisfy {
$0 == errSecSuccess || $0 == errSecItemNotFound
})
}

func clearPasteboard(shouldSetString: Bool = false) {
let pasteboard = UIPasteboard.general

pasteboard.items = []

if shouldSetString {
pasteboard.string = Self.defaultPasteboardString
}
}

func clearUserDefaults() {
let defaults = UserDefaults.standard

for (key, _) in defaults.dictionaryRepresentation() {
defaults.removeObject(forKey: key)
}
}
}
56 changes: 56 additions & 0 deletions Example/NBus/Model/AppState+Handler.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// AppState+Handler.swift
// NBus
//
// Created by nuomi1 on 2022/4/1.
// Copyright © 2022 nuomi1. All rights reserved.
//

import Foundation
import NBus

extension AppState {

static let wechatSDKHandler = WechatSDKHandler(
appID: AppState.getAppID(for: Platforms.wechat)!,
universalLink: AppState.getUniversalLink(for: Platforms.wechat)!
)

static let wechatHandler = WechatHandler(
appID: AppState.getAppID(for: Platforms.wechat)!,
universalLink: AppState.getUniversalLink(for: Platforms.wechat)!
)
}

extension AppState {

static let qqSDKHandler = QQSDKHandler(
appID: AppState.getAppID(for: Platforms.qq)!,
universalLink: AppState.getUniversalLink(for: Platforms.qq)!
)

static let qqHandler = QQHandler(
appID: AppState.getAppID(for: Platforms.qq)!,
universalLink: AppState.getUniversalLink(for: Platforms.qq)!
)
}

extension AppState {

static let weiboSDKHandler = WeiboSDKHandler(
appID: AppState.getAppID(for: Platforms.weibo)!,
universalLink: AppState.getUniversalLink(for: Platforms.weibo)!,
redirectLink: AppState.getRedirectLink(for: Platforms.weibo)!
)

static let weiboHandler = WeiboHandler(
appID: AppState.getAppID(for: Platforms.weibo)!,
universalLink: AppState.getUniversalLink(for: Platforms.weibo)!,
redirectLink: AppState.getRedirectLink(for: Platforms.weibo)!
)
}

extension AppState {

static let systemHandler = SystemHandler()
}
28 changes: 28 additions & 0 deletions Example/NBus/Model/AppState+Notification.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// AppState+Notification.swift
// NBus
//
// Created by nuomi1 on 2022/4/5.
// Copyright © 2022 nuomi1. All rights reserved.
//

import Foundation

extension AppState {

enum OpenURL {
static let requestName = Notification.Name("Bus.OpenURL")
static let responseName = Notification.Name("Bus.OpenURL.Result")
static let requestURLKey = "url"
static let requestPasteboardKey = "pasteboard"
static let responseResultKey = "result"
}

enum OpenUserActivity {
static let requestName = Notification.Name("Bus.OpenUserActivity")
static let responseName = Notification.Name("Bus.OpenUserActivity.Result")
static let requestUserActivityKey = "userActivity"
static let requestPasteboardKey = "pasteboard"
static let responseResultKey = "result"
}
}
Loading