Skip to content

Instantly share code, notes, and snippets.

@ninetyeights
Created September 12, 2023 14:18
Show Gist options
  • Save ninetyeights/ddfbe532f5485b761dc5db122e26cfa9 to your computer and use it in GitHub Desktop.
Save ninetyeights/ddfbe532f5485b761dc5db122e26cfa9 to your computer and use it in GitHub Desktop.
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use tauri::{Manager, Window};
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}
fn main() {
tauri::Builder::default()
.setup(|app| {
let main_window = app.get_window("main").unwrap();
#[cfg(target_os = "macos")]
{
use cocoa::appkit::{NSMainMenuWindowLevel, NSWindow, NSWindowCollectionBehavior};
use cocoa::base::id;
let ns_win = main_window.ns_window().unwrap() as id;
unsafe {
ns_win.setLevel_(((NSMainMenuWindowLevel + 1) as u64).try_into().unwrap());
ns_win.setCollectionBehavior_(NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces);
// ns_win.setCollectionBehavior_(NSWindowCollectionBehavior::NSWindowCollectionBehaviorMoveToActiveSpace);
}
}
Ok(())
})
.invoke_handler(tauri::generate_handler![greet])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment