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

Make sure Element Call uses the correct theme and language. #3017

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -554,12 +554,14 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
// MARK: Calls

private func presentCallScreen(roomProxy: RoomProxyProtocol) {
let colorScheme: ColorScheme = appMediator.windowManager.mainWindow.traitCollection.userInterfaceStyle == .light ? .light : .dark
let callScreenCoordinator = CallScreenCoordinator(parameters: .init(elementCallService: elementCallService,
clientProxy: userSession.clientProxy,
roomProxy: roomProxy,
clientID: InfoPlistReader.main.bundleIdentifier,
elementCallBaseURL: appSettings.elementCallBaseURL,
elementCallBaseURLOverride: appSettings.elementCallBaseURLOverride))
elementCallBaseURLOverride: appSettings.elementCallBaseURLOverride,
colorScheme: colorScheme))

callScreenCoordinator.actions
.sink { [weak self] action in
Expand Down
48 changes: 24 additions & 24 deletions ElementX/Sources/Mocks/Generated/GeneratedMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4922,72 +4922,72 @@ class ElementCallWidgetDriverMock: ElementCallWidgetDriverProtocol {

//MARK: - start

var startBaseURLClientIDUnderlyingCallsCount = 0
var startBaseURLClientIDCallsCount: Int {
var startBaseURLClientIDColorSchemeUnderlyingCallsCount = 0
var startBaseURLClientIDColorSchemeCallsCount: Int {
get {
if Thread.isMainThread {
return startBaseURLClientIDUnderlyingCallsCount
return startBaseURLClientIDColorSchemeUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = startBaseURLClientIDUnderlyingCallsCount
returnValue = startBaseURLClientIDColorSchemeUnderlyingCallsCount
}

return returnValue!
}
}
set {
if Thread.isMainThread {
startBaseURLClientIDUnderlyingCallsCount = newValue
startBaseURLClientIDColorSchemeUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
startBaseURLClientIDUnderlyingCallsCount = newValue
startBaseURLClientIDColorSchemeUnderlyingCallsCount = newValue
}
}
}
}
var startBaseURLClientIDCalled: Bool {
return startBaseURLClientIDCallsCount > 0
var startBaseURLClientIDColorSchemeCalled: Bool {
return startBaseURLClientIDColorSchemeCallsCount > 0
}
var startBaseURLClientIDReceivedArguments: (baseURL: URL, clientID: String)?
var startBaseURLClientIDReceivedInvocations: [(baseURL: URL, clientID: String)] = []
var startBaseURLClientIDColorSchemeReceivedArguments: (baseURL: URL, clientID: String, colorScheme: ColorScheme)?
var startBaseURLClientIDColorSchemeReceivedInvocations: [(baseURL: URL, clientID: String, colorScheme: ColorScheme)] = []

var startBaseURLClientIDUnderlyingReturnValue: Result<URL, ElementCallWidgetDriverError>!
var startBaseURLClientIDReturnValue: Result<URL, ElementCallWidgetDriverError>! {
var startBaseURLClientIDColorSchemeUnderlyingReturnValue: Result<URL, ElementCallWidgetDriverError>!
var startBaseURLClientIDColorSchemeReturnValue: Result<URL, ElementCallWidgetDriverError>! {
get {
if Thread.isMainThread {
return startBaseURLClientIDUnderlyingReturnValue
return startBaseURLClientIDColorSchemeUnderlyingReturnValue
} else {
var returnValue: Result<URL, ElementCallWidgetDriverError>? = nil
DispatchQueue.main.sync {
returnValue = startBaseURLClientIDUnderlyingReturnValue
returnValue = startBaseURLClientIDColorSchemeUnderlyingReturnValue
}

return returnValue!
}
}
set {
if Thread.isMainThread {
startBaseURLClientIDUnderlyingReturnValue = newValue
startBaseURLClientIDColorSchemeUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
startBaseURLClientIDUnderlyingReturnValue = newValue
startBaseURLClientIDColorSchemeUnderlyingReturnValue = newValue
}
}
}
}
var startBaseURLClientIDClosure: ((URL, String) async -> Result<URL, ElementCallWidgetDriverError>)?
var startBaseURLClientIDColorSchemeClosure: ((URL, String, ColorScheme) async -> Result<URL, ElementCallWidgetDriverError>)?

func start(baseURL: URL, clientID: String) async -> Result<URL, ElementCallWidgetDriverError> {
startBaseURLClientIDCallsCount += 1
startBaseURLClientIDReceivedArguments = (baseURL: baseURL, clientID: clientID)
func start(baseURL: URL, clientID: String, colorScheme: ColorScheme) async -> Result<URL, ElementCallWidgetDriverError> {
startBaseURLClientIDColorSchemeCallsCount += 1
startBaseURLClientIDColorSchemeReceivedArguments = (baseURL: baseURL, clientID: clientID, colorScheme: colorScheme)
DispatchQueue.main.async {
self.startBaseURLClientIDReceivedInvocations.append((baseURL: baseURL, clientID: clientID))
self.startBaseURLClientIDColorSchemeReceivedInvocations.append((baseURL: baseURL, clientID: clientID, colorScheme: colorScheme))
}
if let startBaseURLClientIDClosure = startBaseURLClientIDClosure {
return await startBaseURLClientIDClosure(baseURL, clientID)
if let startBaseURLClientIDColorSchemeClosure = startBaseURLClientIDColorSchemeClosure {
return await startBaseURLClientIDColorSchemeClosure(baseURL, clientID, colorScheme)
} else {
return startBaseURLClientIDReturnValue
return startBaseURLClientIDColorSchemeReturnValue
}
}
//MARK: - sendMessage
Expand Down
2 changes: 1 addition & 1 deletion ElementX/Sources/Mocks/RoomProxyMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ extension RoomProxyMock {
fatalError()
}

widgetDriver.startBaseURLClientIDReturnValue = .success(url)
widgetDriver.startBaseURLClientIDColorSchemeReturnValue = .success(url)

elementCallWidgetDriverReturnValue = widgetDriver
sendCallNotificationIfNeeededReturnValue = .success(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct CallScreenCoordinatorParameters {
let clientID: String
let elementCallBaseURL: URL
let elementCallBaseURLOverride: URL?
let colorScheme: ColorScheme
}

enum CallScreenCoordinatorAction {
Expand All @@ -45,7 +46,8 @@ final class CallScreenCoordinator: CoordinatorProtocol {
roomProxy: parameters.roomProxy,
clientID: parameters.clientID,
elementCallBaseURL: parameters.elementCallBaseURL,
elementCallBaseURLOverride: parameters.elementCallBaseURLOverride)
elementCallBaseURLOverride: parameters.elementCallBaseURLOverride,
colorScheme: parameters.colorScheme)
}

func start() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class CallScreenViewModel: CallScreenViewModelType, CallScreenViewModelProtocol
roomProxy: RoomProxyProtocol,
clientID: String,
elementCallBaseURL: URL,
elementCallBaseURLOverride: URL?) {
elementCallBaseURLOverride: URL?,
colorScheme: ColorScheme) {
self.elementCallService = elementCallService
self.roomProxy = roomProxy

Expand Down Expand Up @@ -100,7 +101,7 @@ class CallScreenViewModel: CallScreenViewModelType, CallScreenViewModelProtocol
elementCallBaseURL
}

switch await widgetDriver.start(baseURL: baseURL, clientID: clientID) {
switch await widgetDriver.start(baseURL: baseURL, clientID: clientID, colorScheme: colorScheme) {
case .success(let url):
state.url = url
case .failure(let error):
Expand Down
6 changes: 3 additions & 3 deletions ElementX/Sources/Screens/CallScreen/View/CallScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ struct CallScreen: View {
.id(context.viewState.url)
.ignoresSafeArea(edges: .bottom)
.presentationDragIndicator(.visible)
.environment(\.colorScheme, .dark)
.alert(item: $context.alertInfo)
}
}
Expand Down Expand Up @@ -181,7 +180,7 @@ struct CallScreen_Previews: PreviewProvider {
let widgetDriver = ElementCallWidgetDriverMock()
widgetDriver.underlyingMessagePublisher = .init()
widgetDriver.underlyingActions = PassthroughSubject<ElementCallWidgetDriverAction, Never>().eraseToAnyPublisher()
widgetDriver.startBaseURLClientIDReturnValue = .success(URL.userDirectory)
widgetDriver.startBaseURLClientIDColorSchemeReturnValue = .success(URL.userDirectory)

roomProxy.elementCallWidgetDriverReturnValue = widgetDriver

Expand All @@ -190,7 +189,8 @@ struct CallScreen_Previews: PreviewProvider {
roomProxy: roomProxy,
clientID: "io.element.elementx",
elementCallBaseURL: "https://call.element.io",
elementCallBaseURLOverride: nil)
elementCallBaseURLOverride: nil,
colorScheme: .light)
}()

static var previews: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
//

import Combine
import Foundation
import MatrixRustSDK
import SwiftUI

private struct ElementCallWidgetMessage: Codable {
enum Direction: String, Codable {
Expand Down Expand Up @@ -53,7 +53,7 @@ class ElementCallWidgetDriver: WidgetCapabilitiesProvider, ElementCallWidgetDriv
self.room = room
}

func start(baseURL: URL, clientID: String) async -> Result<URL, ElementCallWidgetDriverError> {
func start(baseURL: URL, clientID: String, colorScheme: ColorScheme) async -> Result<URL, ElementCallWidgetDriverError> {
guard let room = room as? Room else {
return .failure(.roomInvalid)
}
Expand All @@ -75,10 +75,13 @@ class ElementCallWidgetDriver: WidgetCapabilitiesProvider, ElementCallWidgetDriv
return .failure(.failedBuildingWidgetSettings)
}

let languageTag = "\(Locale.current.language.languageCode ?? "en")-\(Locale.current.language.region ?? "US")"
let theme = colorScheme == .light ? "light" : "dark"

guard let urlString = try? await generateWebviewUrl(widgetSettings: widgetSettings, room: room,
props: .init(clientId: clientID,
languageTag: nil,
theme: nil)) else {
languageTag: languageTag,
theme: theme)) else {
return .failure(.failedBuildingCallURL)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//

import Combine
import Foundation
import SwiftUI

enum ElementCallWidgetDriverError: Error {
case roomInvalid
Expand All @@ -37,7 +37,7 @@ protocol ElementCallWidgetDriverProtocol {
var messagePublisher: PassthroughSubject<String, Never> { get }
var actions: AnyPublisher<ElementCallWidgetDriverAction, Never> { get }

func start(baseURL: URL, clientID: String) async -> Result<URL, ElementCallWidgetDriverError>
func start(baseURL: URL, clientID: String, colorScheme: ColorScheme) async -> Result<URL, ElementCallWidgetDriverError>

func sendMessage(_ message: String) async -> Result<Bool, ElementCallWidgetDriverError>
}
Loading