Fix Rust build errors: use setup hook for window icon, enable image-png feature
The previous approach used Builder::default_window_icon() which doesn't exist in Tauri 2.10. Instead, set the icon via window.set_icon() in the setup hook, and enable the "image-png" feature flag so Image::from_bytes can decode the PNG icon at runtime. Also change bundle identifier from "com.triple-c.app" to "com.triple-c.desktop" to avoid conflicting with the .app bundle extension on macOS. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -12,7 +12,7 @@ name = "triple-c"
|
|||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tauri = { version = "2", features = [] }
|
tauri = { version = "2", features = ["image-png"] }
|
||||||
tauri-plugin-store = "2"
|
tauri-plugin-store = "2"
|
||||||
tauri-plugin-dialog = "2"
|
tauri-plugin-dialog = "2"
|
||||||
tauri-plugin-opener = "2"
|
tauri-plugin-opener = "2"
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ pub fn run() {
|
|||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.default_window_icon(tauri::image::Image::from_bytes(include_bytes!("../icons/icon.png")).expect("Failed to load window icon"))
|
|
||||||
.plugin(tauri_plugin_store::Builder::default().build())
|
.plugin(tauri_plugin_store::Builder::default().build())
|
||||||
.plugin(tauri_plugin_dialog::init())
|
.plugin(tauri_plugin_dialog::init())
|
||||||
.plugin(tauri_plugin_opener::init())
|
.plugin(tauri_plugin_opener::init())
|
||||||
@@ -27,6 +26,14 @@ pub fn run() {
|
|||||||
settings_store: SettingsStore::new().expect("Failed to initialize settings store"),
|
settings_store: SettingsStore::new().expect("Failed to initialize settings store"),
|
||||||
exec_manager: ExecSessionManager::new(),
|
exec_manager: ExecSessionManager::new(),
|
||||||
})
|
})
|
||||||
|
.setup(|app| {
|
||||||
|
let icon = tauri::image::Image::from_bytes(include_bytes!("../icons/icon.png"))
|
||||||
|
.expect("Failed to load window icon");
|
||||||
|
if let Some(window) = app.get_webview_window("main") {
|
||||||
|
let _ = window.set_icon(icon);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
.on_window_event(|window, event| {
|
.on_window_event(|window, event| {
|
||||||
if let tauri::WindowEvent::CloseRequested { .. } = event {
|
if let tauri::WindowEvent::CloseRequested { .. } = event {
|
||||||
let state = window.state::<AppState>();
|
let state = window.state::<AppState>();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"$schema": "https://raw.githubusercontent.com/tauri-apps/tauri/dev/crates/tauri-cli/schema.json",
|
"$schema": "https://raw.githubusercontent.com/tauri-apps/tauri/dev/crates/tauri-cli/schema.json",
|
||||||
"productName": "Triple-C",
|
"productName": "Triple-C",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"identifier": "com.triple-c.app",
|
"identifier": "com.triple-c.desktop",
|
||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": "npm run dev",
|
"beforeDevCommand": "npm run dev",
|
||||||
"devUrl": "http://localhost:1420",
|
"devUrl": "http://localhost:1420",
|
||||||
|
|||||||
@@ -5,12 +5,17 @@ import { resolve } from "path";
|
|||||||
describe("Window icon configuration", () => {
|
describe("Window icon configuration", () => {
|
||||||
const srcTauriDir = resolve(__dirname, "../../src-tauri");
|
const srcTauriDir = resolve(__dirname, "../../src-tauri");
|
||||||
|
|
||||||
it("lib.rs sets default_window_icon using the app icon", () => {
|
it("lib.rs sets window icon using set_icon in setup hook", () => {
|
||||||
const libRs = readFileSync(resolve(srcTauriDir, "src/lib.rs"), "utf-8");
|
const libRs = readFileSync(resolve(srcTauriDir, "src/lib.rs"), "utf-8");
|
||||||
expect(libRs).toContain("default_window_icon");
|
expect(libRs).toContain("set_icon");
|
||||||
expect(libRs).toContain("icon.png");
|
expect(libRs).toContain("icon.png");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Cargo.toml enables image-png feature for icon loading", () => {
|
||||||
|
const cargoToml = readFileSync(resolve(srcTauriDir, "Cargo.toml"), "utf-8");
|
||||||
|
expect(cargoToml).toContain("image-png");
|
||||||
|
});
|
||||||
|
|
||||||
it("icon.png exists in the icons directory", () => {
|
it("icon.png exists in the icons directory", () => {
|
||||||
const iconPath = resolve(srcTauriDir, "icons/icon.png");
|
const iconPath = resolve(srcTauriDir, "icons/icon.png");
|
||||||
expect(existsSync(iconPath)).toBe(true);
|
expect(existsSync(iconPath)).toBe(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user