From 32812a6f2fa016144daa73f308ad7e2901362e9e Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sun, 10 Sep 2023 17:02:41 +0400 Subject: [PATCH] Web app improvements --- .../Sources/PeerInfo/PeerInfoScreen.swift | 76 ++++++------------- .../WebUI/Sources/WebAppController.swift | 62 +++++++++------ 2 files changed, 59 insertions(+), 79 deletions(-) diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index 8b9d2a16ac3..c760fee6e3b 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -4615,7 +4615,6 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro })) } - private let openBotAppDisposable = MetaDisposable() private func openBotApp(_ bot: AttachMenuBot) { guard let controller = self.controller else { return @@ -4626,61 +4625,30 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro return } - let progressSignal = Signal { [weak self] subscriber in - let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: nil)) - self?.controller?.present(controller, in: .window(.root)) - return ActionDisposable { [weak controller] in - Queue.mainQueue().async() { - controller?.dismiss() - } - } - } - |> runOn(Queue.mainQueue()) - |> delay(0.35, queue: Queue.mainQueue()) - let progressDisposable = progressSignal.start() - - let signal: Signal = self.context.engine.messages.requestSimpleWebView(botId: bot.peer.id, url: nil, source: .settings, themeParams: generateWebAppThemeParams(self.presentationData.theme)) - |> afterDisposed { - Queue.mainQueue().async { - progressDisposable.dispose() - } - } + let params = WebAppParameters(source: .settings, peerId: self.context.account.peerId, botId: bot.peer.id, botName: bot.peer.compactDisplayTitle, url: nil, queryId: nil, payload: nil, buttonText: nil, keepAliveSignal: nil, forceHasSettings: bot.flags.contains(.hasSettings)) + let controller = standaloneWebAppController(context: self.context, updatedPresentationData: self.controller?.updatedPresentationData, params: params, threadId: nil, openUrl: { [weak self] url, concealed, commit in + self?.openUrl(url: url, concealed: concealed, external: false, forceExternal: true, commit: commit) + }, requestSwitchInline: { _, _, _ in + }, getNavigationController: { [weak self] in + return self?.controller?.navigationController as? NavigationController + }) + controller.navigationPresentation = .flatModal + self.controller?.push(controller) - self.openBotAppDisposable.set((signal - |> deliverOnMainQueue).start(next: { [weak self] url in - guard let self else { - return - } - let params = WebAppParameters(source: .settings, peerId: self.context.account.peerId, botId: bot.peer.id, botName: bot.peer.compactDisplayTitle, url: url, queryId: nil, payload: nil, buttonText: nil, keepAliveSignal: nil, forceHasSettings: bot.flags.contains(.hasSettings)) - let controller = standaloneWebAppController(context: self.context, updatedPresentationData: self.controller?.updatedPresentationData, params: params, threadId: nil, openUrl: { [weak self] url, concealed, commit in - self?.openUrl(url: url, concealed: concealed, external: false, forceExternal: true, commit: commit) - }, requestSwitchInline: { _, _, _ in - }, getNavigationController: { [weak self] in - return self?.controller?.navigationController as? NavigationController + if installed { + Queue.mainQueue().after(0.3, { + let text: String + if bot.flags.contains(.showInSettings) { + text = presentationData.strings.WebApp_ShortcutsSettingsAdded(bot.peer.compactDisplayTitle).string + } else { + text = presentationData.strings.WebApp_ShortcutsAdded(bot.peer.compactDisplayTitle).string + } + controller.present( + UndoOverlayController(presentationData: presentationData, content: .succeed(text: text, timeout: 5.0), elevatedLayout: false, position: .top, action: { _ in return false }), + in: .current + ) }) - controller.navigationPresentation = .flatModal - self.controller?.push(controller) - - if installed { - Queue.mainQueue().after(0.3, { - let text: String - if bot.flags.contains(.showInSettings) { - text = presentationData.strings.WebApp_ShortcutsSettingsAdded(bot.peer.compactDisplayTitle).string - } else { - text = presentationData.strings.WebApp_ShortcutsAdded(bot.peer.compactDisplayTitle).string - } - controller.present( - UndoOverlayController(presentationData: presentationData, content: .succeed(text: text, timeout: 5.0), elevatedLayout: false, position: .top, action: { _ in return false }), - in: .current - ) - }) - } - }, error: { [weak self] error in - if let self { - self.controller?.present(textAlertController(context: self.context, updatedPresentationData: self.controller?.updatedPresentationData, title: nil, text: self.presentationData.strings.Login_UnknownError, actions: [TextAlertAction(type: .defaultAction, title: self.presentationData.strings.Common_OK, action: { - })]), in: .window(.root)) - } - })) + } } if bot.flags.contains(.notActivated) || bot.flags.contains(.showInSettingsDisclaimer) { diff --git a/submodules/WebUI/Sources/WebAppController.swift b/submodules/WebUI/Sources/WebAppController.swift index c2bb514522f..ffcd3d737a4 100644 --- a/submodules/WebUI/Sources/WebAppController.swift +++ b/submodules/WebUI/Sources/WebAppController.swift @@ -320,14 +320,14 @@ public final class WebAppController: ViewController, AttachmentContainable { } self.webView = webView + self.addSubnode(self.backgroundNode) + self.addSubnode(self.headerBackgroundNode) + let placeholderNode = ShimmerEffectNode() placeholderNode.allowsGroupOpacity = true self.addSubnode(placeholderNode) self.placeholderNode = placeholderNode - self.addSubnode(self.backgroundNode) - self.addSubnode(self.headerBackgroundNode) - let placeholder: Signal<(FileMediaReference, Bool)?, NoError> if durgerKingBotIds.contains(controller.botId.id._internalGetInt64Value()) { placeholder = .single(nil) @@ -421,28 +421,40 @@ public final class WebAppController: ViewController, AttachmentContainable { }) } } else { - let _ = (context.engine.messages.requestWebView(peerId: controller.peerId, botId: controller.botId, url: controller.url, payload: controller.payload, themeParams: generateWebAppThemeParams(presentationData.theme), fromMenu: controller.source == .menu, replyToMessageId: controller.replyToMessageId, threadId: controller.threadId) - |> deliverOnMainQueue).start(next: { [weak self] result in - guard let strongSelf = self else { - return - } - if let parsedUrl = URL(string: result.url) { - strongSelf.queryId = result.queryId - strongSelf.webView?.load(URLRequest(url: parsedUrl)) - - strongSelf.keepAliveDisposable = (result.keepAliveSignal - |> deliverOnMainQueue).start(error: { [weak self] _ in - if let strongSelf = self { - strongSelf.controller?.dismiss() - } - }, completed: { [weak self] in - if let strongSelf = self { - strongSelf.controller?.completion() - strongSelf.controller?.dismiss() - } - }) - } - }) + if controller.source.isSimple { + let _ = (context.engine.messages.requestSimpleWebView(botId: controller.botId, url: nil, source: .settings, themeParams: generateWebAppThemeParams(presentationData.theme)) + |> deliverOnMainQueue).start(next: { [weak self] result in + guard let strongSelf = self else { + return + } + if let parsedUrl = URL(string: result) { + strongSelf.webView?.load(URLRequest(url: parsedUrl)) + } + }) + } else { + let _ = (context.engine.messages.requestWebView(peerId: controller.peerId, botId: controller.botId, url: controller.url, payload: controller.payload, themeParams: generateWebAppThemeParams(presentationData.theme), fromMenu: controller.source == .menu, replyToMessageId: controller.replyToMessageId, threadId: controller.threadId) + |> deliverOnMainQueue).start(next: { [weak self] result in + guard let strongSelf = self else { + return + } + if let parsedUrl = URL(string: result.url) { + strongSelf.queryId = result.queryId + strongSelf.webView?.load(URLRequest(url: parsedUrl)) + + strongSelf.keepAliveDisposable = (result.keepAliveSignal + |> deliverOnMainQueue).start(error: { [weak self] _ in + if let strongSelf = self { + strongSelf.controller?.dismiss() + } + }, completed: { [weak self] in + if let strongSelf = self { + strongSelf.controller?.completion() + strongSelf.controller?.dismiss() + } + }) + } + }) + } } }