Skip to content

Commit

Permalink
yay! New SwiftUI, relay functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JJTech0130 committed Mar 26, 2024
1 parent 31ffd6d commit 3dab327
Show file tree
Hide file tree
Showing 9 changed files with 341 additions and 29 deletions.
45 changes: 44 additions & 1 deletion ValidationRelay.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,34 @@
480989A62BB0C01A00B49AE8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 480989A52BB0C01A00B49AE8 /* Assets.xcassets */; };
480989A92BB0C01A00B49AE8 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 480989A82BB0C01A00B49AE8 /* Preview Assets.xcassets */; };
480989B32BB0C19300B49AE8 /* absd.defs in Sources */ = {isa = PBXBuildFile; fileRef = 480989B22BB0C0F800B49AE8 /* absd.defs */; settings = {ATTRIBUTES = (Client, ); }; };
48D289112BB3579000EA9DEC /* libMobileGestalt.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 48D289102BB3579000EA9DEC /* libMobileGestalt.tbd */; };
48D8604A2BB0DD110092EF79 /* ValidationData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48D860492BB0DD110092EF79 /* ValidationData.swift */; };
48D8604D2BB1B8CC0092EF79 /* NWWebSocket in Frameworks */ = {isa = PBXBuildFile; productRef = 48D8604C2BB1B8CC0092EF79 /* NWWebSocket */; };
48D8604F2BB1B8EB0092EF79 /* Relay.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48D8604E2BB1B8EB0092EF79 /* Relay.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
4809899E2BB0C01900B49AE8 /* ValidationRelay.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ValidationRelay.app; sourceTree = BUILT_PRODUCTS_DIR; };
480989A12BB0C01900B49AE8 /* ValidationRelayApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValidationRelayApp.swift; sourceTree = "<group>"; };
480989A32BB0C01900B49AE8 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
480989A32BB0C01900B49AE8 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; usesTabs = 0; };
480989A52BB0C01A00B49AE8 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
480989A82BB0C01A00B49AE8 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
480989AF2BB0C0AF00B49AE8 /* ValidationRelay-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ValidationRelay-Bridging-Header.h"; sourceTree = "<group>"; };
480989B22BB0C0F800B49AE8 /* absd.defs */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.mig; path = absd.defs; sourceTree = "<group>"; };
480989B42BB0D16400B49AE8 /* ValidationRelay.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = ValidationRelay.entitlements; sourceTree = "<group>"; };
48D289102BB3579000EA9DEC /* libMobileGestalt.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libMobileGestalt.tbd; path = usr/lib/libMobileGestalt.tbd; sourceTree = SDKROOT; };
48D860482BB0D7BF0092EF79 /* build.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = "<group>"; };
48D860492BB0DD110092EF79 /* ValidationData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValidationData.swift; sourceTree = "<group>"; };
48D8604E2BB1B8EB0092EF79 /* Relay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Relay.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
4809899B2BB0C01900B49AE8 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
48D289112BB3579000EA9DEC /* libMobileGestalt.tbd in Frameworks */,
48D8604D2BB1B8CC0092EF79 /* NWWebSocket in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -45,6 +52,7 @@
48D860482BB0D7BF0092EF79 /* build.sh */,
480989A02BB0C01900B49AE8 /* ValidationRelay */,
4809899F2BB0C01900B49AE8 /* Products */,
48D2890F2BB3579000EA9DEC /* Frameworks */,
);
sourceTree = "<group>";
};
Expand All @@ -67,6 +75,7 @@
480989A72BB0C01A00B49AE8 /* Preview Content */,
480989AF2BB0C0AF00B49AE8 /* ValidationRelay-Bridging-Header.h */,
48D860492BB0DD110092EF79 /* ValidationData.swift */,
48D8604E2BB1B8EB0092EF79 /* Relay.swift */,
);
path = ValidationRelay;
sourceTree = "<group>";
Expand All @@ -79,6 +88,14 @@
path = "Preview Content";
sourceTree = "<group>";
};
48D2890F2BB3579000EA9DEC /* Frameworks */ = {
isa = PBXGroup;
children = (
48D289102BB3579000EA9DEC /* libMobileGestalt.tbd */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand All @@ -95,6 +112,9 @@
dependencies = (
);
name = ValidationRelay;
packageProductDependencies = (
48D8604C2BB1B8CC0092EF79 /* NWWebSocket */,
);
productName = ValidationRelay;
productReference = 4809899E2BB0C01900B49AE8 /* ValidationRelay.app */;
productType = "com.apple.product-type.application";
Expand Down Expand Up @@ -124,6 +144,9 @@
Base,
);
mainGroup = 480989952BB0C01900B49AE8;
packageReferences = (
48D8604B2BB1B8CC0092EF79 /* XCRemoteSwiftPackageReference "NWWebSocket" */,
);
productRefGroup = 4809899F2BB0C01900B49AE8 /* Products */;
projectDirPath = "";
projectRoot = "";
Expand Down Expand Up @@ -154,6 +177,7 @@
480989B32BB0C19300B49AE8 /* absd.defs in Sources */,
480989A42BB0C01900B49AE8 /* ContentView.swift in Sources */,
480989A22BB0C01900B49AE8 /* ValidationRelayApp.swift in Sources */,
48D8604F2BB1B8EB0092EF79 /* Relay.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -374,6 +398,25 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
48D8604B2BB1B8CC0092EF79 /* XCRemoteSwiftPackageReference "NWWebSocket" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/pusher/NWWebSocket.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.5.4;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
48D8604C2BB1B8CC0092EF79 /* NWWebSocket */ = {
isa = XCSwiftPackageProductDependency;
package = 48D8604B2BB1B8CC0092EF79 /* XCRemoteSwiftPackageReference "NWWebSocket" */;
productName = NWWebSocket;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 480989962BB0C01900B49AE8 /* Project object */;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "nwwebsocket",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pusher/NWWebSocket.git",
"state" : {
"revision" : "1e545fcb53966272fc042aa17ae932f11239e00f",
"version" : "0.5.4"
}
}
],
"version" : 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,16 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<PreActions>
<ExecutionAction
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
<ActionContent
title = "Run Script"
scriptText = "# Type a script or drag a script file from your workspace to insert its path.&#10;/Users/jjtech/Desktop/ValidationRelay/build.sh&#10;"
shellToInvoke = "/usr/bin/env bash">
</ActionContent>
</ExecutionAction>
</PreActions>
<MacroExpansion>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "4809899D2BB0C01900B49AE8"
BuildableName = "ValidationRelay.app"
BlueprintName = "ValidationRelay"
ReferencedContainer = "container:ValidationRelay.xcodeproj">
</BuildableReference>
</MacroExpansion>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
98 changes: 88 additions & 10 deletions ValidationRelay/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,98 @@
import SwiftUI

struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
//.foregroundStyle(.tint)
Text("Hello, world!")
//@State private var registrationCode = "Not Connected"
//@State private var connectionStatusMessage = ""

@State private var wantRelayConnected = false // TODO: Come up with a method to auto connect

@AppStorage("selectedRelay") private var selectedRelay = "Beeper"
@AppStorage("customRelayURL") private var customRelayURL = ""

//private var relayConnectionManager: RelayConnectionManager? = nil
@ObservedObject var relayConnectionManager: RelayConnectionManager

// init() {
// relayConnectionManager = RelayConnectionManager(registrationCodeBinding: $registrationCode, connectionStatusMessageBinding: $connectionStatusMessage)
// }

func getCurrentRelayURL() -> URL {
if selectedRelay == "Custom" {
if let url = URL(string: customRelayURL) {
return url
}
} else if selectedRelay == "pypush" {
return URL(string: "wss://registration-relay.jjtech.dev/api/v1/provider")!
}
.padding()
.onAppear {
test()

// Default to Beeper relay
selectedRelay = "Beeper"
return URL(string: "wss://registration-relay.beeper.com/api/v1/provider")!
}

var body: some View {
List {
Section {
Toggle("Relay", isOn: $wantRelayConnected)
.onChange(of: wantRelayConnected) { newValue in
// Connect or disconnect the relay
if newValue {
relayConnectionManager.connect(getCurrentRelayURL())
} else {
relayConnectionManager.disconnect()
}
}
HStack {
Text("Registration Code")
Spacer()
Text(relayConnectionManager.registrationCode)
.foregroundColor(.secondary)
}
} footer: {
Text(relayConnectionManager.connectionStatusMessage)
}
Section {
// TODO: Actually support running in the background
Toggle("Run in Background", isOn: .constant(false))
.disabled(true)
Picker("Relay", selection: $selectedRelay) {
Text("Beeper").tag("Beeper")
//Text("pypush").tag("pypush")
Text("Custom").tag("Custom")
}
.pickerStyle(.segmented)
.onChange(of: selectedRelay) { newValue in
// Disconnect when the user is switching relay servers
wantRelayConnected = false
}
if (selectedRelay == "Custom") {
TextField("Custom Relay Server URL", text: $customRelayURL)
.textContentType(.URL)
.autocorrectionDisabled()
.autocapitalization(.none)
}
} header: {
Text("Connection settings")
} footer: {
Text("Beeper's relay server is recommended for most users")
}

Section {
Button("Reset Registration Code") {
// Do reset stuff
}
//.foregroundColor(.red)
.frame(maxWidth: .infinity)
.disabled(true)
} footer: {
Text("You will need to re-enter the code on your other devices")
}
}
.listStyle(.grouped)
}

}

#Preview {
ContentView()
ContentView(relayConnectionManager: RelayConnectionManager())
}
Loading

0 comments on commit 3dab327

Please sign in to comment.