This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-09
Channels
- # announcements (2)
- # babashka (11)
- # beginners (9)
- # biff (7)
- # calva (20)
- # catalyst (1)
- # cider (8)
- # clerk (46)
- # clj-kondo (18)
- # clj-otel (2)
- # clojure-brasil (22)
- # clojure-europe (18)
- # clojure-gamedev (23)
- # clojure-italy (5)
- # clojure-nl (2)
- # clojure-norway (14)
- # clojure-uk (6)
- # clr (1)
- # datomic (13)
- # emacs (1)
- # hoplon (13)
- # hyperfiddle (53)
- # introduce-yourself (1)
- # java (23)
- # malli (7)
- # obb (35)
- # off-topic (31)
- # polylith (2)
- # portal (9)
- # rdf (15)
- # reitit (12)
- # releases (3)
- # ring (4)
- # shadow-cljs (6)
- # solo-full-stack (3)
Is it possible to launch a webview with obb? I have a Swift executable to do it but it would be nice to do it all in Clojure. This is what I have atm.
#!/usr/bin/env obb
(.import js/ObjC "Cocoa")
(.import js/ObjC "WebKit")
(doto (js/$.NSWindow.alloc.initWithContentRectStyleMaskBackingDefer
(js/$.NSMakeRect 0 0 800 600)
(bit-or js/$.NSTitledWindowMask
js/$.NSClosableWindowMask
js/$.NSResizableWindowMask
js/$.NSMiniaturizableWindowMask)
js/$.NSBackingStoreBuffered
false)
(.setTitle "Web View Test")
(.makeKeyAndOrderFront nil))
(let [webView (js/$.WKWebView.alloc.initWithFrame
(js/$.NSMakeRect 0 0 800 600))]
(.addSubview (.contentView (.keyWindow js/$.NSApp)) webView)
(.loadRequest webView (.NSURLRequest.requestWithURL (.NSURL.URLWithString ""))))
(doto js/$.NSApplication.sharedApplication
(.setActivationPolicy js/$.NSApplicationActivationPolicyRegular)
(.activateIgnoringOtherApps true))
(.run js/$.NSApp true)
I'm not an expert with the underlying platform but hopefully someone else will be able to help you. Perhaps @U050CT4HR
I haven't tried this in JS yet. I just found Obb last night and am exploring using it to handle the components of my app.
This seems to get "object is not a function":
(.addSubview (.contentView (.keyWindow js/$.NSApp)) webView)
Cool. yea I have been scoping the issue. I was just asking to see if it's known to work. I am assuming that it will.
This works:
(.import js/ObjC "Cocoa")
(.import js/ObjC "WebKit")
(doto (js/$.NSWindow.alloc.initWithContentRectStyleMaskBackingDefer
(js/$.NSMakeRect 0 0 800 600)
(bit-or js/$.NSTitledWindowMask
js/$.NSClosableWindowMask
js/$.NSResizableWindowMask
js/$.NSMiniaturizableWindowMask)
js/$.NSBackingStoreBuffered
false)
(.setTitle "Web View Test")
(.makeKeyAndOrderFront nil))
(let [webView (js/$.WKWebView.alloc.initWithFrame
(js/$.NSMakeRect 0 0 800 600))]
#_(.addSubview (.contentView (.keyWindow js/$.NSApp)) webView)
(.loadRequest webView (js/$.NSURLRequest.requestWithURL (js/$.NSURL.URLWithString ""))))
(doto js/$.NSApplication.sharedApplication
(.setActivationPolicy js/$.NSApplicationActivationPolicyRegular)
(.activateIgnoringOtherApps true))
(.run js/$.NSApp true)
I don't see a contentView thing on KeyWindow https://developer.apple.com/documentation/appkit/nsapplication/1428406-keywindow
It seems that js/$.NSApp
is empty
hmm I have these at the top
(.import js/ObjC "Cocoa")
(.import js/ObjC "WebKit")
oh I was using println
. noted use js/console.log
it is definitely to do with keywindow
It might be a timing issue. How do you sleep in obb?
a better question is how do you sleep in osascript, obb is just a layer on top of that
thats a good point
I think there is a way to check the window is loaded. I just wanted to do this as a quick test.
Well this doesn't break
#!/usr/bin/env obb
(.import js/ObjC "Cocoa")
(.import js/ObjC "WebKit")
(def window (let [newWindow (js/$.NSWindow.alloc.initWithContentRectStyleMaskBackingDefer
(js/$.NSMakeRect 0 0 800 600)
(bit-or js/$.NSTitledWindowMask
js/$.NSClosableWindowMask
js/$.NSResizableWindowMask
js/$.NSMiniaturizableWindowMask)
js/$.NSBackingStoreBuffered
false)]
(.setTitle newWindow "Web View Test")
(.makeKeyAndOrderFront newWindow nil)
newWindow
#_(js/delay 2)
#_(.addSubview (.contentView newWindow) webView)
#_(.loadRequest webView (js/$.NSURLRequest.requestWithURL (js/$.NSURL.URLWithString "")))))
(let [webview (js/$.WKWebView.alloc.initWithFrame
(js/$.NSMakeRect 0 0 800 600))]
(js/console.log "window" (.-contentView window))
(js/delay 2)
(.addSubview (.-contentView window) webview))
window
(doto js/$.NSApplication.sharedApplication
(.setActivationPolicy js/$.NSApplicationActivationPolicyRegular)
(.activateIgnoringOtherApps true))
(.run js/$.NSApp true)
But it looks like we want to use a delegate
I tried creating a delegate and adding it as a method. But it doesn't seem possible to use addMethod.
I also tried it as (js/$.addMethod delegate "windowDidLoad:" #(window-did-load))
I'm also trying #C03U8L2NXNC now for this:
npx squint webview.cljs && esbuild webview.mjs --bundle --outfile=webview.min.mjs && osascript -l JavaScript webview.min.mjs
if this is figured out and I can package it then I might be able to go without needing Swift which would be nice.
What would be the most elegant way to handle if possible using ZeroMQ in obb?
the underlying platform is called osascript, so you might just want to search for that
I am unsure whether what I am doing can be obtained. But I got very close! I shifted to launching the executable built with Swift. But then the application would hang. It might be because Webkit wants to run on the main thread.