forked from y3owk1n/neru
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
140 lines (113 loc) · 3.81 KB
/
Copy pathoptions.go
File metadata and controls
140 lines (113 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package app
import (
"go.uber.org/zap"
"github.com/y3owk1n/neru/internal/config"
"github.com/y3owk1n/neru/internal/ports"
)
// Option is a functional option for configuring an App instance.
type Option func(*App) error
// WithConfig sets the application configuration.
// Note: cfg can be nil, in which case default configuration will be used.
func WithConfig(cfg *config.Config) Option {
return func(a *App) error {
// Config can be nil - system will use defaults
a.config = cfg
return nil
}
}
// WithWrittenConfig records what the configuration passed to WithConfig was
// written as, before the loader settled its derived values — see
// [config.LoadResult.Written]. It is what `neru config set` applies a change
// to, so that a change to a source option can be derived from again.
//
// Optional: without it the app derives from the resolved configuration
// instead, which normalizes what was typed but cannot re-infer.
func WithWrittenConfig(cfg *config.Config) Option {
return func(a *App) error {
a.writtenConfig = cfg
return nil
}
}
// WithConfigPath sets the configuration file path.
func WithConfigPath(path string) Option {
return func(a *App) error {
a.ConfigPath = path
return nil
}
}
// WithLogger sets the application logger.
func WithLogger(logger *zap.Logger) Option {
return func(a *App) error {
// Logger can be nil - system will initialize a default logger if needed
a.logger = logger
return nil
}
}
// WithEventTap sets the event tap implementation.
// Note: eventTap can be nil, will be initialized during app startup if not provided.
func WithEventTap(eventTap ports.EventTapPort) Option {
return func(a *App) error {
a.eventTap = eventTap
return nil
}
}
// WithIPCServer sets the IPC server implementation.
// Note: ipcServer can be nil, will be initialized during app startup if not provided.
func WithIPCServer(ipcServer ports.IPCPort) Option {
return func(a *App) error {
a.ipcServer = ipcServer
return nil
}
}
// WithOverlayPort sets the overlay implementation the app draws through.
//
// It is the one seam between the app and the overlay: a caller that brings its
// own port brings its own screen, and no native backend is built behind it.
// Left unset, the composition root builds the platform backend and the adapter
// over it during startup.
func WithOverlayPort(overlayPort ports.OverlayPort) Option {
return func(a *App) error {
a.overlayPort = overlayPort
return nil
}
}
// WithWatcher sets the app watcher implementation.
// Note: watcher can be nil, will be initialized during app startup if not provided.
func WithWatcher(watcher Watcher) Option {
return func(a *App) error {
a.appWatcher = watcher
return nil
}
}
// WithHotkeyService sets the hotkey service implementation.
// Note: hotkeyService can be nil, will be initialized during app startup if not provided.
func WithHotkeyService(hotkeyService HotkeyService) Option {
return func(a *App) error {
a.hotkeyManager = hotkeyService
return nil
}
}
// WithAccessibility sets the accessibility port implementation.
// Note: accessibility can be nil, will be initialized during app startup if not provided.
func WithAccessibility(accessibility ports.AccessibilityPort) Option {
return func(a *App) error {
a.accessibility = accessibility
return nil
}
}
// WithTextInput sets the text input port implementation.
// Note: textInput can be nil, will be initialized during app startup if not provided.
func WithTextInput(textInput ports.TextInputPort) Option {
return func(a *App) error {
a.textInput = textInput
return nil
}
}
// WithSystemPort sets the system port implementation.
// Note: systemPort can be nil, will be initialized during app startup if not provided.
func WithSystemPort(systemPort ports.SystemPort) Option {
return func(a *App) error {
a.systemPort = systemPort
return nil
}
}