Post

Replies

Boosts

Views

Activity

Reply to List does not move the view into focused element, when changing it with a keyboard
NSTableView from AppKit works just as expected, while List from SwiftUI does this weird "cropping". Here is the code for the NSTableView: import SwiftUI struct NSTableViewWrapper: NSViewRepresentable { class Coordinator: NSObject, NSTableViewDataSource, NSTableViewDelegate { var parent: NSTableViewWrapper init(parent: NSTableViewWrapper) { self.parent = parent } func numberOfRows(in tableView: NSTableView) -> Int { return parent.data.count } func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("Cell"), owner: nil) as? NSTextField ?? NSTextField(labelWithString: "") cell.identifier = NSUserInterfaceItemIdentifier("Cell") cell.stringValue = parent.data[row] return cell } } var data: [String] func makeCoordinator() -> Coordinator { return Coordinator(parent: self) } func makeNSView(context: Context) -> NSScrollView { let scrollView = NSScrollView() let tableView = NSTableView() let column = NSTableColumn(identifier: NSUserInterfaceItemIdentifier("Column")) column.title = "Items" column.width = 200 tableView.addTableColumn(column) tableView.delegate = context.coordinator tableView.dataSource = context.coordinator tableView.headerView = nil tableView.rowHeight = 50 tableView.style = .plain scrollView.documentView = tableView scrollView.hasVerticalScroller = true return scrollView } func updateNSView(_ nsView: NSScrollView, context: Context) { (nsView.documentView as? NSTableView)?.reloadData() } } struct ContentView: View { let items = 0..<40 let itemsSteing = Array(0..<40).map(\.description) var body: some View { NSTableViewWrapper(data: itemsSteing) } } func createAppWindow() { let window = NSWindow( contentRect: .zero, styleMask: [.titled], backing: .buffered, defer: false ) window.title = "NSTableView from AppKit" window.contentViewController = NSHostingController(rootView: ContentView()) window.setContentSize(NSSize(width: 759, height: 300)) window.center() window.makeKeyAndOrderFront(nil) } class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ notification: Notification) { createAppWindow() } } let delegate = AppDelegate() NSApplication.shared.delegate = delegate NSApplication.shared.run()
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’25
Reply to Safari App Extensions vs Safari Extensions
As i understand it – Safari Web Extension have more functionality, specifically it can utilize background and content scripts available in Google Chrome API: Background scripts: https://developer.chrome.com/docs/extensions/mv2/background-pages Content scripts: https://developer.chrome.com/docs/extensions/mv2/content-scripts
Topic: Safari & Web SubTopic: General Tags:
Mar ’25
Reply to Sending messages from Google Chrome extension to macOS app
I was able to set up the Native Messaging https://developer.chrome.com/docs/apps/nativeMessaging But there is a catch: In order for the messaging to work, i need to create a json here (referencing an executable intended to listen to messages from an extension): $HOME/Library/Application\ Support/Google/Chrome/NativeMessagingHosts. https://developer.chrome.com/docs/apps/nativeMessaging#native-messaging-host-location Unfortunately you can not bundle it with a Chrome plugin so it automatically gets added there. Basically the json looks like this: { "name": "com.kopyl.tabfidnder.nativehost", "description": "Tab Finder Chrome", "path": "/usr/local/bin/native_host.py", "type": "stdio", "allowed_origins": [ "chrome-extension://jcbclkhailmoenaeddooicbemefilmje/" ] } (for rapid prototyping i used Python, but eventually i guess it would be better to utilize an XPC service) Of course i could make a .pkg installer which would add that json config to the file system, but in terms of user experience i don't think it's optimal. And i doubt App Store will approve an application which requires external installations for it to work properly. I tried copying the json on macOS app launch, but with enabled App Sandboxing Entitlement, the path turns to this (and hence becomes invalid): $HOME/Library/Containers/kopyl.tab-finder-chrome-app/Data/Library/Application Support/Google/Chrome/NativeMessagingHosts/com.kopyl.tabfidnder.nativehost.json Without the App Sandboxing the macOS app can't be published to the App Store.
Topic: Safari & Web SubTopic: General Tags:
Mar ’25
Reply to ViewBridge to RemoteViewService Terminated (...)
I also get this error: ViewBridge to RemoteViewService Terminated: Error Domain=com.apple.ViewBridge Code=18 "(null)" UserInfo={com.apple.ViewBridge.error.hint=this process disconnected remote view controller -- benign unless unexpected, com.apple.ViewBridge.error.description=NSViewBridgeErrorCanceled}
Topic: UI Frameworks SubTopic: AppKit
Mar ’25
Reply to How to trigger Safari App Extension with a keyboard shortcut without a content script and Accessibility permissions?
I ended up using HotKey Example: import SwiftUI import HotKey struct ContentView: View { let hotKey = HotKey(key: .tab , modifiers: [.option]) var body: some View { VStack {} .onAppear { hotKey.keyDownHandler = buttonHandler } } func buttonHandler() { /* ... */ } } But I'm still curious in how it can send the shortcuts without Accessibility permission.
Topic: Safari & Web SubTopic: General Tags:
Feb ’25
Reply to How to trigger Safari App Extension with a keyboard shortcut without a content script and Accessibility permissions?
So far I figured out: You can trigger a shortcut if you have a Safari Web Extension from background.js by adding a shortcut to manifest.json "commands": { "open-main-app": { "suggested_key": { "default": "Alt+K" }, "description": "Open Main App" } } But you can't set option+tab as a shortcut. Tab Back Lite's manifest.json but it does not have a shortcut in it. It only has nativeMessaging permission and a background script.
Topic: Safari & Web SubTopic: General Tags:
Feb ’25