2020-07-22 13:57:10 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
@main
|
|
|
|
struct WriteFreely_MultiPlatformApp: App {
|
2020-08-18 18:06:02 +00:00
|
|
|
@StateObject private var model = WriteFreelyModel()
|
2020-08-12 14:34:12 +00:00
|
|
|
|
|
|
|
#if os(macOS)
|
2020-08-12 14:21:15 +00:00
|
|
|
@State private var selectedTab = 0
|
2020-08-12 14:34:12 +00:00
|
|
|
#endif
|
2020-08-11 18:32:45 +00:00
|
|
|
|
2020-07-22 13:57:10 +00:00
|
|
|
var body: some Scene {
|
|
|
|
WindowGroup {
|
2020-08-18 18:06:02 +00:00
|
|
|
ContentView()
|
2020-11-04 20:23:03 +00:00
|
|
|
.onAppear(perform: {
|
|
|
|
if let lastDraft = model.editor.fetchLastDraftFromUserDefaults() {
|
|
|
|
self.model.selectedPost = lastDraft
|
|
|
|
} else {
|
|
|
|
createNewLocalPost()
|
|
|
|
}
|
|
|
|
})
|
2020-08-18 18:06:02 +00:00
|
|
|
.environmentObject(model)
|
2020-09-09 18:19:40 +00:00
|
|
|
.environment(\.managedObjectContext, LocalStorageManager.persistentContainer.viewContext)
|
2020-08-13 18:54:56 +00:00
|
|
|
// .preferredColorScheme(preferences.selectedColorScheme) // See PreferencesModel for info.
|
2020-07-22 13:57:10 +00:00
|
|
|
}
|
2020-08-07 20:30:09 +00:00
|
|
|
|
|
|
|
#if os(macOS)
|
|
|
|
Settings {
|
2020-08-12 14:21:15 +00:00
|
|
|
TabView(selection: $selectedTab) {
|
2020-08-18 21:20:16 +00:00
|
|
|
MacAccountView()
|
|
|
|
.environmentObject(model)
|
2020-08-12 14:36:49 +00:00
|
|
|
.tabItem {
|
|
|
|
Image(systemName: "person.crop.circle")
|
|
|
|
Text("Account")
|
2020-08-12 14:21:15 +00:00
|
|
|
}
|
2020-08-12 14:36:49 +00:00
|
|
|
.tag(0)
|
2020-08-18 18:06:02 +00:00
|
|
|
MacPreferencesView(preferences: model.preferences)
|
2020-08-12 14:36:10 +00:00
|
|
|
.tabItem {
|
|
|
|
Image(systemName: "gear")
|
|
|
|
Text("Preferences")
|
|
|
|
}
|
|
|
|
.tag(1)
|
2020-08-12 14:21:15 +00:00
|
|
|
}
|
|
|
|
.frame(minWidth: 300, maxWidth: 300, minHeight: 200, maxHeight: 200)
|
|
|
|
.padding()
|
2020-08-13 18:54:56 +00:00
|
|
|
// .preferredColorScheme(preferences.selectedColorScheme) // See PreferencesModel for info.
|
2020-08-07 20:30:09 +00:00
|
|
|
}
|
|
|
|
#endif
|
2020-07-22 13:57:10 +00:00
|
|
|
}
|
2020-11-04 20:23:03 +00:00
|
|
|
|
|
|
|
private func createNewLocalPost() {
|
|
|
|
let managedPost = WFAPost(context: LocalStorageManager.persistentContainer.viewContext)
|
|
|
|
managedPost.createdDate = Date()
|
|
|
|
managedPost.title = ""
|
|
|
|
managedPost.body = ""
|
|
|
|
managedPost.status = PostStatus.local.rawValue
|
|
|
|
managedPost.collectionAlias = nil
|
|
|
|
switch model.preferences.font {
|
|
|
|
case 1:
|
|
|
|
managedPost.appearance = "sans"
|
|
|
|
case 2:
|
|
|
|
managedPost.appearance = "wrap"
|
|
|
|
default:
|
|
|
|
managedPost.appearance = "serif"
|
|
|
|
}
|
|
|
|
if let languageCode = Locale.current.languageCode {
|
|
|
|
managedPost.language = languageCode
|
|
|
|
managedPost.rtl = Locale.characterDirection(forLanguage: languageCode) == .rightToLeft
|
|
|
|
}
|
|
|
|
self.model.selectedPost = managedPost
|
|
|
|
}
|
2020-07-22 13:57:10 +00:00
|
|
|
}
|