73 lines
2.7 KiB
Swift
73 lines
2.7 KiB
Swift
import Foundation
|
|
import HelderCore
|
|
import HelderServices
|
|
|
|
/// Every service one project window needs. Tests pass fakes; the app uses `live(root:)`.
|
|
public struct WorkspaceServices {
|
|
public var git: GitServicing
|
|
public var files: FileServicing
|
|
public var search: SearchServicing
|
|
public var symbols: SymbolServicing
|
|
public var config: ConfigServicing
|
|
public var notes: NotesServicing
|
|
public var recentFiles: RecentFilesStoring
|
|
|
|
public init(git: GitServicing, files: FileServicing, search: SearchServicing, symbols: SymbolServicing,
|
|
config: ConfigServicing, notes: NotesServicing, recentFiles: RecentFilesStoring) {
|
|
self.git = git
|
|
self.files = files
|
|
self.search = search
|
|
self.symbols = symbols
|
|
self.config = config
|
|
self.notes = notes
|
|
self.recentFiles = recentFiles
|
|
}
|
|
|
|
public static func live(root: URL) -> WorkspaceServices {
|
|
let config = ConfigService(root: root)
|
|
let search = RipgrepSearchService(root: root, config: config)
|
|
return WorkspaceServices(
|
|
git: GitService(root: root),
|
|
files: FileService(root: root, search: search),
|
|
search: search,
|
|
symbols: SymbolService(root: root, config: config),
|
|
config: config,
|
|
notes: NotesService(root: root),
|
|
recentFiles: RecentFilesStore(root: root)
|
|
)
|
|
}
|
|
}
|
|
|
|
/// Services shared by every window: what outlives one project.
|
|
public struct AppServices {
|
|
public var recentProjects: RecentProjectsStoring
|
|
public var session: SessionStoring
|
|
/// Column widths and toggles, per project.
|
|
public var layouts: LayoutPersisting
|
|
/// Dialogs, pasteboard, Finder.
|
|
public var system: SystemActing
|
|
/// Builds the services for a project folder.
|
|
public var makeWorkspace: (URL) -> WorkspaceServices
|
|
public var makeWatcher: () -> FileWatching
|
|
|
|
/// Every store is passed in, so a test can never reach the user's real recents, sessions or layouts.
|
|
public init(recentProjects: RecentProjectsStoring, session: SessionStoring, layouts: LayoutPersisting, system: SystemActing,
|
|
makeWorkspace: @escaping (URL) -> WorkspaceServices, makeWatcher: @escaping () -> FileWatching) {
|
|
self.recentProjects = recentProjects
|
|
self.session = session
|
|
self.layouts = layouts
|
|
self.system = system
|
|
self.makeWorkspace = makeWorkspace
|
|
self.makeWatcher = makeWatcher
|
|
}
|
|
|
|
public static let live = AppServices(
|
|
recentProjects: RecentProjectsStore(),
|
|
session: SessionStore(),
|
|
layouts: UserDefaultsLayoutStore(),
|
|
system: LiveSystemActions(),
|
|
makeWorkspace: WorkspaceServices.live(root:),
|
|
makeWatcher: { FSEventsWatcher() }
|
|
)
|
|
}
|