From ff4218981fb3eb114da58e4e8c145f3710334c83 Mon Sep 17 00:00:00 2001 From: relikd Date: Mon, 31 Aug 2020 12:18:36 +0200 Subject: [PATCH] Discard recording if time criteria not met --- main/Common Classes/PrefsShared.swift | 17 +++- main/DB/DBExtensions.swift | 4 +- main/Extensions/Time.swift | 16 ++-- main/GUI/Base.lproj/Recordings.storyboard | 5 +- main/GlassVPN.swift | 4 +- main/GlassVPNHook.swift | 5 +- main/Recordings/TVCPreviousRecords.swift | 2 +- main/Recordings/VCEditRecording.swift | 2 +- main/Recordings/VCRecordings.swift | 107 ++++++++++++++-------- main/Recordings/VCShareRecording.swift | 2 +- 10 files changed, 106 insertions(+), 58 deletions(-) diff --git a/main/Common Classes/PrefsShared.swift b/main/Common Classes/PrefsShared.swift index e10c963..a86018c 100644 --- a/main/Common Classes/PrefsShared.swift +++ b/main/Common Classes/PrefsShared.swift @@ -23,10 +23,19 @@ enum PrefsShared { get { Int("AutoDeleteLogsDays") } set { Int("AutoDeleteLogsDays", newValue) } } - - static var CurrentlyRecording: Bool { - get { Bool("CurrentlyRecording") } - set { Bool("CurrentlyRecording", newValue) } +} + + +// MARK: - Recording State + +enum CurrentRecordingState : Int { + case Off = 0, App = 1, Background = 2 +} + +extension PrefsShared { + static var CurrentlyRecording: CurrentRecordingState { + get { CurrentRecordingState(rawValue: Int("CurrentlyRecording")) ?? .Off } + set { Int("CurrentlyRecording", newValue.rawValue) } } } diff --git a/main/DB/DBExtensions.swift b/main/DB/DBExtensions.swift index 3731ebb..dcabcdd 100644 --- a/main/DB/DBExtensions.swift +++ b/main/DB/DBExtensions.swift @@ -36,8 +36,8 @@ extension Recording { var fallbackTitle: String { get { isLongTerm ? "Background Recording" : "Unnamed Recording #\(id)" } } - var duration: Timestamp? { get { stop == nil ? nil : stop! - start } } - var isLongTerm: Bool { (duration ?? 0) > Timestamp.hours(1) } + var duration: Timestamp { get { stop ?? .now() - start } } + var isLongTerm: Bool { duration > Timestamp.hours(1) } var isShared: Bool { uploadkey?.count ?? 0 > 0} } diff --git a/main/Extensions/Time.swift b/main/Extensions/Time.swift index feb3cd1..80ec882 100644 --- a/main/Extensions/Time.swift +++ b/main/Extensions/Time.swift @@ -86,17 +86,21 @@ struct TimeFormat { } /// Duration string with format `mm:ss` or `mm:ss.SSS` - static func from(_ duration: TimeInterval, millis: Bool = false) -> String { + static func from(_ duration: TimeInterval, millis: Bool = false, hours: Bool = false) -> String { let t = Int(duration) + let min = t / 60 + let sec = t % 60 if millis { let mil = Int(duration * 1000) % 1000 - return String(format: "%02d:%02d.%03d", t / 60, t % 60, mil) + return String(format: "%02d:%02d.%03d", min, sec, mil) + } else if hours { + return String(format: "%02d:%02d:%02d", min / 60, min % 60, sec) } - return String(format: "%02d:%02d", t / 60, t % 60) + return String(format: "%02d:%02d", min, sec) } - /// Duration string with format `mm:ss` or `mm:ss.SSS` since reference date - static func since(_ date: Date, millis: Bool = false) -> String { - from(Date().timeIntervalSince(date), millis: millis) + /// Duration string with format `mm:ss` or `mm:ss.SSS` or `HH:mm:ss` since reference date + static func since(_ date: Date, millis: Bool = false, hours: Bool = false) -> String { + from(Date().timeIntervalSince(date), millis: millis, hours: hours) } } diff --git a/main/GUI/Base.lproj/Recordings.storyboard b/main/GUI/Base.lproj/Recordings.storyboard index 82946a5..f7f7935 100644 --- a/main/GUI/Base.lproj/Recordings.storyboard +++ b/main/GUI/Base.lproj/Recordings.storyboard @@ -72,7 +72,7 @@