mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Working with resizing
This commit is contained in:
parent
8c99122684
commit
0cc6f369a7
3 changed files with 118 additions and 17 deletions
|
|
@ -85,6 +85,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
var closeNotchWorkItem: DispatchWorkItem?
|
var closeNotchWorkItem: DispatchWorkItem?
|
||||||
private var previousScreens: [NSScreen]?
|
private var previousScreens: [NSScreen]?
|
||||||
private var onboardingWindowController: NSWindowController?
|
private var onboardingWindowController: NSWindowController?
|
||||||
|
private var cancellables = Set<AnyCancellable>()
|
||||||
|
|
||||||
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
||||||
return false
|
return false
|
||||||
|
|
@ -162,9 +163,101 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func updateWindowSizeIfNeeded() {
|
||||||
|
// Calculate required size based on current state
|
||||||
|
let requiredSize = calculateRequiredNotchSize()
|
||||||
|
|
||||||
|
// Update all windows if size has changed
|
||||||
|
for (screen, window) in windows {
|
||||||
|
if window.frame.size != requiredSize {
|
||||||
|
let screenFrame = screen.frame
|
||||||
|
let newFrame = NSRect(
|
||||||
|
x: screenFrame.origin.x + (screenFrame.width / 2) - requiredSize.width / 2,
|
||||||
|
y: screenFrame.origin.y + screenFrame.height - requiredSize.height,
|
||||||
|
width: requiredSize.width,
|
||||||
|
height: requiredSize.height
|
||||||
|
)
|
||||||
|
|
||||||
|
// Animate the frame change for smooth transition
|
||||||
|
NSAnimationContext.runAnimationGroup { context in
|
||||||
|
context.duration = 0.3
|
||||||
|
context.allowsImplicitAnimation = true
|
||||||
|
window.setFrame(newFrame, display: true, animate: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func calculateRequiredNotchSize() -> CGSize {
|
||||||
|
// Only apply dynamic sizing when on stats tab and stats are enabled
|
||||||
|
guard coordinator.currentView == .stats && Defaults[.enableStatsFeature] else {
|
||||||
|
return openNotchSize
|
||||||
|
}
|
||||||
|
|
||||||
|
let enabledGraphsCount = [
|
||||||
|
Defaults[.showCpuGraph],
|
||||||
|
Defaults[.showMemoryGraph],
|
||||||
|
Defaults[.showGpuGraph],
|
||||||
|
Defaults[.showNetworkGraph],
|
||||||
|
Defaults[.showDiskGraph]
|
||||||
|
].filter { $0 }.count
|
||||||
|
|
||||||
|
// If 4+ graphs are enabled, increase width
|
||||||
|
if enabledGraphsCount >= 4 {
|
||||||
|
let extraWidth: CGFloat = CGFloat(enabledGraphsCount - 3) * 120
|
||||||
|
return CGSize(width: openNotchSize.width + extraWidth, height: openNotchSize.height)
|
||||||
|
}
|
||||||
|
|
||||||
|
return openNotchSize
|
||||||
|
}
|
||||||
|
|
||||||
func applicationDidFinishLaunching(_ notification: Notification) {
|
func applicationDidFinishLaunching(_ notification: Notification) {
|
||||||
|
|
||||||
coordinator.setupWorkersNotificationObservers()
|
coordinator.setupWorkersNotificationObservers()
|
||||||
|
|
||||||
|
// Observe tab changes to update window size dynamically
|
||||||
|
coordinator.objectWillChange.sink { [weak self] in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self?.updateWindowSizeIfNeeded()
|
||||||
|
}
|
||||||
|
}.store(in: &cancellables)
|
||||||
|
|
||||||
|
// Observe stats settings changes
|
||||||
|
Defaults.publisher(.enableStatsFeature, options: []).sink { [weak self] _ in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self?.updateWindowSizeIfNeeded()
|
||||||
|
}
|
||||||
|
}.store(in: &cancellables)
|
||||||
|
|
||||||
|
Defaults.publisher(.showCpuGraph, options: []).sink { [weak self] _ in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self?.updateWindowSizeIfNeeded()
|
||||||
|
}
|
||||||
|
}.store(in: &cancellables)
|
||||||
|
|
||||||
|
Defaults.publisher(.showMemoryGraph, options: []).sink { [weak self] _ in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self?.updateWindowSizeIfNeeded()
|
||||||
|
}
|
||||||
|
}.store(in: &cancellables)
|
||||||
|
|
||||||
|
Defaults.publisher(.showGpuGraph, options: []).sink { [weak self] _ in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self?.updateWindowSizeIfNeeded()
|
||||||
|
}
|
||||||
|
}.store(in: &cancellables)
|
||||||
|
|
||||||
|
Defaults.publisher(.showNetworkGraph, options: []).sink { [weak self] _ in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self?.updateWindowSizeIfNeeded()
|
||||||
|
}
|
||||||
|
}.store(in: &cancellables)
|
||||||
|
|
||||||
|
Defaults.publisher(.showDiskGraph, options: []).sink { [weak self] _ in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self?.updateWindowSizeIfNeeded()
|
||||||
|
}
|
||||||
|
}.store(in: &cancellables)
|
||||||
|
|
||||||
NotificationCenter.default.addObserver(
|
NotificationCenter.default.addObserver(
|
||||||
self,
|
self,
|
||||||
|
|
|
||||||
|
|
@ -118,21 +118,6 @@ struct NotchStatsView: View {
|
||||||
return graphs
|
return graphs
|
||||||
}
|
}
|
||||||
|
|
||||||
var dynamicNotchSize: CGSize {
|
|
||||||
let graphCount = availableGraphs.count
|
|
||||||
|
|
||||||
// Base size for 1-3 graphs
|
|
||||||
let baseWidth: CGFloat = 610
|
|
||||||
|
|
||||||
// If 4+ graphs, increase width to accommodate
|
|
||||||
if graphCount >= 4 {
|
|
||||||
let extraWidth: CGFloat = CGFloat(graphCount - 3) * 120
|
|
||||||
return CGSize(width: baseWidth + extraWidth, height: 200)
|
|
||||||
}
|
|
||||||
|
|
||||||
return CGSize(width: baseWidth, height: 200)
|
|
||||||
}
|
|
||||||
|
|
||||||
var gridColumns: [GridItem] {
|
var gridColumns: [GridItem] {
|
||||||
let graphCount = availableGraphs.count
|
let graphCount = availableGraphs.count
|
||||||
|
|
||||||
|
|
@ -264,7 +249,7 @@ struct NotchStatsView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.frame(maxWidth: dynamicNotchSize.width, maxHeight: dynamicNotchSize.height)
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
.background(Color(NSColor.windowBackgroundColor).opacity(0.1))
|
.background(Color(NSColor.windowBackgroundColor).opacity(0.1))
|
||||||
.clipShape(RoundedRectangle(cornerRadius: 12))
|
.clipShape(RoundedRectangle(cornerRadius: 12))
|
||||||
.onAppear {
|
.onAppear {
|
||||||
|
|
|
||||||
|
|
@ -116,13 +116,36 @@ class DynamicIslandViewModel: NSObject, ObservableObject {
|
||||||
|
|
||||||
func open() {
|
func open() {
|
||||||
withAnimation(.bouncy) {
|
withAnimation(.bouncy) {
|
||||||
self.notchSize = openNotchSize
|
self.notchSize = calculateDynamicNotchSize()
|
||||||
self.notchState = .open
|
self.notchState = .open
|
||||||
}
|
}
|
||||||
|
|
||||||
// Force music information update when notch is opened
|
// Force music information update when notch is opened
|
||||||
MusicManager.shared.forceUpdate()
|
MusicManager.shared.forceUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func calculateDynamicNotchSize() -> CGSize {
|
||||||
|
// Only apply dynamic sizing when on stats tab and stats are enabled
|
||||||
|
guard DynamicIslandViewCoordinator.shared.currentView == .stats && Defaults[.enableStatsFeature] else {
|
||||||
|
return openNotchSize
|
||||||
|
}
|
||||||
|
|
||||||
|
let enabledGraphsCount = [
|
||||||
|
Defaults[.showCpuGraph],
|
||||||
|
Defaults[.showMemoryGraph],
|
||||||
|
Defaults[.showGpuGraph],
|
||||||
|
Defaults[.showNetworkGraph],
|
||||||
|
Defaults[.showDiskGraph]
|
||||||
|
].filter { $0 }.count
|
||||||
|
|
||||||
|
// If 4+ graphs are enabled, increase width
|
||||||
|
if enabledGraphsCount >= 4 {
|
||||||
|
let extraWidth: CGFloat = CGFloat(enabledGraphsCount - 3) * 120
|
||||||
|
return CGSize(width: openNotchSize.width + extraWidth, height: openNotchSize.height)
|
||||||
|
}
|
||||||
|
|
||||||
|
return openNotchSize
|
||||||
|
}
|
||||||
|
|
||||||
func close() {
|
func close() {
|
||||||
withAnimation(.smooth) { [weak self] in
|
withAnimation(.smooth) { [weak self] in
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue