mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-06 07:48:38 +09:00
Dactyloidae iOS initial commit
This commit is contained in:
parent
daa6179d22
commit
7154a0497e
2123 changed files with 197052 additions and 0 deletions
71
mobile/ios/Client/Helpers/UserActivityHandler.swift
Normal file
71
mobile/ios/Client/Helpers/UserActivityHandler.swift
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import Foundation
|
||||
import Shared
|
||||
import Storage
|
||||
import CoreSpotlight
|
||||
import MobileCoreServices
|
||||
import WebKit
|
||||
|
||||
private let browsingActivityType: String = "org.mozilla.ios.firefox.browsing"
|
||||
|
||||
private let searchableIndex = CSSearchableIndex(name: "firefox")
|
||||
|
||||
class UserActivityHandler {
|
||||
private var tabObservers: TabObservers!
|
||||
|
||||
init() {
|
||||
self.tabObservers = registerFor(
|
||||
.didLoseFocus,
|
||||
.didGainFocus,
|
||||
.didChangeURL,
|
||||
// .didLoadMetadata // TODO: Bug 1390294
|
||||
// .didLoadFavicon, // TODO: Bug 1390294
|
||||
.didClose,
|
||||
queue: .main)
|
||||
}
|
||||
|
||||
deinit {
|
||||
unregister(tabObservers)
|
||||
}
|
||||
|
||||
class func clearSearchIndex(completionHandler: ((Error?) -> Void)? = nil) {
|
||||
searchableIndex.deleteAllSearchableItems(completionHandler: completionHandler)
|
||||
}
|
||||
}
|
||||
|
||||
extension UserActivityHandler: TabEventHandler {
|
||||
func tabDidGainFocus(_ tab: Tab) {
|
||||
tab.userActivity?.becomeCurrent()
|
||||
}
|
||||
|
||||
func tabDidLoseFocus(_ tab: Tab) {
|
||||
tab.userActivity?.resignCurrent()
|
||||
}
|
||||
|
||||
func tab(_ tab: Tab, didChangeURL url: URL) {
|
||||
guard url.isWebPage(includeDataURIs: false), !url.isLocal else {
|
||||
tab.userActivity?.resignCurrent()
|
||||
tab.userActivity = nil
|
||||
return
|
||||
}
|
||||
|
||||
tab.userActivity?.invalidate()
|
||||
|
||||
let userActivity = NSUserActivity(activityType: browsingActivityType)
|
||||
userActivity.webpageURL = url
|
||||
userActivity.becomeCurrent()
|
||||
|
||||
tab.userActivity = userActivity
|
||||
}
|
||||
|
||||
func tabDidClose(_ tab: Tab) {
|
||||
guard let userActivity = tab.userActivity else {
|
||||
return
|
||||
}
|
||||
tab.userActivity = nil
|
||||
userActivity.invalidate()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue