Skip to content

Commit

Permalink
Fix spm errors and upgrade sparkle (#203)
Browse files Browse the repository at this point in the history
* Switch WriteFreely package import from ssh to https

* Sign macOS project target for Development

This fixes a crash-on-launch bug when running Product > Run from Xcode (Product > Archive should work correctly). See sparkle-project/Sparkle#2056 for more details.

Bug introduced by commit:
671b054

* Update Sparkle to v2.0 from official repo

Previously, we forked the repo to the WriteFreely org because Sparkle didn't support tag-based SPM updates. We therefore had to pull from the `master` branch, so forking insulated us from unexpected changes.

As of 2.x Sparkle now allows for tag-based updating via SPM; we'll allow patch updates but stop short of 2.1 until we can vet changes.

* Add MacUpdatesViewModel ObservableObject

* Use MacUpdatesViewModel to handle Sparkle update logic
  • Loading branch information
AngeloStavrow committed Apr 2, 2022
1 parent 7b68da2 commit 1bc8468
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 88 deletions.
19 changes: 5 additions & 14 deletions Shared/WriteFreely_MultiPlatformApp.swift
Expand Up @@ -25,8 +25,8 @@ struct WriteFreely_MultiPlatformApp: App {
@StateObject private var model = WriteFreelyModel.shared

#if os(macOS)
// swiftlint:disable:next weak_delegate
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@StateObject var updaterViewModel = MacUpdatesViewModel()
@State private var selectedTab = 0
#endif

Expand All @@ -47,25 +47,16 @@ struct WriteFreely_MultiPlatformApp: App {
showLastDraftOrCreateNewLocalPost()
}
}
// DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
// if model.editor.lastDraftURL != nil {
// self.model.selectedPost = model.editor.fetchLastDraftFromAppStorage()
// } else {
// createNewLocalPost()
// }
// }
})
.environmentObject(model)
.environment(\.managedObjectContext, LocalStorageManager.standard.container.viewContext)
// .preferredColorScheme(preferences.selectedColorScheme) // See PreferencesModel for info.
}
.commands {
#if os(macOS)
CommandGroup(after: .appInfo, addition: {
Button("Check For Updates") {
SUUpdater.shared()?.checkForUpdates(self)
}
})
CommandGroup(after: .appInfo) {
CheckForUpdatesView(updaterViewModel: updaterViewModel)
}
#endif
CommandGroup(replacing: .newItem, addition: {
Button("New Post") {
Expand Down Expand Up @@ -116,7 +107,7 @@ struct WriteFreely_MultiPlatformApp: App {
Text("Preferences")
}
.tag(1)
MacUpdatesView()
MacUpdatesView(updaterViewModel: updaterViewModel)
.tabItem {
Image(systemName: "arrow.down.circle")
Text("Updates")
Expand Down
66 changes: 35 additions & 31 deletions WriteFreely-MultiPlatform.xcodeproj/project.pbxproj
Expand Up @@ -20,8 +20,6 @@
17120DAC24E1B99F002B9F6C /* AccountLoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17120DAB24E1B99F002B9F6C /* AccountLoginView.swift */; };
17120DAD24E1B99F002B9F6C /* AccountLoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17120DAB24E1B99F002B9F6C /* AccountLoginView.swift */; };
17120DB224E1E19C002B9F6C /* SettingsHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17120DB124E1E19C002B9F6C /* SettingsHeaderView.swift */; };
1714DD65260BAC14000C0DFF /* WriteFreely in Frameworks */ = {isa = PBXBuildFile; productRef = 1714DD64260BAC14000C0DFF /* WriteFreely */; };
1714DD6B260BAC2C000C0DFF /* WriteFreely in Frameworks */ = {isa = PBXBuildFile; productRef = 1714DD6A260BAC2C000C0DFF /* WriteFreely */; };
171BFDFA24D4AF8300888236 /* CollectionListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 171BFDF924D4AF8300888236 /* CollectionListView.swift */; };
171BFDFB24D4AF8300888236 /* CollectionListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 171BFDF924D4AF8300888236 /* CollectionListView.swift */; };
171DC677272C7D0B002B9B8A /* UserDefaults+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 171DC676272C7D0B002B9B8A /* UserDefaults+Extensions.swift */; };
Expand All @@ -35,7 +33,6 @@
172E10152735C2BD00061372 /* UIHostingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 172E10142735C2BD00061372 /* UIHostingView.swift */; };
172E10172735C2DF00061372 /* EnvironmentValues+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 172E10162735C2DF00061372 /* EnvironmentValues+Extensions.swift */; };
172E10192735C3DB00061372 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 172E10182735C3DB00061372 /* ContentView.swift */; };
172E101B2735C54400061372 /* WriteFreely in Frameworks */ = {isa = PBXBuildFile; productRef = 172E101A2735C54400061372 /* WriteFreely */; };
172E101C2735C57400061372 /* LocalStorageManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1756DBB924FED45500207AB8 /* LocalStorageManager.swift */; };
172E101D2735C5AB00061372 /* LocalStorageModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 1756DBB524FED3A400207AB8 /* LocalStorageModel.xcdatamodeld */; };
172E101E2735C62F00061372 /* PostStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17C42E612507D8E600072984 /* PostStatus.swift */; };
Expand Down Expand Up @@ -78,7 +75,9 @@
17836C15273F0FBB0047AF61 /* Hack-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 17D4F3A42514F1E900517CE6 /* Hack-Regular.ttf */; };
17836C16273F0FBB0047AF61 /* LoraGX.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 17D4F36B2514EE2F00517CE6 /* LoraGX.ttf */; };
17836C17273F0FBB0047AF61 /* OpenSans-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 17D4F39D2514F0E500517CE6 /* OpenSans-Regular.ttf */; };
17A4FEDA25924AF70037E96B /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = 17A4FED925924AF70037E96B /* Sparkle */; };
1784D2ED27946D880033E72E /* WriteFreely in Frameworks */ = {isa = PBXBuildFile; productRef = 1784D2EC27946D880033E72E /* WriteFreely */; };
1784D2EF27946D9A0033E72E /* WriteFreely in Frameworks */ = {isa = PBXBuildFile; productRef = 1784D2EE27946D9A0033E72E /* WriteFreely */; };
1784D2F127946DA10033E72E /* WriteFreely in Frameworks */ = {isa = PBXBuildFile; productRef = 1784D2F027946DA10033E72E /* WriteFreely */; };
17A4FEED25927E730037E96B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17A4FEEC25927E730037E96B /* AppDelegate.swift */; };
17A5388824DDA31F00DEFF9A /* MacAccountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17A5388724DDA31F00DEFF9A /* MacAccountView.swift */; };
17A5388C24DDC83F00DEFF9A /* AccountModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17A5388B24DDC83F00DEFF9A /* AccountModel.swift */; };
Expand Down Expand Up @@ -108,6 +107,8 @@
17C42E71250AAFD500072984 /* NSManagedObjectContext+ExecuteAndMergeChanges.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17C42E6F250AA12200072984 /* NSManagedObjectContext+ExecuteAndMergeChanges.swift */; };
17D435E824E3128F0036B539 /* PreferencesModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17D435E724E3128F0036B539 /* PreferencesModel.swift */; };
17D435E924E3128F0036B539 /* PreferencesModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17D435E724E3128F0036B539 /* PreferencesModel.swift */; };
17D4926527947B4D0035BD7E /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = 17D4926427947B4D0035BD7E /* Sparkle */; };
17D4926727947D780035BD7E /* MacUpdatesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17D4926627947D780035BD7E /* MacUpdatesViewModel.swift */; };
17D4F36C2514EE2F00517CE6 /* LoraGX.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 17D4F36B2514EE2F00517CE6 /* LoraGX.ttf */; };
17D4F36D2514EE2F00517CE6 /* LoraGX.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 17D4F36B2514EE2F00517CE6 /* LoraGX.ttf */; };
17D4F39E2514F0E500517CE6 /* OpenSans-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 17D4F39D2514F0E500517CE6 /* OpenSans-Regular.ttf */; };
Expand Down Expand Up @@ -234,6 +235,7 @@
17C42E642509237800072984 /* PostListFilteredView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostListFilteredView.swift; sourceTree = "<group>"; };
17C42E6F250AA12200072984 /* NSManagedObjectContext+ExecuteAndMergeChanges.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSManagedObjectContext+ExecuteAndMergeChanges.swift"; sourceTree = "<group>"; };
17D435E724E3128F0036B539 /* PreferencesModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesModel.swift; sourceTree = "<group>"; };
17D4926627947D780035BD7E /* MacUpdatesViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacUpdatesViewModel.swift; sourceTree = "<group>"; };
17D4F36B2514EE2F00517CE6 /* LoraGX.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = LoraGX.ttf; sourceTree = "<group>"; };
17D4F39D2514F0E500517CE6 /* OpenSans-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "OpenSans-Regular.ttf"; sourceTree = "<group>"; };
17D4F3A42514F1E900517CE6 /* Hack-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Hack-Regular.ttf"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -269,24 +271,24 @@
buildActionMask = 2147483647;
files = (
172E10012735B83E00061372 /* UniformTypeIdentifiers.framework in Frameworks */,
172E101B2735C54400061372 /* WriteFreely in Frameworks */,
1784D2F127946DA10033E72E /* WriteFreely in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
17DF328524C87D3500BCE2E3 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
1714DD65260BAC14000C0DFF /* WriteFreely in Frameworks */,
1784D2ED27946D880033E72E /* WriteFreely in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
17DF328D24C87D3500BCE2E3 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
17A4FEDA25924AF70037E96B /* Sparkle in Frameworks */,
1714DD6B260BAC2C000C0DFF /* WriteFreely in Frameworks */,
1784D2EF27946D9A0033E72E /* WriteFreely in Frameworks */,
17D4926527947B4D0035BD7E /* Sparkle in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -400,6 +402,7 @@
17A5388724DDA31F00DEFF9A /* MacAccountView.swift */,
1753F6AB24E431CC00309365 /* MacPreferencesView.swift */,
172C492D2593981900E20ADF /* MacUpdatesView.swift */,
17D4926627947D780035BD7E /* MacUpdatesViewModel.swift */,
);
path = Settings;
sourceTree = "<group>";
Expand Down Expand Up @@ -619,7 +622,7 @@
);
name = "ActionExtension-iOS";
packageProductDependencies = (
172E101A2735C54400061372 /* WriteFreely */,
1784D2F027946DA10033E72E /* WriteFreely */,
);
productName = "ActionExtension-iOS";
productReference = 172E0FFF2735B83E00061372 /* ActionExtension-iOS.appex */;
Expand All @@ -642,7 +645,7 @@
);
name = "WriteFreely-MultiPlatform (iOS)";
packageProductDependencies = (
1714DD64260BAC14000C0DFF /* WriteFreely */,
1784D2EC27946D880033E72E /* WriteFreely */,
);
productName = "WriteFreely-MultiPlatform (iOS)";
productReference = 17DF328824C87D3500BCE2E3 /* WriteFreely-MultiPlatform.app */;
Expand All @@ -663,8 +666,8 @@
);
name = "WriteFreely-MultiPlatform (macOS)";
packageProductDependencies = (
17A4FED925924AF70037E96B /* Sparkle */,
1714DD6A260BAC2C000C0DFF /* WriteFreely */,
1784D2EE27946D9A0033E72E /* WriteFreely */,
17D4926427947B4D0035BD7E /* Sparkle */,
);
productName = "WriteFreely-MultiPlatform (macOS)";
productReference = 17DF329024C87D3500BCE2E3 /* WriteFreely for Mac.app */;
Expand Down Expand Up @@ -744,8 +747,8 @@
);
mainGroup = 17DF327B24C87D3300BCE2E3;
packageReferences = (
17A4FED825924AF70037E96B /* XCRemoteSwiftPackageReference "Sparkle" */,
1714DD63260BAC14000C0DFF /* XCRemoteSwiftPackageReference "writefreely-swift" */,
1784D2EB27946D880033E72E /* XCRemoteSwiftPackageReference "writefreely-swift" */,
17D4926327947B4D0035BD7E /* XCRemoteSwiftPackageReference "Sparkle" */,
);
productRefGroup = 17DF328924C87D3500BCE2E3 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -942,6 +945,7 @@
17480CA6251272EE00EB7765 /* Bundle+AppVersion.swift in Sources */,
17C42E662509237800072984 /* PostListFilteredView.swift in Sources */,
17120DAD24E1B99F002B9F6C /* AccountLoginView.swift in Sources */,
17D4926727947D780035BD7E /* MacUpdatesViewModel.swift in Sources */,
17466626256C0D0600629997 /* MacEditorTextView.swift in Sources */,
170A7EC226F5186A00F1CBD4 /* CollectionListModel.swift in Sources */,
17E5DF8A2543610700DCDC9B /* PostTextEditingView.swift in Sources */,
Expand Down Expand Up @@ -1243,7 +1247,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = macOS/macOS.entitlements;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 620;
Expand All @@ -1270,7 +1274,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = macOS/macOS.entitlements;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 620;
Expand Down Expand Up @@ -1440,43 +1444,43 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
1714DD63260BAC14000C0DFF /* XCRemoteSwiftPackageReference "writefreely-swift" */ = {
1784D2EB27946D880033E72E /* XCRemoteSwiftPackageReference "writefreely-swift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "git@github.com:writefreely/writefreely-swift.git";
repositoryURL = "https://github.com/writefreely/writefreely-swift";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.3.2;
minimumVersion = 0.3.4;
};
};
17A4FED825924AF70037E96B /* XCRemoteSwiftPackageReference "Sparkle" */ = {
17D4926327947B4D0035BD7E /* XCRemoteSwiftPackageReference "Sparkle" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/writefreely/Sparkle";
repositoryURL = "https://github.com/sparkle-project/Sparkle";
requirement = {
branch = master;
kind = branch;
kind = upToNextMinorVersion;
minimumVersion = 2.0.0;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
1714DD64260BAC14000C0DFF /* WriteFreely */ = {
1784D2EC27946D880033E72E /* WriteFreely */ = {
isa = XCSwiftPackageProductDependency;
package = 1714DD63260BAC14000C0DFF /* XCRemoteSwiftPackageReference "writefreely-swift" */;
package = 1784D2EB27946D880033E72E /* XCRemoteSwiftPackageReference "writefreely-swift" */;
productName = WriteFreely;
};
1714DD6A260BAC2C000C0DFF /* WriteFreely */ = {
1784D2EE27946D9A0033E72E /* WriteFreely */ = {
isa = XCSwiftPackageProductDependency;
package = 1714DD63260BAC14000C0DFF /* XCRemoteSwiftPackageReference "writefreely-swift" */;
package = 1784D2EB27946D880033E72E /* XCRemoteSwiftPackageReference "writefreely-swift" */;
productName = WriteFreely;
};
172E101A2735C54400061372 /* WriteFreely */ = {
1784D2F027946DA10033E72E /* WriteFreely */ = {
isa = XCSwiftPackageProductDependency;
package = 1714DD63260BAC14000C0DFF /* XCRemoteSwiftPackageReference "writefreely-swift" */;
package = 1784D2EB27946D880033E72E /* XCRemoteSwiftPackageReference "writefreely-swift" */;
productName = WriteFreely;
};
17A4FED925924AF70037E96B /* Sparkle */ = {
17D4926427947B4D0035BD7E /* Sparkle */ = {
isa = XCSwiftPackageProductDependency;
package = 17A4FED825924AF70037E96B /* XCRemoteSwiftPackageReference "Sparkle" */;
package = 17D4926327947B4D0035BD7E /* XCRemoteSwiftPackageReference "Sparkle" */;
productName = Sparkle;
};
/* End XCSwiftPackageProductDependency section */
Expand Down
Expand Up @@ -7,17 +7,17 @@
<key>ActionExtension-iOS.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
<key>WriteFreely-MultiPlatform (iOS).xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>2</integer>
</dict>
<key>WriteFreely-MultiPlatform (macOS).xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>2</integer>
<integer>0</integer>
</dict>
</dict>
</dict>
Expand Down
23 changes: 0 additions & 23 deletions macOS/AppDelegate.swift
Expand Up @@ -3,34 +3,13 @@ import Sparkle

class AppDelegate: NSObject, NSApplicationDelegate {

func applicationWillFinishLaunching(_ notification: Notification) {
// Check UserDefaults for values; if the key doesn't exist (e.g., if MacUpdatesView hasn't ever been shown),
// bool(forKey:) returns false, so set SUUpdater.shared() appropriately.
let automaticallyChecksForUpdates = UserDefaults.shared.bool(forKey: WFDefaults.automaticallyChecksForUpdates)
let subscribeToBetaUpdates = UserDefaults.shared.bool(forKey: WFDefaults.subscribeToBetaUpdates)

// Set Sparkle properties.
SUUpdater.shared()?.automaticallyChecksForUpdates = automaticallyChecksForUpdates
if subscribeToBetaUpdates {
SUUpdater.shared()?.feedURL = URL(string: AppcastFeedUrl.beta.rawValue)
} else {
SUUpdater.shared()?.feedURL = URL(string: AppcastFeedUrl.release.rawValue)
}

// If enabled, check for updates.
if automaticallyChecksForUpdates {
SUUpdater.shared()?.checkForUpdatesInBackground()
}
}

// MARK: - Window handling when miniaturized into app icon on the Dock
// Credit to Henry Cooper (pillboxer) on GitHub:
// https://github.com/tact/beta-bugs/issues/31#issuecomment-855914705

// If the window is currently minimized into the Dock, de-miniaturize it (note that if it's minimized
// and the user uses OPT+TAB to switch to it, it will be de-miniaturized and brought to the foreground).
func applicationDidBecomeActive(_ notification: Notification) {
print("💬 Fired:", #function)
if let window = NSApp.windows.first {
window.deminiaturize(nil)
}
Expand All @@ -39,7 +18,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
// If we're miniaturizing the window, deactivate it as well by activating Finder.app (note that
// this will bring any Finder windows that are behind other apps to the foreground).
func applicationDidChangeOcclusionState(_ notification: Notification) {
print("💬 Fired:", #function)
if let window = NSApp.windows.first, window.isMiniaturized {
NSWorkspace.shared.runningApplications.first(where: {
$0.activationPolicy == .regular
Expand All @@ -49,7 +27,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {

lazy var windows = NSWindow()
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
print("💬 Fired:", #function)
if !flag {
for window in sender.windows {
window.makeKeyAndOrderFront(self)
Expand Down

0 comments on commit 1bc8468

Please sign in to comment.