65 lines
2.9 KiB
Go
65 lines
2.9 KiB
Go
// Cthulhu screen reader.
|
|
// Copyright (c) 2026 Storm Dragon
|
|
// Authors: Storm Dragon, Angus Kola
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify it
|
|
// under the terms of the GNU General Public License as published by the Free
|
|
// Software Foundation, either version 3 of the License, or (at your option)
|
|
// any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
// more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License along with
|
|
// this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
|
|
|
|
package app
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
|
|
"git.stormux.org/storm/cthulhu/internal/lifecycle"
|
|
"git.stormux.org/storm/cthulhu/internal/review"
|
|
)
|
|
|
|
// newRuntimeReviewServices registers review after AT-SPI, then optional browser
|
|
// mode and secure lock. Reverse shutdown therefore stops review before AT-SPI
|
|
// releases native callback state.
|
|
func newRuntimeReviewServices(logger *slog.Logger, commands commandListener, adapter Adapter, inputListener InputListener, focusGate *focusGate, speechOutput speechEnqueuer, speechMessages *speechWorker, brailleOutput *brailleWorker, wineCapture ...wineReviewCapturer) (*review.Worker, *browserModeController, []lifecycle.Service, error) {
|
|
var capturer review.TreeCapturer = adapter
|
|
if len(wineCapture) > 0 && wineCapture[0] != nil {
|
|
capturer = &reviewCaptureRouter{native: adapter, wine: wineCapture[0]}
|
|
}
|
|
objectReview, err := review.NewWorker(capturer, objectReviewCaptureTimeout)
|
|
if err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
if err := objectReview.SetFlatCaptureTimeout(flatReviewCaptureTimeout); err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
services := []lifecycle.Service{{Name: "object review", Start: objectReview.Start, Stop: objectReview.Stop}}
|
|
var browser *browserModeController
|
|
if keys, ok := commands.(browseKeyOwner); ok {
|
|
if capturer, ok := adapter.(documentContextCapturer); ok {
|
|
browser = newBrowserModeController(inputListener, keys, capturer)
|
|
services = append(services, lifecycle.Service{Name: "browser mode", Start: browser.Start, Stop: browser.Stop})
|
|
}
|
|
}
|
|
focusGate.speech = speechOutput
|
|
lockMonitor := &screenLockMonitor{logger: logger, setActive: func(active bool) {
|
|
focusGate.SetLocked(active, adapter, inputListener, commands, speechMessages, brailleOutput)
|
|
objectReview.ClearFocus()
|
|
logger.Info("I38lock secure mode changed", "active", active)
|
|
}}
|
|
services = append(services, lifecycle.Service{Name: "screen lock", Start: func(ctx context.Context) error {
|
|
if err := lockMonitor.Start(ctx); err != nil {
|
|
logger.Warn("I38lock monitor unavailable", "error", err)
|
|
}
|
|
return nil
|
|
}, Stop: lockMonitor.Stop})
|
|
return objectReview, browser, services, nil
|
|
}
|