Privacy: Auto-delete logs (no functionality yet)

This commit is contained in:
relikd
2020-06-28 14:20:31 +02:00
parent 43de81929f
commit 80afa6aff1
8 changed files with 231 additions and 120 deletions

View File

@@ -6,6 +6,7 @@ class TVCSettings: UITableViewController {
@IBOutlet var vpnToggle: UISwitch!
@IBOutlet var cellDomainsIgnored: UITableViewCell!
@IBOutlet var cellDomainsBlocked: UITableViewCell!
@IBOutlet var cellPrivacyAutoDelete: UITableViewCell!
override func viewDidLoad() {
super.viewDidLoad()
@@ -15,37 +16,13 @@ class TVCSettings: UITableViewController {
reloadDataSource()
}
@objc func reloadDataSource() {
let (blocked, ignored) = DomainFilter.counts()
cellDomainsIgnored.detailTextLabel?.text = "\(ignored) Domains"
cellDomainsBlocked.detailTextLabel?.text = "\(blocked) Domains"
}
@IBAction func toggleVPNProxy(_ sender: UISwitch) {
// MARK: - VPN Proxy Settings
@IBAction private func toggleVPNProxy(_ sender: UISwitch) {
appDelegate.setProxyEnabled(sender.isOn)
}
@IBAction func exportDB(_ sender: Any) {
let sheet = UIActivityViewController(activityItems: [URL.internalDB()], applicationActivities: nil)
self.present(sheet, animated: true)
}
@IBAction func resetTutorialAlerts(_ sender: UIButton) {
Pref.DidShowTutorial.Welcome = false
Pref.DidShowTutorial.Recordings = false
Alert(title: sender.titleLabel?.text,
text: "\nDone.\n\nYou may need to restart the application.").presentIn(self)
}
@IBAction func clearDatabaseResults(_ sender: Any) {
AskAlert(title: "Clear results?", text:
"You are about to delete all results that have been logged in the past. " +
"Your preferences for blocked and ignored domains are preserved.\n" +
"Continue?", buttonText: "Delete", buttonStyle: .destructive) { _ in
TheGreatDestroyer.deleteAllLogs()
}.presentIn(self)
}
@objc func vpnStateChanged(_ notification: Notification) {
changedState(notification.object as! VPNState)
}
@@ -55,6 +32,17 @@ class TVCSettings: UITableViewController {
vpnToggle.onTintColor = (newState == .inbetween ? .systemYellow : nil)
}
// MARK: - Logging Filter
@objc func reloadDataSource() {
let (blocked, ignored) = DomainFilter.counts()
cellDomainsIgnored.detailTextLabel?.text = "\(ignored) Domains"
cellDomainsBlocked.detailTextLabel?.text = "\(blocked) Domains"
let (one, two) = autoDeleteSelection([1, 7, 31])
cellPrivacyAutoDelete.detailTextLabel?.text = autoDeleteString(one, unit: two)
}
override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
let t:String, d: String
switch tableView.cellForRow(at: indexPath)?.reuseIdentifier {
@@ -82,4 +70,74 @@ class TVCSettings: UITableViewController {
break
}
}
// MARK: - Privacy
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let cell = tableView.cellForRow(at: indexPath), cell === cellPrivacyAutoDelete {
let multiplier = [1, 7, 31]
let (one, two) = autoDeleteSelection(multiplier)
let picker = DurationPickerAlert(
title: "Auto-delete logs",
detail: "Logs will be deleted on app launch or periodically as long as the VPN is running.",
options: [(0...30).map{"\($0)"}, ["Days", "Weeks", "Months"]],
widths: [0.4, 0.6])
picker.pickerView.setSelection([min(30, one), two])
picker.present(in: self) {
PrefsShared.AutoDeleteLogsDays = $1[0] * multiplier[$1[1]]
cell.detailTextLabel?.text = autoDeleteString($1[0], unit: $1[1])
// TODO: notify VPN and local delete timer
}
}
}
// MARK: - Reset Settings
@IBAction private func resetTutorialAlerts(_ sender: UIButton) {
Pref.DidShowTutorial.Welcome = false
Pref.DidShowTutorial.Recordings = false
Alert(title: sender.titleLabel?.text,
text: "\nDone.\n\nYou may need to restart the application.").presentIn(self)
}
@IBAction private func clearDatabaseResults() {
AskAlert(title: "Clear results?", text:
"You are about to delete all results that have been logged in the past. " +
"Your preferences for blocked and ignored domains are preserved.\n" +
"Continue?", buttonText: "Delete", buttonStyle: .destructive) { _ in
TheGreatDestroyer.deleteAllLogs()
}.presentIn(self)
}
// MARK: - Advanced
@IBAction private func exportDB() {
let sheet = UIActivityViewController(activityItems: [URL.internalDB()], applicationActivities: nil)
self.present(sheet, animated: true)
}
}
// -------------------------------
// |
// | MARK: - Helper methods
// |
// -------------------------------
private func autoDeleteSelection(_ multiplier: [Int]) -> (Int, Int) {
let current = PrefsShared.AutoDeleteLogsDays
let snd = multiplier.lastIndex { current % $0 == 0 }! // make sure 1 is in list
return (current / multiplier[snd], snd)
}
private func autoDeleteString(_ num: Int, unit: Int) -> String {
switch num {
case 0: return "Never"
case 1: return "1 \(["Day", "Week", "Month"][unit])"
default: return "\(num) \(["Days", "Weeks", "Months"][unit])"
}
}