Files
vphone-cli/scripts/vphoned/vphoned_url.m
T
LakrandClaude Opus 4.6 df5d5449b5 feat: Add vphoned modules (accessibility, apps, clipboard, settings, url) and host-side menus
Split vphoned into modular ObjC files for accessibility, apps, clipboard,
settings, and URL handling. Add corresponding Swift menu extensions and
VPhoneControl commands. Format all files with clang-format and swift-format.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-03-10 23:35:41 +08:00

60 lines
1.7 KiB
Objective-C

/*
* vphoned_url — URL opening via LSApplicationWorkspace.
*
* Uses LSApplicationWorkspace (CoreServices) to open URLs.
* Does not require UIKit — works from daemon context.
*/
#import "vphoned_url.h"
#import "vphoned_protocol.h"
#include <objc/message.h>
@interface LSApplicationWorkspace : NSObject
+ (instancetype)defaultWorkspace;
- (BOOL)openURL:(NSURL *)url withOptions:(NSDictionary *)options;
- (BOOL)openSensitiveURL:(NSURL *)url withOptions:(NSDictionary *)options;
@end
NSDictionary *vp_handle_url_command(NSDictionary *msg) {
id reqId = msg[@"id"];
NSString *urlStr = msg[@"url"];
if (!urlStr) {
NSMutableDictionary *r = vp_make_response(@"err", reqId);
r[@"msg"] = @"missing url";
return r;
}
NSURL *url = [NSURL URLWithString:urlStr];
if (!url) {
NSMutableDictionary *r = vp_make_response(@"err", reqId);
r[@"msg"] = [NSString stringWithFormat:@"invalid url: %@", urlStr];
return r;
}
LSApplicationWorkspace *ws = [LSApplicationWorkspace defaultWorkspace];
BOOL ok = NO;
// Try openURL:withOptions: first
SEL openURLSel = sel_registerName("openURL:withOptions:");
if ([ws respondsToSelector:openURLSel]) {
ok = ((BOOL (*)(id, SEL, id, id))objc_msgSend)(ws, openURLSel, url, nil);
}
if (!ok) {
// Fallback: try openSensitiveURL:withOptions: (requires entitlement)
SEL sensitiveSel = sel_registerName("openSensitiveURL:withOptions:");
if ([ws respondsToSelector:sensitiveSel]) {
ok =
((BOOL (*)(id, SEL, id, id))objc_msgSend)(ws, sensitiveSel, url, nil);
}
}
NSMutableDictionary *r = vp_make_response(@"open_url", reqId);
r[@"ok"] = @(ok);
if (!ok) {
r[@"msg"] = [NSString stringWithFormat:@"failed to open url: %@", urlStr];
}
return r;
}