mirror of https://github.com/oxen-io/session-ios
Prep for new share extension
parent
65d96d1c2b
commit
8751a87641
@ -1,28 +1,27 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="j1y-V4-xli">
|
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="j1y-V4-xli">
|
||||||
<device id="retina4_7" orientation="portrait">
|
<device id="retina4_7" orientation="portrait" appearance="light"/>
|
||||||
<adaptation id="fullscreen"/>
|
|
||||||
</device>
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<deployment identifier="iOS"/>
|
<deployment identifier="iOS"/>
|
||||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
|
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
|
||||||
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
||||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<scenes>
|
<scenes>
|
||||||
<!--Share View Controller-->
|
<!--ShareVC-->
|
||||||
<scene sceneID="ceB-am-kn3">
|
<scene sceneID="ceB-am-kn3">
|
||||||
<objects>
|
<objects>
|
||||||
<viewController id="j1y-V4-xli" customClass="ShareViewController" customModule="SignalShareExtension" customModuleProvider="target" sceneMemberID="viewController">
|
<viewController id="j1y-V4-xli" customClass="ShareVC" customModule="SessionShareExtension" customModuleProvider="target" sceneMemberID="viewController">
|
||||||
<view key="view" opaque="NO" contentMode="scaleToFill" id="wbc-yd-nQP">
|
<view key="view" opaque="NO" contentMode="scaleToFill" id="wbc-yd-nQP">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
|
|
||||||
<viewLayoutGuide key="safeArea" id="1Xd-am-t49"/>
|
<viewLayoutGuide key="safeArea" id="1Xd-am-t49"/>
|
||||||
|
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
|
||||||
</view>
|
</view>
|
||||||
</viewController>
|
</viewController>
|
||||||
<placeholder placeholderIdentifier="IBFirstResponder" id="CEy-Cv-SGf" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
<placeholder placeholderIdentifier="IBFirstResponder" id="CEy-Cv-SGf" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||||
</objects>
|
</objects>
|
||||||
|
<point key="canvasLocation" x="126" y="133"/>
|
||||||
</scene>
|
</scene>
|
||||||
</scenes>
|
</scenes>
|
||||||
</document>
|
</document>
|
||||||
|
@ -0,0 +1,172 @@
|
|||||||
|
import SessionUIKit
|
||||||
|
|
||||||
|
final class ShareVC : UIViewController, AppModeManagerDelegate {
|
||||||
|
private var areVersionMigrationsComplete = false
|
||||||
|
|
||||||
|
// MARK: Lifecycle
|
||||||
|
override func loadView() {
|
||||||
|
super.loadView()
|
||||||
|
|
||||||
|
// This should be the first thing we do.
|
||||||
|
let appContext = ShareAppExtensionContext(rootViewController: self)
|
||||||
|
SetCurrentAppContext(appContext)
|
||||||
|
|
||||||
|
AppModeManager.configure(delegate: self)
|
||||||
|
|
||||||
|
DebugLogger.shared().enableTTYLogging()
|
||||||
|
if _isDebugAssertConfiguration() {
|
||||||
|
DebugLogger.shared().enableFileLogging()
|
||||||
|
} else if OWSPreferences.isLoggingEnabled() {
|
||||||
|
DebugLogger.shared().enableFileLogging()
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.info("")
|
||||||
|
|
||||||
|
_ = AppVersion.sharedInstance()
|
||||||
|
|
||||||
|
Cryptography.seedRandom()
|
||||||
|
|
||||||
|
// We don't need to use DeviceSleepManager in the SAE.
|
||||||
|
|
||||||
|
// We don't need to use applySignalAppearence in the SAE.
|
||||||
|
|
||||||
|
if CurrentAppContext().isRunningTests {
|
||||||
|
// TODO: Do we need to implement isRunningTests in the SAE context?
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
AppSetup.setupEnvironment(appSpecificSingletonBlock: {
|
||||||
|
SSKEnvironment.shared.notificationsManager = NoopNotificationsManager()
|
||||||
|
}, migrationCompletion: { [weak self] in
|
||||||
|
AssertIsOnMainThread()
|
||||||
|
|
||||||
|
guard let strongSelf = self else { return }
|
||||||
|
|
||||||
|
// performUpdateCheck must be invoked after Environment has been initialized because
|
||||||
|
// upgrade process may depend on Environment.
|
||||||
|
strongSelf.versionMigrationsDidComplete()
|
||||||
|
})
|
||||||
|
|
||||||
|
// We don't need to use "screen protection" in the SAE.
|
||||||
|
|
||||||
|
NotificationCenter.default.addObserver(self,
|
||||||
|
selector: #selector(storageIsReady),
|
||||||
|
name: .StorageIsReady,
|
||||||
|
object: nil)
|
||||||
|
NotificationCenter.default.addObserver(self,
|
||||||
|
selector: #selector(applicationDidEnterBackground),
|
||||||
|
name: .OWSApplicationDidEnterBackground,
|
||||||
|
object: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc
|
||||||
|
func versionMigrationsDidComplete() {
|
||||||
|
AssertIsOnMainThread()
|
||||||
|
|
||||||
|
Logger.debug("")
|
||||||
|
|
||||||
|
areVersionMigrationsComplete = true
|
||||||
|
|
||||||
|
checkIsAppReady()
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc
|
||||||
|
func storageIsReady() {
|
||||||
|
AssertIsOnMainThread()
|
||||||
|
|
||||||
|
Logger.debug("")
|
||||||
|
|
||||||
|
checkIsAppReady()
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc
|
||||||
|
func checkIsAppReady() {
|
||||||
|
AssertIsOnMainThread()
|
||||||
|
|
||||||
|
// App isn't ready until storage is ready AND all version migrations are complete.
|
||||||
|
guard areVersionMigrationsComplete else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
guard OWSStorage.isStorageReady() else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
guard !AppReadiness.isAppReady() else {
|
||||||
|
// Only mark the app as ready once.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
SignalUtilitiesKit.Configuration.performMainSetup()
|
||||||
|
|
||||||
|
Logger.debug("")
|
||||||
|
|
||||||
|
// TODO: Once "app ready" logic is moved into AppSetup, move this line there.
|
||||||
|
OWSProfileManager.shared().ensureLocalProfileCached()
|
||||||
|
|
||||||
|
// Note that this does much more than set a flag;
|
||||||
|
// it will also run all deferred blocks.
|
||||||
|
AppReadiness.setAppIsReady()
|
||||||
|
|
||||||
|
// We don't need to use messageFetcherJob in the SAE.
|
||||||
|
|
||||||
|
// We don't need to use SyncPushTokensJob in the SAE.
|
||||||
|
|
||||||
|
// We don't need to use DeviceSleepManager in the SAE.
|
||||||
|
|
||||||
|
AppVersion.sharedInstance().saeLaunchDidComplete()
|
||||||
|
|
||||||
|
setUpViewHierarchy()
|
||||||
|
|
||||||
|
// We don't need to use OWSMessageReceiver in the SAE.
|
||||||
|
// We don't need to use OWSBatchMessageProcessor in the SAE.
|
||||||
|
|
||||||
|
OWSProfileManager.shared().ensureLocalProfileCached()
|
||||||
|
|
||||||
|
// We don't need to use OWSOrphanDataCleaner in the SAE.
|
||||||
|
|
||||||
|
// We don't need to fetch the local profile in the SAE
|
||||||
|
|
||||||
|
OWSReadReceiptManager.shared().prepareCachedValues()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setUpViewHierarchy() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc
|
||||||
|
public func applicationDidEnterBackground() {
|
||||||
|
AssertIsOnMainThread()
|
||||||
|
|
||||||
|
Logger.info("")
|
||||||
|
|
||||||
|
if OWSScreenLock.shared.isScreenLockEnabled() {
|
||||||
|
|
||||||
|
self.dismiss(animated: false) { [weak self] in
|
||||||
|
AssertIsOnMainThread()
|
||||||
|
guard let strongSelf = self else { return }
|
||||||
|
strongSelf.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
NotificationCenter.default.removeObserver(self)
|
||||||
|
|
||||||
|
// Share extensions reside in a process that may be reused between usages.
|
||||||
|
// That isn't safe; the codebase is full of statics (e.g. singletons) which
|
||||||
|
// we can't easily clean up.
|
||||||
|
ExitShareExtension()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: App Mode
|
||||||
|
|
||||||
|
public func getCurrentAppMode() -> AppMode {
|
||||||
|
guard let window = self.view.window else { return .light }
|
||||||
|
let userInterfaceStyle = window.traitCollection.userInterfaceStyle
|
||||||
|
let isLightMode = (userInterfaceStyle == .light || userInterfaceStyle == .unspecified)
|
||||||
|
return isLightMode ? .light : .dark
|
||||||
|
}
|
||||||
|
|
||||||
|
public func setCurrentAppMode(to appMode: AppMode) {
|
||||||
|
return // Not applicable to share extensions
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue