From 7a5fd656f626e72a3200790f59a0ba2ca086d9c6 Mon Sep 17 00:00:00 2001 From: Viktor Kushnerov Date: Tue, 22 Oct 2019 11:59:54 +0300 Subject: [PATCH] Send selected text from any apps #40 --- ReaderTranslator/Components/ServiceProvider.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ReaderTranslator/Components/ServiceProvider.swift b/ReaderTranslator/Components/ServiceProvider.swift index 34b5237..94b6f68 100644 --- a/ReaderTranslator/Components/ServiceProvider.swift +++ b/ReaderTranslator/Components/ServiceProvider.swift @@ -19,6 +19,17 @@ class ServiceProvider: NSObject { return } - store.translateAction = .translator(text: text) + self.store.translateAction = .translator(text: text) + openText(text: text) + } + + private func openText(text: String) { + let defaultUrl = "https://translate.google.com" + guard var urlComponent = URLComponents(string: defaultUrl) else { return } + urlComponent.queryItems = [ + .init(name: "text", value: text) + ] + + if let url = urlComponent.url { Safari.openSafari(url) } } }