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

Introduce process argument support #703

Merged
merged 1 commit into from
Aug 3, 2023
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
16 changes: 6 additions & 10 deletions GliaWidgets/Sources/Component/Bubble/BubbleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ enum BubbleKind {
case view(UIView)
}

class BubbleView: UIView {
class BubbleView: BaseView {
var kind: BubbleKind = .userImage(url: nil) {
didSet { update(kind) }
}
Expand Down Expand Up @@ -37,14 +37,11 @@ class BubbleView: UIView {
) {
self.style = style
self.environment = environment
super.init(frame: .zero)
setup()
layout()
super.init()
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
required init() {
fatalError("init() has not been implemented")
}

override func layoutSubviews() {
Expand Down Expand Up @@ -98,7 +95,8 @@ class BubbleView: UIView {
badgeView?.newItemCount = itemCount
}

private func setup() {
override func setup() {
super.setup()
clipsToBounds = false
layer.masksToBounds = false
layer.shadowColor = UIColor.black.cgColor
Expand All @@ -119,8 +117,6 @@ class BubbleView: UIView {
update(kind)
}

private func layout() {}

private func update(_ kind: BubbleKind) {
switch kind {
case .userImage(url: let url):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class ChatMessageEntryView: BaseView {
action: #selector(textViewContainerTap)
)
messageContainerView.addGestureRecognizer(tapRecognizer)
messageContainerView.accessibilityIdentifier = "chat_messageContainerView"

textView.accessibilityIdentifier = "chat_textView"
textView.delegate = self
Expand Down
29 changes: 10 additions & 19 deletions GliaWidgets/Sources/ViewController/GliaViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class GliaViewController: UIViewController {
bubbleWindow.alpha = 0.0
bubbleWindow.isHidden = false
self.bubbleWindow = bubbleWindow
bubbleWindow.makeKeyAndVisible()

UIView.animate(
withDuration: animated ? 0.4 : 0.0,
Expand All @@ -115,25 +116,15 @@ class GliaViewController: UIViewController {
}

private func makeBubbleWindow(bubbleView: BubbleView) -> BubbleWindow {
if #available(iOS 13.0, *) {
if let windowScene = windowScene() {
return BubbleWindow(
bubbleView: bubbleView,
environment: .init(
uiScreen: environment.uiScreen,
uiApplication: environment.uiApplication
),
windowScene: windowScene
)
} else {
return BubbleWindow(
bubbleView: bubbleView,
environment: .init(
uiScreen: environment.uiScreen,
uiApplication: environment.uiApplication
)
)
}
if let windowScene = windowScene() {
yurii-glia marked this conversation as resolved.
Show resolved Hide resolved
return BubbleWindow(
bubbleView: bubbleView,
environment: .init(
uiScreen: environment.uiScreen,
uiApplication: environment.uiApplication
),
windowScene: windowScene
)
} else {
return BubbleWindow(
bubbleView: bubbleView,
Expand Down
63 changes: 46 additions & 17 deletions TestingApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,17 @@ import GliaCoreSDK
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func applicationDidFinishLaunching(_ application: UIApplication) {
handleProcessInfo()
handleSetAnimationsEnabled()
}

func application(
_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {

guard
let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
let queryItems = components.queryItems
else {
debugPrint("URL is not valid. url='\(url.absoluteString)'.")
return false
}

guard let root = window?.rootViewController as? ViewController else {
return false
}

if components.host == "configure" {
root.updateConfiguration(with: queryItems)
}
handleConfigurationUrl(url: url)
return true
}

Expand All @@ -46,4 +36,43 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
) {
debugPrint("💥 Failed to register for remote notifications. Error: \(error.localizedDescription)")
}

private func handleProcessInfo() {
guard let configurationUrl = ProcessInfo.processInfo.environment["CONFIGURATION_URL"] else {
return
}

debugPrint(configurationUrl)

guard let url = URL(string: configurationUrl) else { return }
handleConfigurationUrl(url: url)
}

@discardableResult
private func handleConfigurationUrl(url: URL) -> Bool {
guard
let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
let queryItems = components.queryItems
else {
debugPrint("URL is not valid. url='\(url.absoluteString)'.")
return false
}

guard let root = window?.rootViewController as? ViewController else {
return false
}

if components.host == "configure" {
root.updateConfiguration(with: queryItems)
}

return true
}

private func handleSetAnimationsEnabled() {
let env = ProcessInfo.processInfo.environment
if env["SET_ANIMATION_ENABLED"] == "false" {
UIView.setAnimationsEnabled(false)
}
}
}
Loading