These instructions below are for adding settings in a Cocoa nib and assume you have a Settings nib with its File's Owner
being set to your Settings controller class (e.g, a NSWindowController
subclass). The controller class should have an updater
property set to your application’s SPUUpdater
, which may be passed from your application’s delegate.
File's Owner
from the popup, and set the Model Key Path to updater.automaticallyChecksForUpdates
.File's Owner
from the popup, and set the Model Key Path to updater.updateCheckInterval
.File's Owner
from the popup, and set the Model Key Path to updater.automaticallyChecksForUpdates
.Follow directions similar to Enable automatic checking to bind a check button to updater.sendsSystemProfile
or updater.automaticallyDownloadsUpdates
. See customization for details on the available keys.
This is a continuation from Creating an Updater in SwiftUI.
Create a new view for the updater settings:
// This is the view for our updater settings
// It manages local state for checking for updates and automatically downloading updates
// Upon user changes to these, the updater's properties are set. These are backed by NSUserDefaults.
// Note the updater properties should *only* be set when the user changes the state.
struct UpdaterSettingsView: View {
private let updater: SPUUpdater
@State private var automaticallyChecksForUpdates: Bool
@State private var automaticallyDownloadsUpdates: Bool
init(updater: SPUUpdater) {
self.updater = updater
self.automaticallyChecksForUpdates = updater.automaticallyChecksForUpdates
self.automaticallyDownloadsUpdates = updater.automaticallyDownloadsUpdates
}
var body: some View {
VStack {
Toggle("Automatically check for updates", isOn: $automaticallyChecksForUpdates)
.onChange(of: automaticallyChecksForUpdates) { newValue in
updater.automaticallyChecksForUpdates = newValue
}
Toggle("Automatically download updates", isOn: $automaticallyDownloadsUpdates)
.disabled(!automaticallyChecksForUpdates)
.onChange(of: automaticallyDownloadsUpdates) { newValue in
updater.automaticallyDownloadsUpdates = newValue
}
}.padding()
}
}
Then add these settings to your App
’s body
:
var body: some Scene {
/* ... */
Settings {
UpdaterSettingsView(updater: updaterController.updater)
}
}
This is a continuation from Creating an Updater in Qt and illustrates one way of adding updater settings.
Add new methods for connecting and setting the updater’s automaticallyChecksForUpdates property from a QCheckBox
:
// File: updater.h
/* ... */
class QAction;
class QCheckBox;
class Updater : public QObject
{
Q_OBJECT
public:
Updater(QAction *checkForUpdatesAction);
void connectAutomaticallyCheckForUpdatesButton(QCheckBox *checkBox);
private slots:
void checkForUpdates();
void setAutomaticallyCheckForUpdates(int newState);
/* ... */
}
Then implement the new methods:
#include "updater.h"
#include <qaction.h>
#include <qcheckbox.h>
#import <Sparkle/Sparkle.h>
/* ... */
void Updater::connectAutomaticallyCheckForUpdatesButton(QCheckBox *checkBox)
{
@autoreleasepool {
checkBox->setChecked(_updaterDelegate.updaterController.updater.automaticallyChecksForUpdates ? Qt::CheckState::Checked : Qt::CheckState::Unchecked);
connect(checkBox, &QCheckBox::stateChanged, this, &Updater::setAutomaticallyCheckForUpdates);
}
}
// Called when the user toggles automatically check for updates checkbox
void Updater::setAutomaticallyCheckForUpdates(int newState)
{
@autoreleasepool {
_updaterDelegate.updaterController.updater.automaticallyChecksForUpdates = (newState == Qt::CheckState::Checked);
}
}
Note that automaticallyChecksForUpdates is an updater setting that is backed by NSUserDefaults
, and shouldn’t be backed by additional defaults. Also note this property should only be set upon the user toggling the checkbox.
These instructions below are for adding settings in a Cocoa nib and assume you have a Settings nib with its File's Owner
being set to your Settings controller class (e.g, a NSWindowController
subclass). The controller class should have an updater
property set to your application’s SUUpdater
, which may be passed from your application’s delegate.
File's Owner
from the popup, and set the Model Key Path to updater.automaticallyChecksForUpdates
.File's Owner
from the popup, and set the Model Key Path to updater.updateCheckInterval
.File's Owner
from the popup, and set the Model Key Path to updater.automaticallyChecksForUpdates
.Follow directions similar to Enable automatic checking. to bind a check button to sendsSystemProfile
or automaticallyDownloadsUpdates
. See customization for details on the available keys.
These directions do not work for non-app bundles, as the updater you add to the nib will be the sharedUpdater
for the application bundle. To be able to bind to the updater for your bundle, you can add the following accessor to your settings controller (the owner of the nib):
- (SUUpdater *)updater {
return [SUUpdater updaterForBundle:[NSBundle bundleForClass:[self class]]];
}
Then just bind the controls to the File’s Owner, and start the Model Key Path with updater., e.g. updater.automaticallyChecksForUpdates.
macOS caches plist files in ~/Library/Preferences
, so don’t edit them directly. If you want to tweak these files for testing (e.g. change last update check date), use the defaults
command.