diff --git a/Shared/Navigation/ContentView.swift b/Shared/Navigation/ContentView.swift index 73bdfc1..bbbd598 100644 --- a/Shared/Navigation/ContentView.swift +++ b/Shared/Navigation/ContentView.swift @@ -1,86 +1,88 @@ import SwiftUI struct ContentView: View { @EnvironmentObject var model: WriteFreelyModel @EnvironmentObject var errorHandling: ErrorHandling var body: some View { NavigationView { #if os(macOS) CollectionListView() .withErrorHandling() .toolbar { Button( action: { NSApp.keyWindow?.contentViewController?.tryToPerform( #selector(NSSplitViewController.toggleSidebar(_:)), with: nil ) }, label: { Image(systemName: "sidebar.left") } ) .help("Toggle the sidebar's visibility.") Spacer() Button(action: { withAnimation { // Un-set the currently selected post self.model.selectedPost = nil } // Create the new-post managed object let managedPost = model.editor.generateNewLocalPost(withFont: model.preferences.font) withAnimation { DispatchQueue.main.async { // Load the new post in the editor self.model.selectedPost = managedPost } } }, label: { Image(systemName: "square.and.pencil") }) .help("Create a new local draft.") } + .frame(idealWidth: 200) #else CollectionListView() .withErrorHandling() #endif #if os(macOS) ZStack { PostListView(selectedCollection: model.selectedCollection, showAllPosts: model.showAllPosts) .withErrorHandling() + .frame(idealWidth: 300) if model.isProcessingRequest { ZStack { Color(NSColor.controlBackgroundColor).opacity(0.75) ProgressView() } } } #else PostListView(selectedCollection: model.selectedCollection, showAllPosts: model.showAllPosts) .withErrorHandling() #endif Text("Select a post, or create a new local draft.") .foregroundColor(.secondary) } .environmentObject(model) .onChange(of: model.hasError) { value in if value { if let error = model.currentError { self.errorHandling.handle(error: error) } else { self.errorHandling.handle(error: AppError.genericError()) } model.hasError = false } } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { let context = LocalStorageManager.standard.container.viewContext let model = WriteFreelyModel() return ContentView() .environment(\.managedObjectContext, context) .environmentObject(model) } } diff --git a/macOS/AppDelegate.swift b/macOS/AppDelegate.swift index d6f577e..a1dd53f 100644 --- a/macOS/AppDelegate.swift +++ b/macOS/AppDelegate.swift @@ -1,37 +1,36 @@ import Cocoa -import Sparkle class AppDelegate: NSObject, NSApplicationDelegate { // MARK: - Window handling when miniaturized into app icon on the Dock // Credit to Henry Cooper (pillboxer) on GitHub: // https://github.com/tact/beta-bugs/issues/31#issuecomment-855914705 // If the window is currently minimized into the Dock, de-miniaturize it (note that if it's minimized // and the user uses OPT+TAB to switch to it, it will be de-miniaturized and brought to the foreground). func applicationDidBecomeActive(_ notification: Notification) { if let window = NSApp.windows.first { window.deminiaturize(nil) } } // If we're miniaturizing the window, deactivate it as well. // Credit to KHKnobl on GitHub: // https://github.com/writefreely/writefreely-swiftui-multiplatform/issues/135#issuecomment-1101713817 func applicationDidChangeOcclusionState(_ notification: Notification) { if let window = NSApp.windows.first, window.isMiniaturized { NSApp.hide(self) } } lazy var windows = NSWindow() func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool { if !flag { for window in sender.windows { window.makeKeyAndOrderFront(self) } } return true } }