Skip to content

Commit

Permalink
Web app improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
laktyushin committed Sep 10, 2023
1 parent e5d2537 commit 32812a6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 79 deletions.
76 changes: 22 additions & 54 deletions submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -4626,61 +4625,30 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
return
}

let progressSignal = Signal<Never, NoError> { [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<String, RequestSimpleWebViewError> = 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) {
Expand Down
62 changes: 37 additions & 25 deletions submodules/WebUI/Sources/WebAppController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
}
})
}
})
}
}
}

Expand Down

0 comments on commit 32812a6

Please sign in to comment.