Skip to content

Commit

Permalink
Add outdated detection. (eu-digital-green-certificates#74)
Browse files Browse the repository at this point in the history
* Add outdated detection.

* Bigger gear.
  • Loading branch information
yspreen authored May 16, 2021
1 parent 9b61fe6 commit f716da9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
7 changes: 7 additions & 0 deletions DGCAVerifier/Services/GatewayConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Foundation
import Alamofire
import SwiftDGC
import SwiftyJSON
import UIKit

struct GatewayConnection: ContextConnection {
public static func certUpdate(resume resumeToken: String? = nil, completion: ((String?, String?) -> Void)?) {
Expand Down Expand Up @@ -141,6 +142,12 @@ struct GatewayConnection: ContextConnection {
let json = JSON(parseJSONC: string)
LocalData.sharedInstance.config.merge(other: json)
LocalData.sharedInstance.save()
if LocalData.sharedInstance.versionedConfig["outdated"].bool == true {
(
UIApplication.shared.windows[0].rootViewController as? UINavigationController
)?.popToRootViewController(animated: false)
return
}
completion?()
}
}
Expand Down
14 changes: 7 additions & 7 deletions DGCAVerifier/Storyboards/Base.lproj/CertificateViewer.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Max Mustermann" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="DVW-2y-e4I">
<rect key="frame" x="16" y="32" width="343" height="38.333333333333343"/>
<rect key="frame" x="16" y="32" width="305" height="38.333333333333343"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="32"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
Expand Down Expand Up @@ -132,7 +132,6 @@
<constraints>
<constraint firstAttribute="trailing" secondItem="9hO-yQ-B4J" secondAttribute="trailing" constant="16" id="1gH-1K-TaY"/>
<constraint firstItem="DVW-2y-e4I" firstAttribute="top" secondItem="yEe-AH-rsr" secondAttribute="top" constant="32" id="6Py-fR-Th3"/>
<constraint firstAttribute="trailing" secondItem="DVW-2y-e4I" secondAttribute="trailing" constant="16" id="7qh-Db-iAm"/>
<constraint firstItem="91E-ya-yA8" firstAttribute="centerX" secondItem="yEe-AH-rsr" secondAttribute="centerX" id="E8r-tf-ykp"/>
<constraint firstItem="NIJ-V3-NpL" firstAttribute="top" secondItem="9hO-yQ-B4J" secondAttribute="bottom" constant="16" id="GFZ-yy-x5z"/>
<constraint firstItem="Enm-XG-fIc" firstAttribute="bottom" secondItem="NIJ-V3-NpL" secondAttribute="bottom" id="NWZ-cm-Psu"/>
Expand Down Expand Up @@ -162,12 +161,12 @@
</constraints>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="YKQ-nV-gL0">
<rect key="frame" x="323" y="60" width="36" height="36"/>
<rect key="frame" x="329" y="68" width="30" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="36" id="Zxq-Yo-AZT"/>
<constraint firstAttribute="height" constant="36" id="sPS-Rz-i1M"/>
<constraint firstAttribute="width" secondItem="YKQ-nV-gL0" secondAttribute="height" multiplier="1:1" id="I01-2e-CPw"/>
<constraint firstAttribute="height" constant="30" id="sPS-Rz-i1M"/>
</constraints>
<state key="normal" image="gear_white"/>
<state key="normal" backgroundImage="gear_white"/>
<connections>
<action selector="settingsButton" destination="WCj-Xf-fml" eventType="touchUpInside" id="Ncw-yx-grf"/>
</connections>
Expand All @@ -177,6 +176,7 @@
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="fKu-7E-jAI" firstAttribute="bottom" secondItem="NIJ-V3-NpL" secondAttribute="top" id="36H-da-mo3"/>
<constraint firstItem="YKQ-nV-gL0" firstAttribute="top" secondItem="ghT-Ae-92i" secondAttribute="top" constant="24" id="6de-XA-YN7"/>
<constraint firstAttribute="trailing" secondItem="yEe-AH-rsr" secondAttribute="trailing" id="6hb-Qt-RV8"/>
<constraint firstItem="fKu-7E-jAI" firstAttribute="top" secondItem="Zct-pN-WQt" secondAttribute="top" id="ArD-jJ-uNk"/>
<constraint firstItem="Sd1-4U-jsd" firstAttribute="top" secondItem="Zct-pN-WQt" secondAttribute="top" id="E6p-gk-4o7"/>
Expand All @@ -189,7 +189,7 @@
<constraint firstAttribute="trailing" secondItem="Sd1-4U-jsd" secondAttribute="trailing" priority="100" id="Xl8-Re-0ql"/>
<constraint firstAttribute="trailing" secondItem="YKQ-nV-gL0" secondAttribute="trailing" constant="16" id="d8Y-GS-Ubd"/>
<constraint firstAttribute="bottomMargin" secondItem="yEe-AH-rsr" secondAttribute="bottom" id="xEk-Du-C7N"/>
<constraint firstItem="YKQ-nV-gL0" firstAttribute="top" secondItem="ghT-Ae-92i" secondAttribute="top" constant="16" id="xTI-Xq-JiW"/>
<constraint firstItem="YKQ-nV-gL0" firstAttribute="leading" secondItem="DVW-2y-e4I" secondAttribute="trailing" constant="8" id="zxW-E4-xci"/>
</constraints>
</view>
<connections>
Expand Down
20 changes: 19 additions & 1 deletion DGCAVerifier/ViewControllers/Home.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,20 @@

import Foundation
import UIKit
import SwiftDGC

class HomeVC: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

if !loaded {
return load()
}
return loadComplete()
}

var loaded = false
func load() {
GatewayConnection.timer?.invalidate()
LocalData.initialize {
DispatchQueue.main.async { [weak self] in
Expand All @@ -42,8 +51,17 @@ class HomeVC: UIViewController {
SecureBackground.image = renderer.image { rendererContext in
self.view.layer.render(in: rendererContext.cgContext)
}
self.performSegue(withIdentifier: "scanner", sender: self)
self.loaded = true
self.loadComplete()
}
}
}

func loadComplete() {
if LocalData.sharedInstance.versionedConfig["outdated"].bool == true {
showAlert(title: l10n("info.outdated"), subtitle: l10n("info.outdated.body"))
return
}
performSegue(withIdentifier: "scanner", sender: self)
}
}
8 changes: 5 additions & 3 deletions DGCAVerifier/ViewControllers/Scan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ class ScanVC: SwiftDGC.ScanVC {
let settingsButton = UIButton(frame: .zero)
settingsButton.addTarget(self, action: #selector(openSettings), for: .touchUpInside)
settingsButton.translatesAutoresizingMaskIntoConstraints = false
settingsButton.setImage(UIImage(named: "gear_white"), for: .normal)
settingsButton.setBackgroundImage(UIImage(named: "gear_white"), for: .normal)
view.addSubview(settingsButton)
let guide = view.safeAreaLayoutGuide
NSLayoutConstraint.activate([
settingsButton.topAnchor.constraint(equalTo: guide.topAnchor, constant: 32.0),
settingsButton.trailingAnchor.constraint(equalTo: guide.trailingAnchor, constant: -24.0)
settingsButton.topAnchor.constraint(equalTo: guide.topAnchor, constant: 36.0),
settingsButton.trailingAnchor.constraint(equalTo: guide.trailingAnchor, constant: -24.0),
settingsButton.heightAnchor.constraint(equalToConstant: 30),
settingsButton.widthAnchor.constraint(equalToConstant: 30)
])
}

Expand Down

0 comments on commit f716da9

Please sign in to comment.