Skip to content

Commit b74a56e

Browse files
author
codersdg
committed
some optimization
1 parent 56cc90e commit b74a56e

21 files changed

+610
-415
lines changed

NIO1901.xcodeproj/project.pbxproj

Lines changed: 56 additions & 52 deletions
Large diffs are not rendered by default.

NIO1901/Modules/Home/Controller/MainViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class MainViewController: BaseViewController {
331331
}
332332
}else{
333333
if vpnStatus == .connected {
334-
mitmServer?.close()
334+
mitmServer?.close(nil)
335335
currentTask = nil
336336
}else{
337337
let task = Task.newTask()

NIO1901/Modules/SessionList/Controller/SessionListViewController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,11 @@ class SessionListViewController: BaseViewController {
238238
tableView.register(SessionCell.self, forCellReuseIdentifier: "SessionCell")
239239
tableView.separatorStyle = .none
240240
tableView.allowsMultipleSelectionDuringEditing = true
241-
tableView.configRefreshHeader(container: self) {
242-
self.loadData()
241+
tableView.configRefreshHeader(container: self) { [weak self] in
242+
self?.loadData()
243243
}
244-
tableView.configRefreshFooter(container: self, action: {
245-
self.loadData(isMore: true)
244+
tableView.configRefreshFooter(container: self, action: { [weak self] in
245+
self?.loadData(isMore: true)
246246
})
247247
tableView.switchRefreshHeader(to: .refreshing)
248248
return tableView

NIO1901/Modules/Setting/WebViewController.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ class WebViewController: BaseViewController,WKNavigationDelegate {
5858
}
5959
/// 加载服务条款
6060
@objc func loadTCHtml() -> Void {
61-
let fwtkRequest = URLRequest(url: URL(string: fwtkUrl)!,cachePolicy: .reloadIgnoringLocalAndRemoteCacheData)
62-
// reloadRevalidatingCacheData
63-
webview.load(fwtkRequest)
61+
// let fwtkRequest = URLRequest(url: URL(string: fwtkUrl)!,cachePolicy: .reloadIgnoringLocalAndRemoteCacheData)
62+
// // reloadRevalidatingCacheData
63+
if let bundleHttpPath = Bundle.main.url(forResource: "Http/fwtkcn", withExtension: "html") {
64+
webview.loadFileURL(bundleHttpPath, allowingReadAccessTo: Bundle.main.bundleURL)
65+
}
66+
// webview.load(fwtkRequest)
6467
}
6568

6669
func loadPPHtml() -> Void {

PacketTunnel/PacketTunnelProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
116116
pendingStopCompletion = completionHandler
117117
// TODO:stop server
118118
if StartInExtension {
119-
mitmServer.close()
119+
mitmServer.close(completionHandler)
120120
}
121121
}
122122

TunnelServices/ActiveSQLite/ASConfigration.swift

100755100644
Lines changed: 75 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,93 @@ import SQLite
1111

1212
//MARK: Custom Class
1313
open class ASConfigration {
14-
public static var logLevel: LogLevel = .error// .debug//
14+
public static var logLevel: LogLevel = .info
1515

1616
private static var dbMap:Dictionary<String,Connection> = Dictionary<String,Connection>()
1717

1818
private static var defaultDB:Connection!
19+
private static var defaultDBName:String?
1920

20-
public static func setDB(path:String,name:String){
21-
22-
// guard dbMap[name] == nil else {
23-
// return
24-
// }
25-
let db = try! Connection(path)
26-
dbMap[name] = db
27-
28-
// #if DEBUG
29-
// ASModel.db.trace{ debugPrint($0)}
30-
// #endif
31-
32-
if logLevel == .debug {
33-
db.trace{ print($0)}
21+
/// 创建数据库
22+
///
23+
/// - Parameters:
24+
/// - path: 文件路径
25+
/// - name: 数据库名字
26+
/// - isAutoCreate: 文件不存在时候,是否自动创建文件。默认true
27+
public static func setDB(path:String,name:String,isAutoCreate:Bool = true){
28+
29+
// guard dbMap[name] == nil else {
30+
// return
31+
// }
32+
if isAutoCreate || fileExists( path){
33+
do{
34+
35+
let db = try Connection(path)
36+
db.busyTimeout = 5
37+
dbMap[name] = db
38+
}catch{
39+
Log.e(error)
40+
}
41+
42+
}
43+
44+
// #if DEBUG
45+
// DBModel.db.trace{ debugPrint($0)}
46+
// #endif
47+
48+
// if logLevel == .debug {
49+
// db.trace{ print($0)}
50+
// }
3451
}
35-
}
3652

37-
public static func setDefaultDB(path:String,name:String){
38-
39-
guard dbMap[name] == nil else {
40-
return
53+
public static func setDefaultDB(path:String,name:String){
54+
55+
guard dbMap[name] == nil else {
56+
return
57+
}
58+
59+
defaultDBName = name
60+
61+
do{
62+
let db = try Connection(path)
63+
db.busyTimeout = 5
64+
dbMap[name] = db
65+
66+
defaultDB = db
67+
}catch{
68+
Log.e(error)
69+
}
70+
71+
// if logLevel == .debug {
72+
// db.trace{ print($0)}
73+
// }
4174
}
4275

43-
let db = try! Connection(path)
44-
dbMap[name] = db
76+
public static func getDefaultDB() throws -> Connection{
77+
if let db = defaultDB{
78+
return db
79+
}else{
80+
throw ASError.dbNotFound(dbName:defaultDBName ?? "默认数据库")
81+
}
82+
}
4583

46-
if logLevel == .debug {
47-
db.trace{ print($0)}
84+
public static func getDB(name:String) throws -> Connection{
85+
if let db = dbMap[name]{
86+
return db
87+
}else{
88+
throw ASError.dbNotFound(dbName:name)
89+
}
90+
4891
}
4992

50-
defaultDB = db
51-
}
52-
53-
public static func getDefaultDB() -> Connection{
54-
return defaultDB
55-
}
56-
57-
public static func getDB(name:String) -> Connection{
58-
return dbMap[name]!
59-
}
93+
private static func fileExists(_ path:String) -> Bool{
94+
var isDir:ObjCBool = false
95+
let exists = FileManager.default.fileExists(atPath: path, isDirectory: &isDir)
96+
if exists && !isDir.boolValue {
97+
return true
98+
}
99+
return false
100+
}
60101

61102
}
62103

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// ASError.swift
3+
// ActiveSQLite
4+
//
5+
// Created by Kevin Zhou on 2020/7/7.
6+
// Copyright © 2020 hereigns. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public enum ASError:Error{
12+
case dbNotFound(dbName:String)
13+
}
14+
15+
extension ASError: LocalizedError{
16+
public var errorDescription: String?{
17+
switch self {
18+
case .dbNotFound(_):
19+
return description
20+
// default:
21+
// return "未知错误。"
22+
}
23+
}
24+
25+
}
26+
27+
extension ASError:CustomNSError{
28+
public static var errorDomain: String {
29+
return "com.hereigns.ios.activesqlite"
30+
}
31+
public var errorCode: Int{
32+
switch self {
33+
case .dbNotFound(_):
34+
return 10001
35+
// default:
36+
// return 00000
37+
}
38+
}
39+
public var errorUserInfo: [String: Any] {
40+
switch self {
41+
case .dbNotFound(let dbName):
42+
return [NSLocalizedDescriptionKey:"找不到数据库:【\(dbName)"]
43+
}
44+
45+
}
46+
47+
}
48+
49+
extension ASError:CustomStringConvertible,CustomDebugStringConvertible{
50+
public var description: String{
51+
return "EaseSQLiteError: errodCode:\(errorCode),errorDomain:\(ASError.errorDomain),errorDescription:\(errorUserInfo)"
52+
}
53+
54+
public var debugDescription: String{
55+
return description
56+
}
57+
}

0 commit comments

Comments
 (0)