diff --git a/package.json b/package.json index 31653cb..f8dde2b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "bing-chat", "private": true, - "version": "1.0.0", + "version": "0.1.1", "type": "module", "scripts": { "dev": "vite", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 2bcf93f..ea30c6e 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -100,7 +100,7 @@ checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" [[package]] name = "bing-chat" -version = "1.0.0" +version = "0.1.1" dependencies = [ "serde", "serde_json", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 121c15a..4ddbf38 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "bing-chat" -version = "1.0.0" +version = "0.1.1" description = "A Tauri App" -authors = ["you"] +authors = ["Aron Pavel"] license = "" repository = "" edition = "2021" diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 32f07a6..1612321 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,11 +1,66 @@ // Prevents additional console window on Windows in release, DO NOT REMOVE!! #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] +use std::collections::HashMap; +use tauri::{CustomMenuItem, Menu, MenuItem, Submenu, WindowMenuEvent}; + +fn switch_content(event: WindowMenuEvent, from: &str, to: &str) { + let page_links: HashMap<&str, &str> = [ + ("chat", "search?q=Bing+AI&showconv=1"), + ("image", "images/create"), + ].iter().cloned().collect(); + + let main_window = event.window(); + let menu_handle = main_window.menu_handle(); + + let from_item = menu_handle.get_item(from); + let to_item = menu_handle.get_item(to); + + to_item.set_enabled(false).unwrap(); + main_window.eval(&format!("window.location.replace('https://www.bing.com/{}')", page_links[to])).unwrap(); + + from_item.set_selected(false).unwrap(); + to_item.set_selected(true).unwrap(); + from_item.set_enabled(true).unwrap(); +} + fn main() { + let chat = CustomMenuItem::new("chat".to_string(), "Chat").selected().disabled(); + let image = CustomMenuItem::new("image".to_string(), "Image Generator"); + let quit = CustomMenuItem::new("quit".to_string(), "Quit"); + + let submenu = Submenu::new("File", Menu::new().add_item(quit)); + let window_submenu = Submenu::new("Window", + Menu::new() + .add_item(chat) + .add_item(image) + ); + + let menu = Menu::new() + .add_native_item(MenuItem::Copy) + .add_item(CustomMenuItem::new("hide", "Hide")) + .add_submenu(submenu) + .add_submenu(window_submenu); + tauri::Builder::default() .setup(|_| { Ok(()) }) + .menu(menu) + .on_menu_event(|event| { + match event.menu_item_id() { + "quit" => { + std::process::exit(0); + } + "chat" => { + switch_content(event, "image", "chat"); + } + "image" => { + switch_content(event, "chat", "image"); + } + _ => {} + } + }) .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index fbd9182..25f964e 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "BingChat", - "version": "1.0.0" + "version": "0.1.1" }, "tauri": { "allowlist": {