-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(macos): add 'Check for Updates...' menu item #4666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(macos): add 'Check for Updates...' menu item #4666
Conversation
Fixes BasedHardware#4550 - Add 'Check for Updates...' menu item to app menu (MainMenu.xib) - Add IBAction in AppDelegate.swift to handle menu selection - Set up FlutterMethodChannel to communicate with Dart - Add method channel handler in DesktopUpdateService to trigger checkForUpdates() Users can now manually check for updates via Omi > Check for Updates... instead of waiting for the 3-hour background check interval.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request successfully adds a 'Check for Updates...' menu item to the macOS application, integrating it with the Flutter update service. The changes involve setting up a Flutter MethodChannel in both Swift and Dart to facilitate communication between the native macOS menu and the Flutter update logic. The XIB file is correctly updated to include the new menu item and wire it to the AppDelegate's action. The overall implementation is clear and follows standard patterns for Flutter-native integration.
| private func setupUpdateChannel() { | ||
| guard updateChannel == nil else { return } | ||
|
|
||
| if let mainWindow = NSApp.windows.first(where: { $0 is MainFlutterWindow }) as? MainFlutterWindow, | ||
| let flutterViewController = mainWindow.contentViewController as? FlutterViewController { | ||
| updateChannel = FlutterMethodChannel( | ||
| name: "com.omi/updates", | ||
| binaryMessenger: flutterViewController.engine.binaryMessenger | ||
| ) | ||
| NSLog("DEBUG: Created updates method channel") | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setupUpdateChannel method relies on finding the MainFlutterWindow and its FlutterViewController at the time it's called. While this might work in most cases, there's a potential for the updateChannel to remain nil if the main window or its content view controller isn't fully initialized or available when the menu item is first clicked. This could lead to the 'Check for Updates' functionality not working as expected. Consider initializing the updateChannel earlier in the app lifecycle, perhaps in applicationDidFinishLaunching, to ensure it's always ready when needed, or add more robust error handling/retries if the window is not found.
private func setupUpdateChannel() {
guard updateChannel == nil else { return }
// Attempt to get the FlutterViewController from the main window
// A more robust approach might involve storing a direct reference to the FlutterViewController
// during its initial setup, or ensuring this method is called only after the Flutter engine is fully ready.
if let mainWindow = NSApp.windows.first(where: { $0 is MainFlutterWindow }) as? MainFlutterWindow,
let flutterViewController = mainWindow.contentViewController as? FlutterViewController {
updateChannel = FlutterMethodChannel(
name: "com.omi/updates",
binaryMessenger: flutterViewController.engine.binaryMessenger
)
NSLog("DEBUG: Created updates method channel")
} else {
NSLog("ERROR: Could not find MainFlutterWindow or FlutterViewController to set up update channel.")
}
}
Summary
Adds a manual "Check for Updates..." menu item to the macOS app, allowing users to trigger update checks on demand.
Fixes #4550
Changes
Swift (AppDelegate.swift)
updateChannelfor Flutter communicationcheckForUpdates:IBAction triggered by menusetupUpdateChannel()to lazily initialize the method channelXIB (MainMenu.xib)
checkForUpdates:selector on AppDelegateDart (desktop_update_service.dart)
MethodChannel('com.omi/updates')_handleMethodCallto receive native calls and triggercheckForUpdates()Testing
Screenshots
(Menu item location: Omi > Check for Updates...)