Post

Replies

Boosts

Views

Activity

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 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 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 How can I change the background color of a focused item of a NSTableView?
Here is a more simplified example of the app: 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 { 1 } func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { return NSTextField(labelWithString: "Item") } func tableView(_ tableView: NSTableView, rowActionsForRow row: Int, edge: NSTableView.RowActionEdge) -> [NSTableViewRowAction] { return [NSTableViewRowAction(style: .destructive, title: "Delete") { _, _ in }] } } func makeCoordinator() -> Coordinator { return Coordinator(parent: self) } func makeNSView(context: Context) -> NSScrollView { let scrollView = NSScrollView() let tableView = NSTableView() let column = NSTableColumn(identifier: NSUserInterfaceItemIdentifier("Column")) tableView.addTableColumn(column) tableView.delegate = context.coordinator tableView.dataSource = context.coordinator scrollView.documentView = tableView return scrollView } func updateNSView(_ nsView: NSScrollView, context: Context) { (nsView.documentView as? NSTableView)?.reloadData() } } struct ContentView: View { var body: some View { NSTableViewWrapper() } } And here is the demo:
Topic: UI Frameworks SubTopic: AppKit Tags:
Mar ’25
Reply to How can I change the background color of a focused item of a NSTableView?
There are two things which can be done: 1: Add another tableView method into the Coordinator which looks like this: func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? { return MyCustomRowView() } And MyCustomRowView would just have a isEmphasized property override: class MyCustomRowView: NSTableRowView { override var isEmphasized: Bool { set {} get { false } } } It can not give us any selection color we want, but it does change the color. To gray:
Topic: UI Frameworks SubTopic: AppKit Tags:
Mar ’25
Reply to How can I change the background color of a focused item of a NSTableView?
2: Replace property override with a method override in the MyCustomRowView from the code above: class MyCustomRowView: NSTableRowView { override func drawSelection(in dirtyRect: NSRect) { NSColor.brown.setFill() self.bounds.fill() } } It changes the background, but not the background we had initially. It completely ignores the interaction with the swipe action:
Topic: UI Frameworks SubTopic: AppKit Tags:
Mar ’25
Reply to How can I change the background color of a focused item of a NSTableView?
Another thing that I could do – is change AccentColor in project's Assets.xcassets. But it does not address the issue from this topic, because setting a color with 0.10% opacity gives an unexpected result :( Here i set the same brown color, but set the slider at the very left (1%) in the Assets.xcassets making the color barely visible: As you can see instead of giving me a barely brown color it gave me almost white...
Topic: UI Frameworks SubTopic: AppKit Tags:
Mar ’25