Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

New Mixer Integration

  • Loading branch information
Tim Palade committed Apr 16, 2018
1 parent 5e0d7fa commit 506cd971056873ca5ba03ecd6d447fb890ec9647
@@ -454,6 +454,10 @@
A9072B801D07B34100459960 /* NoImageModeHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9072B7F1D07B34100459960 /* NoImageModeHelper.swift */; };
A93067E81D0FE18E00C49C6E /* NightModeHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93067E71D0FE18E00C49C6E /* NightModeHelper.swift */; };
AF24CBAE2068E3B000DBE428 /* TrackersController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF24CB9F2068E3B000DBE428 /* TrackersController.swift */; };
AF28D3D8207E32250065FF86 /* PermissionManagerModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF28D3D7207E32250065FF86 /* PermissionManagerModule.swift */; };
AF28D3DB207E325F0065FF86 /* PermissionManagerModuleBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = AF28D3DA207E325F0065FF86 /* PermissionManagerModuleBridge.m */; };
AF28D3DD207E378E0065FF86 /* GeoLocationBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = AF28D3DC207E378E0065FF86 /* GeoLocationBridge.m */; };
AF28D3DF207E37A20065FF86 /* GeoLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF28D3DE207E37A20065FF86 /* GeoLocation.swift */; };
AF53D3BC206A346B0012A11F /* TabExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF53D3BB206A346B0012A11F /* TabExtension.swift */; };
AF6FA97220652C6800D7F9F0 /* ghostery_content_blocker.json in Resources */ = {isa = PBXBuildFile; fileRef = AF6FA96E20652C6700D7F9F0 /* ghostery_content_blocker.json */; };
AF6FA97320652C6800D7F9F0 /* preload.js in Resources */ = {isa = PBXBuildFile; fileRef = AF6FA96F20652C6800D7F9F0 /* preload.js */; };
@@ -1874,6 +1878,10 @@
A9072B7F1D07B34100459960 /* NoImageModeHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoImageModeHelper.swift; sourceTree = "<group>"; };
A93067E71D0FE18E00C49C6E /* NightModeHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NightModeHelper.swift; sourceTree = "<group>"; };
AF24CB9F2068E3B000DBE428 /* TrackersController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrackersController.swift; sourceTree = "<group>"; };
AF28D3D7207E32250065FF86 /* PermissionManagerModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PermissionManagerModule.swift; sourceTree = "<group>"; };
AF28D3DA207E325F0065FF86 /* PermissionManagerModuleBridge.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PermissionManagerModuleBridge.m; sourceTree = "<group>"; };
AF28D3DC207E378E0065FF86 /* GeoLocationBridge.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GeoLocationBridge.m; sourceTree = "<group>"; };
AF28D3DE207E37A20065FF86 /* GeoLocation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeoLocation.swift; sourceTree = "<group>"; };
AF53D3BB206A346B0012A11F /* TabExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabExtension.swift; sourceTree = "<group>"; };
AF6FA96E20652C6700D7F9F0 /* ghostery_content_blocker.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ghostery_content_blocker.json; sourceTree = "<group>"; };
AF6FA96F20652C6800D7F9F0 /* preload.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = preload.js; sourceTree = "<group>"; };
@@ -3230,6 +3238,10 @@
4F30F5042051670C0049E4F6 /* TelemetryBridge.m */,
4F30F5052051670C0049E4F6 /* UserAgentConstants.swift */,
4F30F5062051670C0049E4F6 /* UserAgentConstantsBridge.m */,
AF28D3D7207E32250065FF86 /* PermissionManagerModule.swift */,
AF28D3DA207E325F0065FF86 /* PermissionManagerModuleBridge.m */,
AF28D3DE207E37A20065FF86 /* GeoLocation.swift */,
AF28D3DC207E378E0065FF86 /* GeoLocationBridge.m */,
);
path = Modules;
sourceTree = "<group>";
@@ -6209,6 +6221,7 @@
0B3E7D951B27A7CE00E2E84D /* AboutHomeHandler.swift in Sources */,
D331DFCA1CB6E9EE009B5DA2 /* OldStrings.swift in Sources */,
1EDF0B22207B86A200856493 /* QuerySuggestionView.swift in Sources */,
AF28D3DB207E325F0065FF86 /* PermissionManagerModuleBridge.m in Sources */,
4F3FA4E520444FE900A9E7F6 /* StringExtension.swift in Sources */,
1EAFE56B205FFE82006A36B4 /* AutoForgetTabTableViewController.swift in Sources */,
D3BE7B461B054F8600641031 /* TestAppDelegate.swift in Sources */,
@@ -6333,6 +6346,7 @@
4F3046B1204FF18700C99162 /* AppStatus.swift in Sources */,
F84B22241A09122500AAB793 /* HomePanelViewController.swift in Sources */,
4FBBC1522035E5C400445AD1 /* NewsDataSource.swift in Sources */,
AF28D3D8207E32250065FF86 /* PermissionManagerModule.swift in Sources */,
39455F771FC83F430088A22C /* TabEventHandler.swift in Sources */,
E47616C71AB74CA600E7DD25 /* ReaderModeBarView.swift in Sources */,
D88FDA9F1F4E2B9200FD9709 /* PhotonActionSheetProtocol.swift in Sources */,
@@ -6345,6 +6359,7 @@
2F44FCCB1A9E972E00FD20CC /* SearchEnginePicker.swift in Sources */,
D02816C21ECA5E2A00240CAA /* HistoryStateHelper.swift in Sources */,
E68E7ACB1CAC1D4500FDCA76 /* PagingPasscodeViewController.swift in Sources */,
AF28D3DF207E37A20065FF86 /* GeoLocation.swift in Sources */,
D34DC8531A16C40C00D49B7B /* Profile.swift in Sources */,
AF6FA99020652D4600D7F9F0 /* TrackerListHosts.swift in Sources */,
392ED6B71D06E85E009D9B62 /* NewTabChoiceViewController.swift in Sources */,
@@ -6358,6 +6373,7 @@
1EAFE56F205FFE82006A36B4 /* HumanWebSettingsTableViewController.swift in Sources */,
4F0445E2203344E300E2C0C7 /* LogoLoader.swift in Sources */,
4F30F5082051670C0049E4F6 /* AutoCompletion.swift in Sources */,
AF28D3DD207E378E0065FF86 /* GeoLocationBridge.m in Sources */,
E68AEDB01B18F81A00133D99 /* SwipeAnimator.swift in Sources */,
4F30F50A2051670C0049E4F6 /* BrowserActions.swift in Sources */,
3BF56D271CDBBE1F00AC4D75 /* SimpleToast.swift in Sources */,
@@ -50,6 +50,8 @@ class AutocompleteTextField: UITextField, UITextFieldDelegate {
self.textDidChange(self)
}
}
//Cliqz: Cliqz Search
private var lastText: String?

