Skip to content

Commit

Permalink
Merge pull request #16 from Louiswu2011/proxy-updater
Browse files Browse the repository at this point in the history
On-device upload functionality
  • Loading branch information
Louiswu2011 authored Feb 10, 2023
2 parents c13878c + 46cf5b1 commit 1c185b5
Show file tree
Hide file tree
Showing 19 changed files with 1,269 additions and 7 deletions.
206 changes: 206 additions & 0 deletions chafenqi.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
buildConfiguration = "Debug"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,19 @@
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>updater.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>BF068F6E2991856F008665E3</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>BFF353BC29681F8D001392E5</key>
<dict>
<key>primary</key>
Expand Down
1 change: 1 addition & 0 deletions chafenqi/App/chafenqiApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var credits = """
特别感谢:
@SoreHait
@Diving-Fish - 舞萌DX/中二节奏查分器
@bakapiano - 查分器更新方案
sdvx.in - 谱面预览
And You
"""
Expand Down
96 changes: 96 additions & 0 deletions chafenqi/Service/TunnelManagerService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// TunnelManagerService.swift
// chafenqi
//
// Created by 刘易斯 on 2023/2/8.
//

import Foundation
import NetworkExtension
import UIKit

final class TunnelManagerService: ObservableObject {
@Published private(set) var manager: NETunnelProviderManager?
@Published private(set) var isStarted = false

static let shared = TunnelManagerService()

private var observer: AnyObject?

private init() {
observer = NotificationCenter.default.addObserver(forName: UIApplication.willEnterForegroundNotification, object: nil, queue: .main) { [weak self] _ in
self?.loadProfile { _ in }
}
}

func loadProfile(_ completion: @escaping (Result<Void, Error>) -> Void) {
NETunnelProviderManager.loadAllFromPreferences { [weak self] managers, error in
guard let self = self else { return }

self.manager = managers?.first
if let error = error {
completion(.failure(error))
} else {
self.isStarted = true
self.manager?.isEnabled = true
print("Loaded preference from settings.")
completion(.success(()))
}
}
}

func installProfile(_ completion: @escaping (Result<Void, Error>) -> Void) {
let m = self.makeManager()
m.saveToPreferences() { [weak self] error in
if let error = error {
return completion(.failure(error))
}

m.loadFromPreferences { [weak self] error in
self?.manager = m
completion(.success(()))
}
}
}

func removeProfile(_ completion: @escaping (Result<Void, Error>) -> Void) {
assert(manager != nil, "Manager missing!")
manager?.removeFromPreferences() { error in
if let error = error {
return completion(.failure(error))
}

self.manager = nil
completion(.success(()))
}
}

private func makeManager() -> NETunnelProviderManager {
let manager = NETunnelProviderManager()
manager.localizedDescription = "国服更新代理"

let proto = NETunnelProviderProtocol()
proto.providerBundleIdentifier = "com.nltv.chafenqi.updater"
proto.serverAddress = "43.139.107.206"

manager.protocolConfiguration = proto

manager.isEnabled = true

return manager
}
}

extension NEVPNStatus: CustomStringConvertible {
public var description: String {
switch self {
case .disconnected: return "未连接"
case .disconnecting: return "断开中"
case .invalid: return "无效"
case .connected: return "已连接"
case .connecting: return "连接中"
case .reasserting: return "重连中"
@unknown default: return "未知"
}
}
}
6 changes: 6 additions & 0 deletions chafenqi/View/PanelView/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ struct SettingsView: View {
@AppStorage("settingsMaimaiCoverSource") var maimaiCoverSource = 0
@AppStorage("settingsCurrentMode") var currentMode = 0

@AppStorage("proxyDidInstallProfile") var installed = false

@AppStorage("userAccountName") var accountName = ""
@AppStorage("userNickname") var accountNickname = ""
@AppStorage("userToken") var token = ""
Expand Down Expand Up @@ -160,6 +162,10 @@ struct SettingsView: View {
token = ""
infoData = Data()
}

func setupProxy() {

}
}

struct RandomizerSettingsView: View {
Expand Down
33 changes: 27 additions & 6 deletions chafenqi/View/TopView/ToolView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import SwiftUI
struct ToolView: View {
@AppStorage("settingsCurrentMode") var currentMode = 0

@State private var showingUpdaterView = false

var body: some View {
VStack {
Form {
Expand All @@ -25,15 +27,15 @@ struct ToolView: View {
.padding(5)
VStack(alignment: .leading) {
Text("随机歌曲")
.font(.title2)
.font(.system(size: 16))
.bold()
Text(currentMode == 0 ? "今天中二打什么?" : "今天maimai打什么?")
.font(.footnote)
.font(.system(size: 12))
}
}
.buttonStyle(.plain)
}
.frame(height: 50)
.frame(height: 40)

// HStack {
// NavigationLink {
Expand All @@ -55,8 +57,27 @@ struct ToolView: View {
// .buttonStyle(.plain)
// }
// .frame(height: 50)
} header: {
Text("常规")

NavigationLink {
UpdaterRouterView()
} label: {
HStack {
Image(systemName: "paperplane")
.resizable()
.aspectRatio(1, contentMode: .fit)
.padding(5)
VStack(alignment: .leading) {
Text("分数上传")
.font(.system(size: 16))
.bold()
Text("Powered by ?")
.font(.system(size: 12))
}
}
.frame(height: 40)
}


}
}
.navigationTitle("工具箱")
Expand All @@ -66,6 +87,6 @@ struct ToolView: View {

struct ToolView_Previews: PreviewProvider {
static var previews: some View {
MainView()
ToolView()
}
}
Loading

0 comments on commit 1c185b5

Please sign in to comment.