mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-27 15:53:31 +03:00
Show no preview initially
This commit is contained in:
parent
de9d75579d
commit
511e3685ab
@ -52,10 +52,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
fileprivate var launching = true
|
||||
|
||||
override init() {
|
||||
let initialAppState = AppState.default
|
||||
self.stateContext = StateContext(initialAppState)
|
||||
|
||||
let source = self.stateContext.stateSource
|
||||
self.uiRoot = UiRoot(source: source,
|
||||
emitter: self.stateContext.actionEmitter,
|
||||
state: AppState.default) // FIXME
|
||||
state: initialAppState) // FIXME
|
||||
|
||||
self.actionSink = self.actionSubject.asObservable()
|
||||
self.changeSink = self.changeSubject.asObservable()
|
||||
@ -140,7 +143,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate let stateContext = StateContext()
|
||||
fileprivate let stateContext: StateContext
|
||||
fileprivate let uiRoot: UiRoot
|
||||
fileprivate var hasDirtyWindows = true
|
||||
fileprivate var hasMainWindows = false
|
||||
|
@ -10,6 +10,10 @@ class AppDelegateTransformer: Transformer {
|
||||
|
||||
typealias Pair = StateActionPair<AppState, AppDelegate.Action>
|
||||
|
||||
init(baseServerUrl: URL) {
|
||||
self.baseServerUrl = baseServerUrl
|
||||
}
|
||||
|
||||
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
|
||||
return source.map { pair in
|
||||
var state = pair.state
|
||||
@ -21,6 +25,7 @@ class AppDelegateTransformer: Transformer {
|
||||
mainWindow.uuid = UUID().uuidString
|
||||
mainWindow.urlsToOpen = urls.toDict { url in MainWindow.OpenMode.default }
|
||||
mainWindow.cwd = cwd
|
||||
mainWindow.preview.server = self.baseServerUrl.appendingPathComponent("/tools/preview/none")
|
||||
|
||||
state.mainWindows[mainWindow.uuid] = mainWindow
|
||||
|
||||
@ -33,4 +38,6 @@ class AppDelegateTransformer: Transformer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate let baseServerUrl: URL
|
||||
}
|
||||
|
@ -11,13 +11,14 @@ class StateContext {
|
||||
let stateSource: Observable<AppState>
|
||||
let actionEmitter = Emitter<Any>()
|
||||
|
||||
init() {
|
||||
init(_ initialState: AppState) {
|
||||
self.appState = initialState
|
||||
self.stateSource = self.stateSubject.asObservable()
|
||||
let actionSource = self.actionEmitter.observable
|
||||
|
||||
let port = NetUtils.openPort()
|
||||
self.previewTransformer = PreviewTransformer(baseServerUrl: URL(string: "http://localhost:\(port)")!)
|
||||
self.httpServerService = HttpServerService(port: port)
|
||||
self.appDelegateTransformer = AppDelegateTransformer(baseServerUrl: initialState.baseServerUrl)
|
||||
self.previewTransformer = PreviewTransformer(baseServerUrl: initialState.baseServerUrl)
|
||||
self.httpServerService = HttpServerService(port: initialState.baseServerUrl.port ?? 0)
|
||||
|
||||
Observable
|
||||
.of(
|
||||
@ -74,9 +75,9 @@ class StateContext {
|
||||
fileprivate let scheduler = SerialDispatchQueueScheduler(qos: .userInitiated)
|
||||
fileprivate let disposeBag = DisposeBag()
|
||||
|
||||
fileprivate var appState = AppState.default
|
||||
fileprivate var appState: AppState
|
||||
|
||||
fileprivate let appDelegateTransformer = AppDelegateTransformer()
|
||||
fileprivate let appDelegateTransformer: AppDelegateTransformer
|
||||
fileprivate let uiRootTransformer = UiRootTransformer()
|
||||
fileprivate let mainWindowTransformer = MainWindowTransformer()
|
||||
fileprivate let previewTransformer: PreviewTransformer
|
||||
|
@ -24,10 +24,10 @@ class HttpServerService: Service {
|
||||
|
||||
typealias Element = StateActionPair<UuidState<MainWindow.State>, MainWindow.Action>
|
||||
|
||||
init(port: in_port_t) {
|
||||
init(port: Int) {
|
||||
self.port = port
|
||||
do {
|
||||
try self.server.start(port)
|
||||
try self.server.start(in_port_t(port))
|
||||
NSLog("server started on http://localhost:\(port)")
|
||||
|
||||
self.server["/tools/preview/error"] = { r in .ok(.html("ERROR!")) }
|
||||
@ -64,5 +64,5 @@ class HttpServerService: Service {
|
||||
|
||||
fileprivate let server = HttpServer()
|
||||
fileprivate let resourceBaesUrl = Bundle.main.resourceURL!.appendingPathComponent("markdown")
|
||||
fileprivate let port: in_port_t
|
||||
fileprivate let port: Int
|
||||
}
|
||||
|
@ -98,15 +98,16 @@ protocol Service {
|
||||
|
||||
struct AppState {
|
||||
|
||||
static let `default` = AppState(mainWindow: MainWindow.State.default)
|
||||
static let `default` = AppState(baseServerUrl: URL(string: "http://localhost:\(NetUtils.openPort())")!,
|
||||
mainWindow: MainWindow.State.default)
|
||||
|
||||
var currentMainWindow: MainWindow.State
|
||||
var mainWindows: [String: MainWindow.State] = [:]
|
||||
|
||||
let baseServerUrl: URL
|
||||
|
||||
init(mainWindow: MainWindow.State) {
|
||||
self.baseServerUrl = URL(string: "http://localhost:\(NetUtils.openPort())")!
|
||||
init(baseServerUrl: URL, mainWindow: MainWindow.State) {
|
||||
self.baseServerUrl = baseServerUrl
|
||||
self.currentMainWindow = mainWindow
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user