1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-21 18:53:29 +00:00

rework error handling & presentation

This commit is contained in:
John Harrington
2025-12-05 16:28:18 -07:00
parent 9ff43a66c5
commit 386cf03c42
11 changed files with 164 additions and 21 deletions

View File

@@ -14,7 +14,7 @@
}
- (NSString *)requestAccessToBrowserDir:(NSString *)browserName relativePath:(NSString *)relativePath {
if (!relativePath) {
return nil;
}
@@ -53,14 +53,7 @@
NSURL *localStatePath = [selectedURL URLByAppendingPathComponent:@"Local State"];
if (![[NSFileManager defaultManager] fileExistsAtPath:localStatePath.path]) {
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = @"Invalid Folder";
alert.informativeText = [NSString stringWithFormat:
@"The selected folder doesn't appear to be a valid %@ data directory. Please select the correct folder.",
browserName];
alert.alertStyle = NSAlertStyleWarning;
[alert runModal];
// Invalid directory selected caller will handle
return nil;
}

View File

@@ -0,0 +1,8 @@
#ifndef CHECK_BROWSER_INSTALLED_H
#define CHECK_BROWSER_INSTALLED_H
#import <Foundation/Foundation.h>
void checkBrowserInstalledCommand(void *context, NSDictionary *params);
#endif

View File

@@ -0,0 +1,29 @@
#import <Foundation/Foundation.h>
#import <CoreServices/CoreServices.h>
#import "../../interop.h"
#import "check_browser_installed.h"
void checkBrowserInstalledCommand(void* context, NSDictionary *params) {
NSString *bundleId = params[@"bundleId"];
if (!bundleId) {
return _return(context, _error(@"Missing required parameter: bundleId"));
}
CFURLRef appURL = NULL;
OSStatus status = LSFindApplicationForInfo(
kLSUnknownCreator,
(__bridge CFStringRef)bundleId,
NULL,
NULL,
&appURL
);
BOOL isInstalled = (status == noErr && appURL != NULL);
if (appURL != NULL) {
CFRelease(appURL);
}
_return(context, _success(@{@"isInstalled": @(isInstalled)}));
}

View File

@@ -15,7 +15,7 @@ void requestAccessCommand(void* context, NSDictionary *params) {
NSString *bookmarkData = [manager requestAccessToBrowserDir:browserName relativePath:relativePath];
if (bookmarkData == nil) {
return _return(context, _error(@"User denied access or selected an invalid browser directory"));
return _return(context, _error(@"browserAccessDenied"));
}
_return(context, _success(@{@"bookmark": bookmarkData}));

View File

@@ -3,6 +3,7 @@
#import "commands/has_stored_access.h"
#import "commands/start_access.h"
#import "commands/stop_access.h"
#import "commands/check_browser_installed.h"
#import "../interop.h"
#import "../utils.h"
#import "run_chromium_command.h"
@@ -19,6 +20,8 @@ void runChromiumCommand(void* context, NSDictionary *input) {
return startAccessCommand(context, params);
} else if ([command isEqual:@"stop_access"]) {
return stopAccessCommand(context, params);
} else if ([command isEqual:@"check_browser_installed"]) {
return checkBrowserInstalledCommand(context, params);
}
_return(context, _error([NSString stringWithFormat:@"Unknown command: %@", command]));