From bcbb38c120532f18ecf8ae136ad628457af6199c Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 5 Jul 2020 19:49:07 -0500 Subject: [PATCH] Change to initialize Refresh when the onAppear event happens so that we quit crashing on macOS --- Multiplatform/Shared/MainApp.swift | 6 ++++++ Multiplatform/Shared/SceneModel.swift | 9 ++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Multiplatform/Shared/MainApp.swift b/Multiplatform/Shared/MainApp.swift index 3e8200009..6cd5dcd50 100644 --- a/Multiplatform/Shared/MainApp.swift +++ b/Multiplatform/Shared/MainApp.swift @@ -29,6 +29,9 @@ struct MainApp: App { .frame(minWidth: 600, idealWidth: 1000, maxWidth: .infinity, minHeight: 600, idealHeight: 700, maxHeight: .infinity) .environmentObject(sceneModel) .environmentObject(defaults) + .onAppear { + sceneModel.startup() + } .sheet(isPresented: $showSheet, onDismiss: { showSheet = false }) { AddWebFeedView() } @@ -155,6 +158,9 @@ struct MainApp: App { .environmentObject(sceneModel) .environmentObject(defaults) .modifier(PreferredColorSchemeModifier(preferredColorScheme: defaults.userInterfaceColorPalette)) + .onAppear { + sceneModel.startup() + } } .commands { CommandGroup(after: .newItem, addition: { diff --git a/Multiplatform/Shared/SceneModel.swift b/Multiplatform/Shared/SceneModel.swift index 99071215f..250df5031 100644 --- a/Multiplatform/Shared/SceneModel.swift +++ b/Multiplatform/Shared/SceneModel.swift @@ -17,13 +17,12 @@ final class SceneModel: ObservableObject { var timelineModel: TimelineModel? var articleModel: ArticleModel? - private let refreshProgressModel: RefreshProgressModel + private var refreshProgressModel: RefreshProgressModel? = nil - init(refreshProgressModel: RefreshProgressModel = RefreshProgressModel()) { - self.refreshProgressModel = refreshProgressModel - self.refreshProgressModel.$state.assign(to: self.$refreshProgressState) + func startup() { + self.refreshProgressModel = RefreshProgressModel() + self.refreshProgressModel!.$state.assign(to: self.$refreshProgressState) } - } // MARK: SidebarModelDelegate