Skip to content

Commit

Permalink
Able to toggle automatically check for updates and install updates fr…
Browse files Browse the repository at this point in the history
…om updates menu.
  • Loading branch information
chigkim committed Jan 23, 2024
1 parent 4f42876 commit d7b8202
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 42 deletions.
4 changes: 2 additions & 2 deletions VOCR.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = "2.0.0-beta.1";
MARKETING_VERSION = "2.0.0-beta.2";
PRODUCT_BUNDLE_IDENTIFIER = com.chikim.VOCR;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -458,7 +458,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = "2.0.0-beta.1";
MARKETING_VERSION = "2.0.0-beta.2";
PRODUCT_BUNDLE_IDENTIFIER = com.chikim.VOCR;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
4 changes: 3 additions & 1 deletion VOCR/AutoUpdateManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import UserNotifications
class AutoUpdateManager: NSObject, SPUUpdaterDelegate, SPUStandardUserDriverDelegate, UNUserNotificationCenterDelegate {

static let shared = AutoUpdateManager()
private var updaterController: SPUStandardUpdaterController?
var updaterController: SPUStandardUpdaterController?
private let UPDATE_NOTIFICATION_IDENTIFIER = "VOCRUpdateCheck"
var supportsGentleScheduledUpdateReminders: Bool {
return true
Expand All @@ -36,9 +36,11 @@ class AutoUpdateManager: NSObject, SPUUpdaterDelegate, SPUStandardUserDriverDele
func allowedChannels(for updater: SPUUpdater) -> Set<String> {
if Settings.preRelease {
log("Download pre-release.")
updater.updateCheckInterval = 3600
return Set(["pre"])
} else {
log("No pre-release.")
updater.updateCheckInterval = 3600*24
return Set()
}
}
Expand Down
54 changes: 26 additions & 28 deletions VOCR/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SUScheduledCheckInterval</key>
<integer>3600</integer>
<key>NSUserNotificationAlertStyle</key>
<string>alert</string>
<key>SUFeedURL</key>
<string>https://chigkim.github.io/VOCR/appcast.xml</string>
<key>SUPublicEDKey</key>
<string>mag38x5Zl6J5oFFwEeO4MfVY+4jJqEsDZPL6nHmbPg8=</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>Image files</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>public.image</string>
</array>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIconFile</key>
Expand All @@ -39,6 +41,11 @@
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSAppleEventsUsageDescription</key>
<string>Speak announcements and take Screenshot under VoiceOver cursor</string>
<key>NSHumanReadableCopyright</key>
Expand All @@ -51,20 +58,11 @@
<true/>
<key>NSSupportsSuddenTermination</key>
<true/>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>Image files</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>public.image</string>
</array>
</dict>
</array>
<key>NSUserNotificationAlertStyle</key>
<string>alert</string>
<key>SUFeedURL</key>
<string>https://chigkim.github.io/VOCR/appcast.xml</string>
<key>SUPublicEDKey</key>
<string>mag38x5Zl6J5oFFwEeO4MfVY+4jJqEsDZPL6nHmbPg8=</string>
</dict>
</plist>
52 changes: 41 additions & 11 deletions VOCR/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ enum Settings {
("Move Mouse", #selector(MenuHandler.toggleSetting(_:)), moveMouse),
("Launch on Login", #selector(MenuHandler.toggleLaunch(_:)), launchOnBoot),
("Log", #selector(MenuHandler.toggleLaunch(_:)), writeLog),
("Download Pre-release", #selector(MenuHandler.toggleLaunch(_:)), preRelease)
]
}

Expand Down Expand Up @@ -109,7 +108,7 @@ enum Settings {
let settingsMenuItem = NSMenuItem(title: "Settings", action: nil, keyEquivalent: "")
settingsMenuItem.submenu = settingsMenu
menu.addItem(settingsMenuItem)

if Navigation.cgImage != nil {
let saveScreenshotMenuItem = NSMenuItem(title: "Save Screenschot", action: #selector(target.saveScreenShot(_:)), keyEquivalent: "s")
saveScreenshotMenuItem.target = target
Expand All @@ -121,15 +120,38 @@ enum Settings {
saveMenuItem.target = target
menu.addItem(saveMenuItem)
}

let checkForUpdatesItem = NSMenuItem(title: "Check for Updates", action: #selector(target.checkForUpdates), keyEquivalent: "")
checkForUpdatesItem.target = target
menu.addItem(checkForUpdatesItem)


let updateMenu = NSMenu()
let aboutMenuItem = NSMenuItem(title: "About...", action: #selector(target.displayAboutWindow(_:)), keyEquivalent: "")
aboutMenuItem.target = target
menu.addItem(aboutMenuItem)

updateMenu.addItem(aboutMenuItem)

let checkForUpdatesItem = NSMenuItem(title: "Check for Updates", action: #selector(target.checkForUpdates), keyEquivalent: "")
checkForUpdatesItem.target = target
updateMenu.addItem(checkForUpdatesItem)

let autoCheckItem = NSMenuItem(title: "Automatically Chek for Updates", action: #selector(target.toggleSetting(_:)), keyEquivalent: "")
autoCheckItem.target = target
updateMenu.addItem(autoCheckItem)

let autoUpdateItem = NSMenuItem(title: "Automatically Install Updates", action: #selector(target.toggleSetting(_:)), keyEquivalent: "")
autoUpdateItem.target = target
updateMenu.addItem(autoUpdateItem)

if let updater = AutoUpdateManager.shared.updaterController?.updater {
autoCheckItem.state = (updater.automaticallyChecksForUpdates) ? .on : .off
autoUpdateItem.state = (updater.automaticallyDownloadsUpdates) ? .on : .off
}

let preReleaseItem = NSMenuItem(title: "Download Pre-release", action: #selector(target.toggleSetting(_:)), keyEquivalent: "")
preReleaseItem.target = target
updateMenu.addItem(preReleaseItem)
preReleaseItem.state = (Settings.preRelease) ? .on : .off

let updateMenuItem = NSMenuItem(title: "Updates", action: nil, keyEquivalent: "")
updateMenuItem.submenu = updateMenu
menu.addItem(updateMenuItem)

if Shortcuts.navigationActive {
let dismissMenuItem = NSMenuItem(title: "Dismiss Menu", action: #selector(target.dismiss(_:)), keyEquivalent: "z")
dismissMenuItem.target = target
Expand Down Expand Up @@ -265,8 +287,6 @@ class MenuHandler: NSObject {
Settings.positionReset = sender.state == .on
case "Positional Audio":
Settings.positionalAudio = sender.state == .on
case "Download Pre-release":
Settings.preRelease = sender.state == .on
case "Use Last Prompt":
Settings.useLastPrompt = sender.state == .on
case "Move Mouse":
Expand All @@ -275,6 +295,16 @@ class MenuHandler: NSObject {
Settings.launchOnBoot = sender.state == .on
case "Log":
Settings.writeLog = sender.state == .on
case "Download Pre-release":
Settings.preRelease = sender.state == .on
case "Automatically Chek for Updates":
if let updater = AutoUpdateManager.shared.updaterController?.updater {
updater.automaticallyChecksForUpdates = sender.state == .on
}
case "Automatically Install Updates":
if let updater = AutoUpdateManager.shared.updaterController?.updater {
updater.automaticallyDownloadsUpdates = sender.state == .on
}
default: break
}

Expand Down

0 comments on commit d7b8202

Please sign in to comment.