override var accessibilityValue: String? {
get {
@@ -253,6 +255,9 @@ class AutocompleteTextField: UITextField, UITextFieldDelegate {
//Cliqz: Always notify text change
notifyTextChanged?()
}
//Cliqz: Cliqz Search
Engine.sharedInstance.sendUrlBarInputEvent(newString: textField.text, lastString: lastText)
lastText = textField.text
}

// Reset the cursor to the end of the text field.
@@ -104,4 +104,49 @@ open class Engine {
}

}

// MARK :- Search
func sendUrlBarFocusEvent() {
debugPrint("urlbar in focus")
self.getBridge().publishEvent("urlbar:focus", args: [[:]])
}

func sendUrlBarNotInFocusEvent() {
debugPrint("urlbar NOT in focus")
self.getBridge().publishEvent("urlbar:blur", args: [[:]])
}

func sendUrlBarInputEvent(newString: String?, lastString: String?) {
debugPrint("newString = \(newString ?? "null") | lastString = \(lastString ?? "null")")

guard let newString = newString, let lastString = lastString else {
return
}

//Invariant: The newString and oldString must differ by one character at the end
guard abs(newString.count - lastString.count) == 1 && (newString == lastString.dropLast() || newString.dropLast() == lastString) else {
if newString == "" {
let dict:[String: Any] = ["isTyped": true, "query": lastString, "keyCode":""]
self.getBridge().publishEvent("urlbar:input", args: [dict])
}
else {
let dict:[String: Any] = ["isTyped": true, "query": newString, "keyCode":""]
self.getBridge().publishEvent("urlbar:input", args: [dict])
}
return
}

var keyCode = ""

if newString.count < lastString.count {
keyCode = "Backspace"
}
else if newString.count > 0 {
keyCode = "Key" + String(newString.last!).uppercased()
}

let dict: [String: Any] = ["isTyped": true, "query": newString, "keyCode": keyCode]

self.getBridge().publishEvent("urlbar:input", args: [dict])
}
}
@@ -16,11 +16,7 @@ open class BrowserActions: RCTEventEmitter {
@objc(searchHistory:callback:)
func searchHistory(query: NSString, callback: RCTResponseSenderBlock) {
debugPrint("searchHistory")
//don't send empty stuff
let history = getHistory()
if history.count > 0 {
callback([history])
}
callback(getHistory())
}

func getHistory() -> [[String: String]] {
@@ -0,0 +1,13 @@
//
// GeolocationBridge.m
// Client
//
// Created by Tim Palade on 4/11/18.
// Copyright © 2018 Mozilla. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
@interface RCT_EXTERN_MODULE(GeoLocation, NSObject)
RCT_EXTERN_METHOD(getCurrentPosition:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
@end
@@ -0,0 +1,20 @@
//
// Geolocation.swift
// Client
//
// Created by Tim Palade on 4/11/18.
// Copyright © 2018 Mozilla. All rights reserved.
//
import React

@objc(GeoLocation)
class GeoLocation: RCTEventEmitter {
@objc(getCurrentPosition:reject:)
func getCurrentPosition(resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
//use only the resolve block
if let l = LocationManager.sharedInstance.getUserLocation() {
resolve(["latitude": l.coordinate.latitude, "longitude": l.coordinate.longitude])
}
}
}
@@ -0,0 +1,44 @@
//
// PermissionManagerModule.swift
// Client
//
// Created by Tim Palade on 4/11/18.
// Copyright © 2018 Mozilla. All rights reserved.
//
import React

@objc(PermissionManagerModule)
class PermissionManagerModule: RCTEventEmitter {

let permissions = ["ACCESS_FINE_LOCATION": "LocationPermission", "WRITE_EXTERNAL_STORAGE": "Undefined for iOS"]
let results = ["GRANTED": "Success", "REJECTED": "Failure"]

@objc(check:resolve:reject:)
func check(permission: NSString, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
//use only the resolve block
if String(permission) == permissions["ACCESS_FINE_LOCATION"]! {
LocationManager.sharedInstance.isLocationAcessEnabled() ? resolve(results["GRANTED"]) : resolve(results["REJECTED"])
}
}

@objc(request:resolve:reject:)
func request(permission:NSString, resolve: @escaping RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
//use only the resolve block
if String(permission) == permissions["ACCESS_FINE_LOCATION"]! {
LocationManager.sharedInstance.shareLocation(callback: { (result) in
if result == true {
resolve(self.results["GRANTED"])
}
else {
resolve(self.results["REJECTED"])
}
})
}
}

override func constantsToExport() -> [AnyHashable : Any]! {
return ["PERMISSIONS": permissions, "RESULTS": results]
}
}
@@ -0,0 +1,14 @@
//
// PermissionManagerModuleBridge.m
// Client
//
// Created by Tim Palade on 4/11/18.
// Copyright © 2018 Mozilla. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
@interface RCT_EXTERN_MODULE(PermissionManagerModule, NSObject)
RCT_EXTERN_METHOD(check:(nullable NSString *)permission resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(request:(nullable NSString *)permission resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
@end
@@ -35,12 +35,10 @@ let CallSearchNotification = NSNotification.Name(rawValue: "mobile-search:call")
let MapSearchNotification = NSNotification.Name(rawValue: "mobile-search:map")
let ShareLocationSearchNotification = NSNotification.Name(rawValue: "mobile-search:share-location")

//let SearchEngineChangedNotification = Notification.Name(rawValue: "SearchEngineChangedNotification")
let SearchEngineChangedNotification = Notification.Name(rawValue: "SearchEngineChangedNotification")

class CliqzSearchViewController : UIViewController, KeyboardHelperDelegate, UIAlertViewDelegate {

fileprivate var lastQuery: String?

let searchView = Engine.sharedInstance.rootView

private static let KVOLoading = "loading"
@@ -50,11 +48,7 @@ class CliqzSearchViewController : UIViewController, KeyboardHelperDelegate, UIAl

weak var delegate: SearchViewDelegate?

var searchQuery: String? {
didSet {
self.loadData(searchQuery!)
}
}
var searchQuery: String? = nil

var profile: Profile

@@ -72,7 +66,7 @@ class CliqzSearchViewController : UIViewController, KeyboardHelperDelegate, UIAl
NotificationCenter.default.addObserver(self, selector: #selector(autocomplete(_:)), name: AutoCompleteNotification, object: nil)

//TODO: Send notification when search engine is changed
//NotificationCenter.default.addObserver(self, selector: #selector(searchEngineChanged), name: SearchEngineChangedNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(searchEngineChanged), name: SearchEngineChangedNotification, object: nil)

}

@@ -102,8 +96,6 @@ class CliqzSearchViewController : UIViewController, KeyboardHelperDelegate, UIAl

self.updateExtensionPreferences()
self.updateExtensionSearchEngine()

NotificationCenter.default.addObserver(self, selector: #selector(searchWithLastQuery), name: NSNotification.Name(rawValue: LocationManager.NotificationUserLocationAvailable), object: nil)
}

override func viewWillDisappear(_ animated: Bool) {
@@ -119,41 +111,9 @@ class CliqzSearchViewController : UIViewController, KeyboardHelperDelegate, UIAl
super.didReceiveMemoryWarning()
}

func sendUrlBarFocusEvent() {
Engine.sharedInstance.getBridge().publishEvent("mobile-browser:urlbar-focus", args: [])
}

func isHistoryUptodate() -> Bool {
return true
}
func searchWithLastQuery() {
if let query = lastQuery {
search(query)
}
}

func loadData(_ query: String) {
guard query != lastQuery else {
return
}
if query == "" && lastQuery == nil {
return
}

search(query)
}

fileprivate func search(_ query: String) {
var parameters: Array<Any> = [query/*.escape()*/]
if let l = LocationManager.sharedInstance.getUserLocation() {
parameters += [true, l.coordinate.latitude, l.coordinate.longitude]
}
//self.javaScriptBridge.publishEvent("search", parameters: parameters)
//TODO: Bridge can return null, so implement a queue, on Engine level.
Engine.sharedInstance.getBridge().publishEvent("search", args: parameters)

lastQuery = query
}

func updatePrivateMode(_ privateMode: Bool) {
if privateMode != self.privateMode {
@@ -185,7 +145,8 @@ class CliqzSearchViewController : UIViewController, KeyboardHelperDelegate, UIAl
"incognito" : self.privateMode,
"backend_country" : SettingsPrefs.shared.getRegionPref(),
"suggestionsEnabled" : QuerySuggestions.isEnabled(),
"subscriptions" : subscriptions] as [String : Any]
"subscriptions" : subscriptions,
"share_location": LocationManager.sharedInstance.isLocationAcessEnabled() ? "yes" : "ask"] as [String : Any]

//javaScriptBridge.publishEvent("notify-preferences", parameters: params)
Engine.sharedInstance.getBridge().publishEvent("mobile-browser:notify-preferences", args: [params])
@@ -257,7 +218,7 @@ extension CliqzSearchViewController {
fileprivate func callPhoneNumber(_ phoneNumber: String) {
let trimmedPhoneNumber = phoneNumber.removeWhitespaces()
if let url = URL(string: "tel://\(trimmedPhoneNumber)") {
UIApplication.shared.openURL(url)
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}

@@ -289,29 +250,34 @@ extension CliqzSearchViewController {
message = NSLocalizedString("To share your location, go to the settings for the CLIQZ app:\n1.Tap Location\n2.Enable 'While Using'", tableName: "Cliqz", comment: "Alert message for turning on location service when clicking share location on local card")
settingsAction = UIAlertAction(title: settingsOptionTitle, style: .default) { (_) -> Void in
if let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) {
UIApplication.shared.openURL(settingsUrl)
UIApplication.shared.open(settingsUrl, options: [:], completionHandler: nil)
}
}
} else {
message = NSLocalizedString("To share your location, go to the settings of your smartphone:\n1.Turn on Location Services\n2.Select the CLIQZ App\n3.Enable 'While Using'", tableName: "Cliqz", comment: "Alert message for turning on location service when clicking share location on local card")
settingsAction = UIAlertAction(title: settingsOptionTitle, style: .default) { (_) -> Void in
if let settingsUrl = URL(string: "App-Prefs:root=Privacy&path=LOCATION") {
UIApplication.shared.openURL(settingsUrl)
UIApplication.shared.open(settingsUrl, options: [:], completionHandler: nil)
}
}
}

let title = NSLocalizedString("Turn on Location Services", tableName: "Cliqz", comment: "Alert title for turning on location service when clicking share location on local card")

let alertController = UIAlertController (title: title, message: message, preferredStyle: .alert)

let notNowOptionTitle = NSLocalizedString("Not Now", tableName: "Cliqz", comment: "Not now option for turning on location service")
let cancelAction = UIAlertAction(title: notNowOptionTitle, style: .default, handler: nil)

alertController.addAction(cancelAction)
alertController.addAction(settingsAction)

present(alertController, animated: true, completion: nil)
DispatchQueue.main.async {
if let delegate = UIApplication.shared.delegate as? AppDelegate {
let alertController = UIAlertController (title: title, message: message, preferredStyle: .alert)

let notNowOptionTitle = NSLocalizedString("Not Now", tableName: "Cliqz", comment: "Not now option for turning on location service")
let cancelAction = UIAlertAction(title: notNowOptionTitle, style: .default, handler: nil)

alertController.addAction(cancelAction)
alertController.addAction(settingsAction)

//self.present(alertController, animated: true, completion: nil)
delegate.presentContollerOnTop(controller: alertController)
}
}

}
}

0 comments on commit 506cd97

Please sign in to comment.