Skip to content

Commit 13c00ce

Browse files
authored
Feature to add start up at login
Add start at login
2 parents 55715c1 + 5848ab8 commit 13c00ce

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

ClipboardManager/ClipboardManager/Models.swift

+1-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ class AppState: ObservableObject, ClipboardUpdateDelegate {
3737
#else
3838
@Published var isDebugMode = false
3939
#endif
40-
41-
42-
43-
44-
45-
40+
4641
init() {
4742
#if DEBUG
4843
Logger.debug("Running in DEBUG configuration")

ClipboardManager/ClipboardManager/SettingsView.swift

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import SwiftUI
22
import AppKit
3+
import ServiceManagement
34

45
struct SettingsView: View {
56
@AppStorage(UserDefaultsKeys.maxClipsShown) private var maxClipsShown: Int = 10
@@ -10,6 +11,7 @@ struct SettingsView: View {
1011
@AppStorage(UserDefaultsKeys.playSoundOnCopy) private var playSoundOnCopy: Bool = false
1112
@AppStorage(UserDefaultsKeys.selectedSound) private var selectedSound: String = SystemSound.tink.rawValue
1213
@AppStorage(UserDefaultsKeys.debugEnabled) private var debugEnabled: Bool = false
14+
@AppStorage("launchAtLogin") private var launchAtLogin = false
1315

1416
@Environment(\.dismiss) var dismiss
1517
@State private var showFeedback = false
@@ -52,6 +54,7 @@ struct SettingsView: View {
5254
// Play test sound when changed
5355
SoundManager.shared.playCopySound()
5456
}
57+
5558
}
5659
} header: {
5760
Text("Sound")
@@ -95,7 +98,6 @@ struct SettingsView: View {
9598
// Obsidian Integration Settings
9699
Section {
97100
Toggle("Enable Obsidian Integration", isOn: $obsidianEnabled)
98-
99101
if obsidianEnabled {
100102
Button(obsidianVaultPath.isEmpty ? "Select Vault Path" : "Change Vault Path") {
101103
selectObsidianVaultPath()
@@ -138,9 +140,36 @@ struct SettingsView: View {
138140
} header: {
139141
Text("Debug")
140142
}
143+
// Launch at Login Settings
144+
Section {
145+
Toggle("Launch at Login", isOn: $launchAtLogin)
146+
.help("Launch application automatically at login")
147+
.onChange(of: launchAtLogin) { oldValue, newValue in
148+
if newValue {
149+
try? SMAppService.mainApp.register()
150+
} else {
151+
try? SMAppService.mainApp.unregister()
152+
}
153+
154+
withAnimation {
155+
showFeedback = true
156+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
157+
showFeedback = false
158+
}
159+
}
160+
}
161+
} header: {
162+
Text("Startup")
163+
}
141164
}
142165
.formStyle(.grouped)
143166

167+
Spacer()
168+
Text("Made with ♡ by hp77")
169+
.font(.caption)
170+
.foregroundColor(.secondary)
171+
.padding(.bottom)
172+
144173
if showFeedback {
145174
Text("Setting saved")
146175
.font(.caption)

ClipboardManager/ClipboardManager/Views/ClipboardHistoryView.swift

+24-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,22 @@ struct ClipboardHistoryView: View {
1616
@Environment(\.dismiss) private var dismiss
1717
@Binding var selectedIndex: Int
1818

19-
private let pageSize = 20
19+
@AppStorage(UserDefaultsKeys.maxClipsShown) private var maxClipsShown: Int = 10
2020
private let searchManager = SearchManager()
2121

22+
private func formatSize(_ bytes: Int) -> String {
23+
let kb = Double(bytes) / 1024.0
24+
if kb < 1024 {
25+
return String(format: "%.1f KB", kb)
26+
}
27+
let mb = kb / 1024.0
28+
return String(format: "%.1f MB", mb)
29+
}
30+
31+
private var totalSize: Int {
32+
searchState.clips.reduce(0) { $0 + $1.content.count }
33+
}
34+
2235
init(isInPanel: Bool = false, selectedIndex: Binding<Int> = .constant(0)) {
2336
self.isInPanel = isInPanel
2437
self._selectedIndex = selectedIndex
@@ -29,14 +42,14 @@ struct ClipboardHistoryView: View {
2942
isLoadingMore = true
3043

3144
do {
32-
let newClips = try await appState.apiClient.getClips(offset: page * pageSize, limit: pageSize)
45+
let newClips = try await appState.apiClient.getClips(offset: page * maxClipsShown, limit: maxClipsShown)
3346
await MainActor.run {
3447
if page == 0 {
3548
searchState.clips = newClips
3649
} else {
3750
searchState.clips.append(contentsOf: newClips)
3851
}
39-
searchState.hasMoreContent = newClips.count == pageSize
52+
searchState.hasMoreContent = newClips.count == maxClipsShown
4053
searchState.currentPage = page
4154
isLoadingMore = false
4255
}
@@ -96,6 +109,14 @@ struct ClipboardHistoryView: View {
96109
}
97110
}
98111

112+
// Total clips count
113+
if !searchState.clips.isEmpty {
114+
Text("\(searchState.clips.count) clips (\(formatSize(totalSize)))")
115+
.font(.caption)
116+
.foregroundColor(.secondary)
117+
.padding(.horizontal, 8)
118+
}
119+
99120
// Debug status
100121
if appState.isDebugMode && !isInPanel {
101122
StatusView(

0 commit comments

Comments
 (0)