#Errors with the example provided in tauri::window::Window docs

14 messages · Page 1 of 1 (latest)

tender canopy
#

I'm trying to implement the example provided at https://docs.rs/tauri/latest/tauri/window/struct.Window.html. Specifically the bit setting the background color of a macos window. There are three errors in the code:

#[cfg(target_os = "macos")]
unsafe {
  let () = msg_send![win.inner(), setPageZoom: 4.];
  let () = msg_send![win.controller(), removeAllUserScripts];
  let bg_color: cocoa::base::id = msg_send![class!(NSColor), colorWithDeviceRed:0.5 green:0.2 blue:0.4 alpha:1.];
  let () = msg_send![win.ns_window(), setBackgroundColor: bg_color];
}

win.inner() - no method inner found for struct Window
win.controller() - no method controller found for struct Window
msg_send![win.ns_window(), setBackgroundColor: bg_color]; - type Result<*mut c_void, tauri::Error> cannot be dereferenced

#

Ah, I forgot to enclose it in win.with_webview(|webview| {.

#

I was trying to call it directly on win, and not webview 😅

#

Question, this builds and runs just fine now. I can see page zoom working but the color doesn't seem to do anything. Do I need to do anything further?

spice cairn
#

probably the html itself having some color?

#

ah actually

#

the webview itself has a color too i think. so in that regard the example seems a bit useless

#

So there are (at least) 3 layers of color

  • window
  • webview
  • html/body
  • whatever elements you have that may have a bg color
tender canopy
#

I don't have any html color as I can set windows.transparent = false in tauri.conf.json (and it is in fact transparent) So it the webview that is in in the way?

spice cairn
#

I don't have any html color as I can set windows.transparent = false in tauri.conf.json
to confirm you don't have any html color, try adding some css like this * {background:transparent !important;}

windows.transparent = false requires privateMacOSApis to be true too. but since that's the layer you're trying to re-color this shouldn't matter here actually nvm, i think windows.transparent controls the window and the webview

tender canopy
#

I have html and body set to background-color: rgba(0,0,0,0);, and my window looks as follows so It seems to be working

#

This might be a fruitless endevour though. What I am ultimately trying to do it change the color of the window when simultaneously using apply_vibrancy, which requires window.transparent = true. Setting the color of the window might not have any effect here? In which case, if setting the window color achieves the same as just just changing my html color? then it doesn't matter

#

But I would still expect the window to change color when my html is transparent and I set it as shown above, without window transparency.

spice cairn
#

in which case, if setting the window color achieves the same as just just changing my html color? then it doesn't matter
the window color indeed almost never matters. Sometimes it does on Windows (the os) because the webview can be a bit slow to resize.

But I would still expect the window to change color when my html is transparent and I set it as shown above, without window transparency.
That indeed is weird, yeah. but i don't know enough about the macos apis to help here tbh