Skip to content

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
rrroyal committed Jun 21, 2022
1 parent 4c4e9fc commit 408336d
Show file tree
Hide file tree
Showing 35 changed files with 269 additions and 271 deletions.
50 changes: 24 additions & 26 deletions Harbour.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Harbour.xcodeproj/xcshareddata/xcschemes/Harbour.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1400"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1320"
LastUpgradeVersion = "1400"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1320"
LastUpgradeVersion = "1400"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
Expand Down
3 changes: 3 additions & 0 deletions Harbour/Controllers/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation
import UIKit
import BackgroundTasks
import PortainerKit

final class AppDelegate: UIResponder, UIApplicationDelegate {

Expand All @@ -18,6 +19,8 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
]
UserDefaults.standard.register(defaults: defaults)
#endif

Preferences.shared.enableDebugLogging = false

BGTaskScheduler.shared.register(forTaskWithIdentifier: BackgroundTasks.BackgroundTask.refresh, using: nil) { task in
BackgroundTasks.scheduleBackgroundRefreshTask()
Expand Down
2 changes: 1 addition & 1 deletion Harbour/Controllers/SceneState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ final class SceneState: ObservableObject {
UIDevice.generateHaptic(.error)
logger.error("\(String(describing: error), privacy: .public) [\(_fileID, privacy: .public):\(_line, privacy: .public) \(_function, privacy: .public)]")

let errorDescription = error.readableDescription
let errorDescription = error.localizedDescription
let recoverySuggestion = (error as? LocalizedError)?.recoverySuggestion

if displayIndicator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ extension Portainer {
isConnected = false
update(error)

let indicator: Indicators.Indicator = .init(id: "ContainerWebSocketDisconnected-\(container.id)", icon: "bolt.fill", headline: Localization.Indicator.WebSocketDisconnected.title, subheadline: error.readableDescription, dismissType: .after(5))
let indicator: Indicators.Indicator = .init(id: "ContainerWebSocketDisconnected-\(container.id)", icon: "bolt.fill", headline: Localization.Indicator.WebSocketDisconnected.title, subheadline: error.localizedDescription, dismissType: .after(5))
errorHandler?(error, indicator, #fileID, #line, #function)
}
}
Expand All @@ -100,7 +100,7 @@ extension Portainer {
string = Localization.Portainer.AttachedContainer.finished
case .failure(let error):
attributes.foregroundColor = .red
string = error.readableDescription
string = error.localizedDescription
}

let attributedString = AttributedString(string, attributes: attributes)
Expand All @@ -111,7 +111,7 @@ extension Portainer {
var attributes = AttributeContainer()
attributes.foregroundColor = .red

let attributedString = AttributedString(error.readableDescription, attributes: attributes)
let attributedString = AttributedString(error.localizedDescription, attributes: attributes)
self.attributedString.append(attributedString)
}
}
Expand All @@ -121,7 +121,7 @@ private extension Portainer.AttachedContainer {
enum AttachedContainerError: LocalizedError {
case unhandledMessage(String)

var errorDescription: String {
var errorDescription: String? {
switch self {
case .unhandledMessage(let message):
return Localization.Portainer.AttachedContainer.unhandledMessage(message)
Expand Down
28 changes: 0 additions & 28 deletions Harbour/Views/Components/ContainerCellBackground.swift

This file was deleted.

3 changes: 2 additions & 1 deletion Harbour/Views/Components/ToolbarTitle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ struct ToolbarTitle: ToolbarContent {
VStack(spacing: 1) {
Text(title)
.font(.headline)
.fixedSize()
.transition(.move(edge: .bottom))

if let subtitle = subtitle {
Text(subtitle)
.font(.footnote)
.foregroundStyle(.tertiary)
.fixedSize()
.transition(.move(edge: .bottom).combined(with: .opacity))
}
}
Expand All @@ -30,4 +32,3 @@ struct ToolbarTitle: ToolbarContent {
}
}
}

102 changes: 53 additions & 49 deletions Harbour/Views/Container Detail/ContainerDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
// Created by royal on 11/06/2021.
//

// TODO: Rework this view

import PortainerKit
import SwiftUI

#warning("TODO: Rework view")
struct ContainerDetailView: View {
@EnvironmentObject var sceneState: SceneState
@EnvironmentObject var portainer: Portainer
Expand Down Expand Up @@ -40,54 +41,23 @@ struct ContainerDetailView: View {
.buttonStyle(.decreasesOnPress)
}

@ViewBuilder
var generalSection: some View {
if let details = container.details {
LabeledSection(label: "ID", content: details.id, monospace: true, hideIfEmpty: false)
LabeledSection(label: "Created", content: details.created.formatted(), hideIfEmpty: false)
LabeledSection(label: "PID", content: "\(details.state.pid)", monospace: true, hideIfEmpty: false)
LabeledSection(label: "Status", content: container.status ?? details.state.status.rawValue, monospace: true, hideIfEmpty: false)
LabeledSection(label: "Error", content: details.state.error, monospace: true, hideIfEmpty: false)
LabeledSection(label: "Started at", content: details.state.startedAt?.formatted(), hideIfEmpty: false)
LabeledSection(label: "Finished at", content: details.state.finishedAt?.formatted(), hideIfEmpty: false)
} else if loading {
ProgressView()
.padding()
.frame(maxWidth: .infinity, alignment: .center)
}
}

var logsSection: some View {
CustomSection(label: "Logs (last \(lastLogsTailCount) lines)") {
if let logs = lastLogsSnippet {
Text(logs.isReallyEmpty ? "empty" : logs)
.font(.system(.footnote, design: .monospaced))
.foregroundStyle(logs.isReallyEmpty ? .secondary : .primary)
.lineLimit(nil)
.contentShape(Rectangle())
.frame(maxWidth: .infinity, alignment: .topLeading)
.textSelection(.enabled)
} else if loading {
ProgressView()
.padding()
.frame(maxWidth: .infinity, alignment: .center)
}
}
.frame(maxWidth: .infinity)
.id("LastLogsSnippetLabel-\(lastLogsSnippet?.hashValue ?? -1)")
}

var body: some View {
ScrollView {
LazyVStack(spacing: 20) {
buttonsSection
generalSection
logsSection

if let containerDetails = container.details {
GeneralSection(details: containerDetails)
StateSection(state: containerDetails.state)
GraphDriverSection(graphDriver: containerDetails.graphDriver)

if let details = container.details {
GeneralSection(container: container, details: details)
}

if let lastLogsSnippet = lastLogsSnippet {
LogsSection(logs: lastLogsSnippet, tailCount: lastLogsTailCount)
}

if let details = container.details {
DetailsSection(details: details)
StateSection(state: details.state)
GraphDriverSection(graphDriver: details.graphDriver)
}
}
.padding()
Expand Down Expand Up @@ -120,7 +90,9 @@ struct ContainerDetailView: View {
}
}
}
.animation(.easeInOut, value: lastLogsSnippet)
.animation(.easeInOut, value: loading)
.animation(.easeInOut, value: container.details != nil)
.animation(.easeInOut, value: lastLogsSnippet != nil)
.refreshable { await refresh() }
.task { await refresh() }
.userActivity(UserActivity.ViewContainer.activityType, isActive: sceneState.activeContainer == container) { activity in
Expand All @@ -147,6 +119,7 @@ struct ContainerDetailView: View {

private func refresh() async {
loading = true
defer { loading = false }

do {
async let logs = portainer.getLogs(from: container.id, tail: lastLogsTailCount, displayTimestamps: true)
Expand All @@ -162,8 +135,6 @@ struct ContainerDetailView: View {
} catch {
sceneState.handle(error)
}

loading = false
}
}

Expand All @@ -173,12 +144,45 @@ extension ContainerDetailView: Identifiable, Equatable {
}

static func == (lhs: ContainerDetailView, rhs: ContainerDetailView) -> Bool {
lhs.container == rhs.container
lhs.container.id == rhs.container.id
}
}

fileprivate extension ContainerDetailView {
struct GeneralSection: View {
let container: PortainerKit.Container
let details: PortainerKit.ContainerDetails

var body: some View {
LabeledSection(label: "ID", content: details.id, monospace: true, hideIfEmpty: false)
LabeledSection(label: "Created", content: details.created.formatted(), hideIfEmpty: false)
LabeledSection(label: "PID", content: "\(details.state.pid)", monospace: true, hideIfEmpty: false)
LabeledSection(label: "Status", content: container.status ?? details.state.status.rawValue, monospace: true, hideIfEmpty: false)
LabeledSection(label: "Error", content: details.state.error, monospace: true, hideIfEmpty: false)
LabeledSection(label: "Started at", content: details.state.startedAt?.formatted(), hideIfEmpty: false)
LabeledSection(label: "Finished at", content: details.state.finishedAt?.formatted(), hideIfEmpty: false)
}
}

struct LogsSection: View {
let logs: String
let tailCount: Int

var body: some View {
CustomSection(label: "Logs (last \(tailCount) lines)") {
Text(logs.isReallyEmpty ? "empty" : logs)
.font(.system(.footnote, design: .monospaced))
.foregroundStyle(logs.isReallyEmpty ? .secondary : .primary)
.lineLimit(nil)
.contentShape(Rectangle())
.frame(maxWidth: .infinity, alignment: .topLeading)
.textSelection(.enabled)
}
.frame(maxWidth: .infinity)
}
}

struct DetailsSection: View {
let details: PortainerKit.ContainerDetails

var body: some View {
Expand Down
4 changes: 2 additions & 2 deletions Harbour/Views/Containers List/ContainersView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ struct ContainersView: View {
var body: some View {
if useContainerGridView {
ContainersGridView(containers: containers)
// .equatable()
.equatable()
} else {
ContainersListView(containers: containers)
// .equatable()
.equatable()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension ContainersGridView {
}
.padding(.medium)
.aspectRatio(1, contentMode: .fill)
.background(ContainerCellBackground(state: container.state))
.background(Color(uiColor: .systemBackground))
.containerShape(Self.backgroundShape)
.animation(.easeInOut, value: container.status)
.animation(.easeInOut, value: container.displayName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extension ContainersListView {
.animation(.easeInOut, value: container.state.color)
}
.padding()
.background(ContainerCellBackground(state: container.state))
.background(Color(uiColor: .systemBackground))
.containerShape(Self.backgroundShape)
.animation(.easeInOut, value: container.state)
.animation(.easeInOut, value: container.status)
Expand Down
6 changes: 6 additions & 0 deletions Harbour/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ struct ContentView: View {
}
.disabled(!portainer.isSetup)
}

var background: some View {
Color(uiColor: .systemGroupedBackground)
}

@ViewBuilder
var content: some View {
Expand All @@ -86,6 +90,8 @@ struct ContentView: View {
var body: some View {
NavigationView {
content
.maxSize()
.background(background.ignoresSafeArea())
.transition(.opacity)
.navigationTitle("Harbour")
.navigationBarTitleDisplayMode(.inline)
Expand Down
9 changes: 7 additions & 2 deletions Harbour/Views/DebugView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import OSLog
import Indicators
import BackgroundTasks
import WidgetKit
import PortainerKit

struct DebugView: View {
@EnvironmentObject var sceneState: SceneState
Expand All @@ -33,6 +34,10 @@ struct DebugView: View {
Preferences.shared.selectedEndpointID = nil
Portainer.shared.cleanup()
}

Button("\(Preferences.shared.enableDebugLogging ? "Disable" : "Enable") debug logging") {
Preferences.shared.enableDebugLogging.toggle()
}
}

#if DEBUG
Expand Down Expand Up @@ -65,7 +70,7 @@ struct DebugView: View {

Button("Reset all") {
UIDevice.generateHaptic(.heavy)
Preferences.Key.allCases.forEach { Preferences.ud.removeObject(forKey: $0.rawValue) }
Preferences.Keys.allCases.forEach { Preferences.ud.removeObject(forKey: $0.rawValue) }
exit(0)
}
.foregroundStyle(.red)
Expand Down Expand Up @@ -161,7 +166,7 @@ extension DebugView {
.compactMap { $0 as? OSLogEntryLog }
.map { LogEntry(message: $0.composedMessage, level: $0.level, date: $0.date, category: $0.category) }
} catch {
logs = [LogEntry(message: error.readableDescription, level: nil, date: nil, category: nil)]
logs = [LogEntry(message: error.localizedDescription, level: nil, date: nil, category: nil)]
}
}
}
Expand Down

0 comments on commit 408336d

Please sign in to comment.