Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Jan 9, 2020
1 parent f9213f5 commit 6cef88c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 29 deletions.
66 changes: 38 additions & 28 deletions Blink/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,36 +120,41 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
}

func sceneDidBecomeActive(_ scene: UIScene) {
guard let window = window else {
return
}

if LocalAuth.shared.lockRequired {
if let lockCtrl = _lockCtrl {
if window?.rootViewController != lockCtrl {
window?.rootViewController = lockCtrl
if window.rootViewController != lockCtrl {
window.rootViewController = lockCtrl
}
} else {
let ctrl = UIHostingController(rootView: LockView(scene: scene))
window?.rootViewController = ctrl
_lockCtrl = ctrl
LocalAuth.shared.unlock(scene: scene)

return
}

_lockCtrl = UIHostingController(rootView: LockView(scene: scene))
window.rootViewController = _lockCtrl
LocalAuth.shared.unlock(scene: scene)

return
} else {
_lockCtrl = nil
}

_lockCtrl = nil
LocalAuth.shared.stopTrackTime()

if window?.rootViewController != _spCtrl {
window?.rootViewController = _spCtrl
let spCtrl = _spCtrl

if window.rootViewController != spCtrl {
window.rootViewController = spCtrl
}

guard let term = _spCtrl.currentTerm()
else {
guard let term = spCtrl.currentTerm() else {
return
}


term.resumeIfNeeded()
term.view?.setNeedsLayout()
let spCtrl = _spCtrl

let input = SmarterTermInput.shared
if let key = input.stuckKey() {
Expand All @@ -161,36 +166,41 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
ctrl.modalPresentationStyle = .formSheet
spCtrl.stuckKeyCode = key
spCtrl.present(ctrl, animated: false)
return;
} else {
spCtrl.stuckKeyCode = nil

return
}

spCtrl.stuckKeyCode = nil

guard spCtrl.presentedViewController == nil else {
return
}

if
term.termDevice.view?.isFocused() == false,
if term.termDevice.view?.isFocused() == false,
!input.isRealFirstResponder,
input.window == self.window {
input.window === window {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) {
if !SmarterTermInput.shared.isRealFirstResponder,
scene.activationState == .foregroundActive {
if scene.activationState == .foregroundActive,
!input.isRealFirstResponder {
spCtrl.focusOnShellAction()
}
}
} else if input.window == self.window {

return
}

if input.window === window {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) {
if term.termDevice.view?.isFocused() == false,
scene.activationState == .foregroundActive {
if scene.activationState == .foregroundActive,
term.termDevice.view?.isFocused() == false {
spCtrl.focusOnShellAction()
}
}
} else {
SmarterTermInput.shared.reportStateReset()

return
}

SmarterTermInput.shared.reportStateReset()
}

func stateRestorationActivity(for scene: UIScene) -> NSUserActivity? {
Expand Down
6 changes: 5 additions & 1 deletion Settings/Security/LocalAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,16 @@ import LocalAuthentication

autheticate(callback: { [weak self] (success) in
if success {
self?._didEnterBackgroundAt = nil
self?.stopTrackTime()
NotificationCenter.default.post(name: LocalAuth.unlockNotification, object: nil)
}
}, reason: "to unlock blink.")
}

func stopTrackTime() {
_didEnterBackgroundAt = nil
}

@objc func autheticate(callback: @escaping (_ success: Bool) -> Void, reason: String = "to access sensitive data.") {
if _inProgress {
callback(false)
Expand Down

0 comments on commit 6cef88c

Please sign in to comment.