Commit 8a11e7f9 authored by Kourser's avatar Kourser
Browse files

Mac menu bar capture: quick note, screenshots and clipboard into the open or today's note

MenuBarExtra with a quick note window, region/window/full-screen capture via
ScreenCaptureKit and clipboard paste. Open editors receive captures directly;
otherwise today's journal entry is updated or created. Settings: show the icon,
default destination, open at login. 1.3.0 build 19 for TestFlight.

Co-Authored-By: default avatarClaude Opus 5.5 <noreply@anthropic.com>
parent 72f0a8e3
Loading
Loading
Loading
Loading
+31
Changes for App/EnvorennApp.swift: 31 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -13,6 +13,10 @@ struct EnvorennApp: App {
    @State private var location = LocationCapture()
    @State private var commands = AppCommands()
    @State private var settingsRoute = SettingsRoute()
    #if os(macOS)
    @State private var captureCenter = CaptureCenter()
    @AppStorage(CapturePreference.menuBar) private var showsMenuBar = true
    #endif
    @AppStorage(AppLanguage.preference) private var language = ""
    @AppStorage(AppPreference.appearance) private var appearance = AppAppearance.system.rawValue
    @AppStorage(AppPreference.textSize) private var textSize = AppTextSize.system.rawValue
@@ -39,6 +43,9 @@ struct EnvorennApp: App {
                .environment(location)
                .environment(commands)
                .environment(settingsRoute)
                #if os(macOS)
                .environment(captureCenter)
                #endif
                .environment(\.locale, AppLanguage.locale)
                .accessibleStyles()
                .preferredColorScheme(AppAppearance(rawValue: appearance)?.colorScheme)
@@ -102,8 +109,32 @@ struct EnvorennApp: App {
            .environment(location)
            .environment(commands)
            .environment(settingsRoute)
            .environment(captureCenter)
        }

        // Capture rapide depuis la barre des menus : note, captures d'écran,
        // presse-papiers, vers la note ouverte ou celle du jour.
        MenuBarExtra(isInserted: $showsMenuBar) {
            CaptureMenu()
                .modifier(VaultSessionEnvironment(library: library))
                .environment(appLock)
                .environment(captureCenter)
                .environment(\.locale, AppLanguage.locale)
        } label: {
            Image(systemName: "square.and.pencil")
                .accessibilityLabel(Text("Capture Envorenn"))
        }

        Window(Text("Note rapide"), id: QuickNoteWindow.id) {
            QuickNoteWindow()
                .modifier(JournalWindowChromeStyle(appearance: appearance, textSize: textSize))
                .modifier(VaultSessionEnvironment(library: library))
                .environment(captureCenter)
        }
        .defaultSize(width: 480, height: 230)
        .windowResizability(.contentMinSize)
        .defaultPosition(.center)

        Window(Text("Aide Envorenn"), id: Self.helpWindowID) {
            MacJournalHelpView()
                .modifier(JournalWindowChromeStyle(appearance: appearance, textSize: textSize))
+47
Changes for App/Features/Journal/JournalComposeView.swift: 47 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -28,6 +28,11 @@ struct JournalComposeView: View {
    @Environment(VaultIdentity.self) private var vault
    @Environment(AppLockController.self) private var appLock
    @Environment(SyncController.self) private var sync
    #if os(macOS)
    /// La barre des menus envoie ses captures à l'éditeur ouvert.
    @Environment(CaptureCenter.self) private var captureCenter
    @State private var captureReceiver = UUID()
    #endif
    @Environment(\.dismiss) private var dismiss
    @Environment(\.scenePhase) private var scenePhase
    @Environment(\.colorScheme) private var colorScheme
@@ -316,6 +321,11 @@ struct JournalComposeView: View {
        .focusedSceneValue(\.journalFindCommand, JournalCommand { markdownEditor.find() })
        .focusedSceneValue(\.journalExportCommand, editing != nil && !hasChanges ? JournalCommand(perform: exportPage) : nil)
        .focusedSceneValue(\.journalRecordCommand, draftReady && !saving && audioContext == nil && !showCamera && !showHandwriting ? JournalCommand(perform: startVoice) : nil)
        .onAppear { registerCapture() }
        .onChange(of: draftReady) { registerCapture() }
        .onChange(of: entryDate) { registerCapture() }
        .onChange(of: editingText) { if editingText { captureCenter.activate(captureReceiver) } }
        .onDisappear { captureCenter.unregister(captureReceiver) }
        .focusedSceneValue(\.journalEditorCommand, draftReady ? JournalEditorCommand(apply: { shortcut in
            markdownEditor.apply(MarkdownAction(shortcut))
        }, toggleMode: {
@@ -1603,3 +1613,40 @@ extension MarkdownAction {
        }
    }
}

#if os(macOS)
extension JournalComposeView {
    /// Se déclare auprès de la barre des menus : ses captures arrivent ici,
    /// et c'est l'éditeur qui les publie avec le reste de la note.
    fileprivate func registerCapture() {
        captureCenter.register(captureReceiver, entryID: editing?.id ?? draftID,
                               isToday: (document?.kind ?? .journal) == .journal && Calendar.current.isDateInToday(entryDate)) { item in
            receiveCapture(item)
        }
    }

    /// Ajoute la capture à la fin de la note. Une image devient une photo de la
    /// note, insérée dans le texte ; au-delà de dix photos, elle est refusée.
    fileprivate func receiveCapture(_ item: CaptureItem) -> Bool {
        guard draftReady, !closingForLock else { return false }
        let separator = text.isEmpty || text.hasSuffix("\n\n") ? "" : (text.hasSuffix("\n") ? "\n" : "\n\n")
        switch item {
        case .text(let value):
            text += separator + value
        case .image(let data, let caption):
            let index: Int
            if photo == nil {
                photo = data; index = 0
            } else if extraPhotos.count < JournalEntry.maximumExtraPhotos {
                extraPhotos.append(data); index = extraPhotos.count
            } else {
                return false
            }
            let name = (editing?.id ?? draftID).uuidString.lowercased() + (index == 0 ? "" : "-\(index + 1)") + ".jpg"
            text += separator + "![\(caption)](\(name))"
        }
        captureCenter.activate(captureReceiver)
        return true
    }
}
#endif
+23
Changes for App/Features/LibraryView.swift: 23 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -281,6 +281,8 @@ struct LibraryView: View {
    @AppStorage(AppPreference.promptsEnabled) private var promptsEnabled = true
    #if os(macOS) && DEBUG
    @Environment(\.openSettings) private var openSettings
    @Environment(\.openWindow) private var openWindow
    @Environment(CaptureCenter.self) private var captureCenter
    #endif
    // Sections du volet que l'on replie quand elles s'allongent ; l'état est
    // retenu d'un lancement à l'autre.
@@ -767,6 +769,23 @@ struct LibraryView: View {
            }
            #if os(macOS)
            if defaults.string(forKey: "EnvorennUITestSettings") != nil { openSettings() }
            // Une capture de test, par le même chemin que la barre des menus.
            if let kind = defaults.string(forKey: "EnvorennUITestCapture") {
                try? await Task.sleep(for: .seconds(2))
                let item: CaptureItem
                if kind == "image", let context = CGContext(data: nil, width: 640, height: 360, bitsPerComponent: 8, bytesPerRow: 0,
                                                            space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: CGImageAlphaInfo.noneSkipLast.rawValue) {
                    context.setFillColor(CGColor(red: 0.36, green: 0.31, blue: 0.77, alpha: 1))
                    context.fill(CGRect(x: 0, y: 0, width: 640, height: 360))
                    item = .image(context.makeImage().flatMap(ScreenCapture.jpeg) ?? Data(), caption: "Capture de test")
                } else {
                    item = .text("Capture de test depuis la barre des menus")
                }
                let target = CaptureDestination(rawValue: defaults.string(forKey: "EnvorennUITestDestination") ?? "today") ?? .today
                do { captureCenter.lastMessage = try captureCenter.deliver(item, to: target, environment: environment, sync: sync) }
                catch { print("EnvorennUITestCapture:", error) }
            }
            if defaults.string(forKey: "EnvorennUITestQuickNote") != nil { openWindow(id: QuickNoteWindow.id) }
            #endif
        }
        #endif
@@ -805,6 +824,10 @@ struct LibraryView: View {
            // Une synchronisation a déposé ou fusionné des souvenirs.
            model?.reload()
        }
        .onChange(of: environment.captureRevision) {
            // Une capture de la barre des menus a écrit la note du jour.
            model?.reload()
        }
        .onChange(of: appLock.isLocked) {
            if appLock.isLocked {
                // Rien ne reste ouvert derrière l'écran de verrouillage. Un
+38 −1
Changes for App/Features/Settings/SettingsView.swift: 38 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -136,7 +136,7 @@ struct SettingsView: View {
        MacSettingsLayout(selection: $macCategory) {
            switch macCategory ?? .writing {
            case .writing:
                Form { writingSection; captureSection }
                Form { writingSection; captureSection; MenuBarSettingsSection() }
            case .shortcuts:
                KeyboardShortcutsSettingsView()
            case .appearance:
@@ -528,3 +528,40 @@ private struct SettingsRow: View {
        }
    }
}

#if os(macOS)
/// Réglages › Écriture › Barre des menus : l'icône de capture rapide, le
/// lancement à l'ouverture de session et la destination des captures.
private struct MenuBarSettingsSection: View {
    @AppStorage(CapturePreference.menuBar) private var showsMenuBar = true
    @AppStorage(CapturePreference.destination) private var destination = CaptureDestination.current.rawValue
    @State private var launchAtLogin = LoginItem.isEnabled
    @State private var loginError: String?

    var body: some View {
        Section {
            Toggle("Afficher Envorenn dans la barre des menus", isOn: $showsMenuBar)
            Picker("Envoyer les captures vers", selection: $destination) {
                ForEach([CaptureDestination.current, .today]) { Text($0.title).tag($0.rawValue) }
            }
            Toggle("Ouvrir Envorenn à l’ouverture de session", isOn: $launchAtLogin)
                .onChange(of: launchAtLogin) {
                    do { try LoginItem.set(launchAtLogin); loginError = nil }
                    catch {
                        loginError = String(localized: "macOS n’a pas accepté ce réglage. Réessayez depuis Réglages Système › Général › Ouverture.", bundle: AppLanguage.bundle, locale: AppLanguage.locale)
                        launchAtLogin = LoginItem.isEnabled
                    }
                }
            if let loginError { Text(verbatim: loginError).foregroundStyle(Color.warning) }
        } header: {
            Text("Barre des menus")
        } footer: {
            Text("Note rapide, captures d’écran et presse-papiers, depuis l’icône de la barre des menus. Une capture va dans la note ouverte, ou dans la note du jour si aucune ne l’est.")
        }
    }
}
#else
private struct MenuBarSettingsSection: View {
    var body: some View { EmptyView() }
}
#endif
+4260

File changed.

Preview size limit exceeded, changes collapsed.

Loading