mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-01 20:26:00 +00:00
* ios: share extension (#4414) * ios: add share extension target * ios: Add UI * ios: send file from share-sheet * image utils * ShareError * error handling; ui-cleanup * progress bar; completion for direct chat * cleanup * cleanup * ios: unify filter and sort between forward and share sheets * ios: match share sheet styling with the main app * ios: fix text input stroke width * ios: align compose views * more of the same... * ShareAPI * remove combine * minor * Better error descriptions --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * ios: enable file sending workers in share extension (#4474) * ios: align compose background, row height and fallback images for share-sheet (#4467) Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * ios: coordinate database access between share extension, the app and notifications extension (#4472) * ios: database management proposal * Add SEState * Global event loop * minor * reset state * use apiCreateItem for local chats * simplify waiting for suspension * loading bar * Dismiss share sheet with error --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * send image message (#4481) Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * ios: improve share extension completion handling (#4486) * improve completion handling * minor * show only spinner for group send * rework event loop, errorAlert * group chat timeout loading bar * state machine WIP * event loop actor * alert * errors text * default * file error --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * ios: add remaining share types; process attachment in background on launch (#4510) * add remaining share types; process attachment in background on launch * cleanup diff * revert `makeVideoQualityLower` * reduce diff * reduce diff * iOS15 support * process events when sharing link and text * cleanup * remove video file on failure * cleanup CompletionHandler --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * ios: share extension - additional alerts and media previews (#4521) * add remaining share types; process attachment in background on launch * cleanup diff * revert `makeVideoQualityLower` * reduce diff * reduce diff * iOS15 support * process events when sharing link and text * cleanup * remove video file on failure * cleanup CompletionHandler * media previews * network timeout alert * revert framework compiler optimisation flag * suspend chat after sheet dismiss * activate chat * update * fix search * sendMessageColor, file preview, chat deselect, simplify error action * cleanup * interupt database closing when sheet is reopened quickly * cleanup redundant alert check * restore package * refactor previews, remove link preview * show link preview when becomes available * comment * dont fail on invalid image * suspend --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * ios: descriptive database errors (#4527) * ios: set share extension as inactive when suspending chat --------- Co-authored-by: Arturs Krumins <auth@levitatingpineapple.com>
187 lines
6.1 KiB
Swift
187 lines
6.1 KiB
Swift
//
|
|
// SMPServerView.swift
|
|
// SimpleX (iOS)
|
|
//
|
|
// Created by Evgeny on 15/11/2022.
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
import SimpleXChat
|
|
|
|
struct ProtocolServerView: View {
|
|
@Environment(\.dismiss) var dismiss: DismissAction
|
|
@EnvironmentObject var theme: AppTheme
|
|
let serverProtocol: ServerProtocol
|
|
@Binding var server: ServerCfg
|
|
@State var serverToEdit: ServerCfg
|
|
@State private var showTestFailure = false
|
|
@State private var testing = false
|
|
@State private var testFailure: ProtocolTestFailure?
|
|
|
|
var proto: String { serverProtocol.rawValue.uppercased() }
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
if server.preset {
|
|
presetServer()
|
|
} else {
|
|
customServer()
|
|
}
|
|
if testing {
|
|
ProgressView().scaleEffect(2)
|
|
}
|
|
}
|
|
.modifier(BackButton(label: "Your \(proto) servers", disabled: Binding.constant(false)) {
|
|
server = serverToEdit
|
|
dismiss()
|
|
})
|
|
.alert(isPresented: $showTestFailure) {
|
|
Alert(
|
|
title: Text("Server test failed!"),
|
|
message: Text(testFailure?.localizedDescription ?? "")
|
|
)
|
|
}
|
|
.onChange(of: serverToEdit.server) { _ in
|
|
serverToEdit.tested = serverToEdit.server == server.server ? server.tested : nil
|
|
}
|
|
}
|
|
|
|
private func presetServer() -> some View {
|
|
return VStack {
|
|
List {
|
|
Section(header: Text("Preset server address").foregroundColor(theme.colors.secondary)) {
|
|
Text(serverToEdit.server)
|
|
.textSelection(.enabled)
|
|
}
|
|
useServerSection(true)
|
|
}
|
|
}
|
|
}
|
|
|
|
private func customServer() -> some View {
|
|
VStack {
|
|
let serverAddress = parseServerAddress(serverToEdit.server)
|
|
let valid = serverAddress?.valid == true && serverAddress?.serverProtocol == serverProtocol
|
|
List {
|
|
Section {
|
|
TextEditor(text: $serverToEdit.server)
|
|
.multilineTextAlignment(.leading)
|
|
.autocorrectionDisabled(true)
|
|
.autocapitalization(.none)
|
|
.allowsTightening(true)
|
|
.lineLimit(10)
|
|
.frame(height: 144)
|
|
.padding(-6)
|
|
} header: {
|
|
HStack {
|
|
Text("Your server address")
|
|
.foregroundColor(theme.colors.secondary)
|
|
if !valid {
|
|
Spacer()
|
|
Image(systemName: "exclamationmark.circle").foregroundColor(.red)
|
|
}
|
|
}
|
|
}
|
|
useServerSection(valid)
|
|
if valid {
|
|
Section(header: Text("Add to another device").foregroundColor(theme.colors.secondary)) {
|
|
MutableQRCode(uri: $serverToEdit.server)
|
|
.listRowInsets(EdgeInsets(top: 12, leading: 12, bottom: 12, trailing: 12))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private func useServerSection(_ valid: Bool) -> some View {
|
|
Section(header: Text("Use server").foregroundColor(theme.colors.secondary)) {
|
|
HStack {
|
|
Button("Test server") {
|
|
testing = true
|
|
serverToEdit.tested = nil
|
|
Task {
|
|
if let f = await testServerConnection(server: $serverToEdit) {
|
|
showTestFailure = true
|
|
testFailure = f
|
|
}
|
|
await MainActor.run { testing = false }
|
|
}
|
|
}
|
|
.disabled(!valid || testing)
|
|
Spacer()
|
|
showTestStatus(server: serverToEdit)
|
|
}
|
|
let useForNewDisabled = serverToEdit.tested != true && !serverToEdit.preset
|
|
Toggle("Use for new connections", isOn: $serverToEdit.enabled)
|
|
.disabled(useForNewDisabled)
|
|
.foregroundColor(useForNewDisabled ? theme.colors.secondary : theme.colors.onBackground)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct BackButton: ViewModifier {
|
|
var label: LocalizedStringKey = "Back"
|
|
@Binding var disabled: Bool
|
|
var action: () -> Void
|
|
|
|
func body(content: Content) -> some View {
|
|
content
|
|
.navigationBarBackButtonHidden(true)
|
|
.toolbar {
|
|
ToolbarItem(placement: .navigationBarLeading) {
|
|
Button(action: action) {
|
|
HStack {
|
|
Image(systemName: "chevron.left")
|
|
Text(label)
|
|
}
|
|
}
|
|
.disabled(disabled)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@ViewBuilder func showTestStatus(server: ServerCfg) -> some View {
|
|
switch server.tested {
|
|
case .some(true):
|
|
Image(systemName: "checkmark")
|
|
.foregroundColor(.green)
|
|
case .some(false):
|
|
Image(systemName: "multiply")
|
|
.foregroundColor(.red)
|
|
case .none:
|
|
Color.clear
|
|
}
|
|
}
|
|
|
|
func testServerConnection(server: Binding<ServerCfg>) async -> ProtocolTestFailure? {
|
|
do {
|
|
let r = try await testProtoServer(server: server.wrappedValue.server)
|
|
switch r {
|
|
case .success:
|
|
await MainActor.run { server.wrappedValue.tested = true }
|
|
return nil
|
|
case let .failure(f):
|
|
await MainActor.run { server.wrappedValue.tested = false }
|
|
return f
|
|
}
|
|
} catch let error {
|
|
logger.error("testServerConnection \(responseError(error))")
|
|
await MainActor.run {
|
|
server.wrappedValue.tested = false
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
|
|
struct ProtocolServerView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
ProtocolServerView(
|
|
serverProtocol: .smp,
|
|
server: Binding.constant(ServerCfg.sampleData.custom),
|
|
serverToEdit: ServerCfg.sampleData.custom
|
|
)
|
|
}
|
|
}
|