This repository has been archived by the owner on May 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/new_desktop_feature' into develop
- Loading branch information
Showing
18 changed files
with
349 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use tauri::{api, command, AppHandle, Manager}; | ||
|
||
#[command] | ||
pub fn open_link(app: AppHandle, url: String) { | ||
api::shell::open(&app.shell_scope(), url, None).unwrap(); | ||
} | ||
|
||
#[command] | ||
pub fn set_enabled_new_chat(app: AppHandle, enabled: bool) { | ||
let main_window = app.get_window("main").unwrap(); | ||
|
||
let menu_handle = main_window.menu_handle(); | ||
let tray_menu_handle = app.tray_handle(); | ||
|
||
let item = menu_handle.get_item("new_chat"); | ||
item.set_enabled(enabled).unwrap(); | ||
|
||
let tray_item = tray_menu_handle.get_item("new_chat"); | ||
tray_item.set_enabled(enabled).unwrap() | ||
} | ||
|
||
#[command] | ||
pub fn set_enabled_explore_tipi(app: AppHandle, enabled: bool) { | ||
let tray_menu_handle = app.tray_handle(); | ||
|
||
let tray_item = tray_menu_handle.get_item("explore_tipi"); | ||
tray_item.set_enabled(enabled).unwrap() | ||
} | ||
|
||
// #[command] | ||
// pub fn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,40 @@ | ||
// Prevents additional console window on Windows in release, DO NOT REMOVE!! | ||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] | ||
|
||
use tauri::Manager; | ||
mod cmd; | ||
mod menu; | ||
mod tray; | ||
|
||
fn main() { | ||
tauri::Builder::default() | ||
.run(tauri::generate_context!()) | ||
.expect("error while running tauri application"); | ||
let context = tauri::generate_context!(); | ||
|
||
tauri::Builder::default() | ||
.system_tray(tray::create()) | ||
.on_system_tray_event(tray::handler) | ||
.menu(menu::create_menu(&context)) | ||
.on_menu_event(menu::menu_handler) | ||
.invoke_handler(tauri::generate_handler![ | ||
cmd::open_link, | ||
cmd::set_enabled_new_chat, | ||
cmd::set_enabled_explore_tipi, | ||
]) | ||
.on_window_event(|event| match event.event() { | ||
tauri::WindowEvent::CloseRequested { api, .. } => { | ||
#[cfg(not(target_os = "macos"))] | ||
{ | ||
event.window().hide().unwrap(); | ||
} | ||
|
||
#[cfg(target_os = "macos")] | ||
{ | ||
tauri::AppHandle::hide(&event.window().app_handle()).unwrap(); | ||
} | ||
api.prevent_close(); | ||
} | ||
|
||
_ => {} | ||
}) | ||
.run(context) | ||
.expect("error while running tauri application"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use tauri::utils::assets::EmbeddedAssets; | ||
use tauri::{AboutMetadata, Context, CustomMenuItem, Menu, MenuItem, Submenu, WindowMenuEvent}; | ||
|
||
pub fn create_menu(context: &Context<EmbeddedAssets>) -> Menu { | ||
let app_name: &String = &context.package_info().name; | ||
|
||
let app_menu = Submenu::new( | ||
"", | ||
Menu::new() | ||
.add_native_item(MenuItem::About(app_name.into(), AboutMetadata::new())) | ||
.add_item(CustomMenuItem::new("settings", "Settings")) | ||
.add_native_item(MenuItem::Separator) | ||
.add_native_item(MenuItem::Hide) | ||
.add_native_item(MenuItem::HideOthers) | ||
.add_native_item(MenuItem::Quit), | ||
); | ||
|
||
let mut new_chat = CustomMenuItem::new("new_chat".to_string(), "Start new chat"); | ||
|
||
new_chat.enabled = false; | ||
|
||
let file_menu = Submenu::new("Chat", Menu::new().add_item(new_chat)); | ||
|
||
let edit_menu = Submenu::new( | ||
"Edit", | ||
Menu::new() | ||
.add_native_item(MenuItem::Undo) | ||
.add_native_item(MenuItem::Redo) | ||
.add_native_item(MenuItem::Separator) | ||
.add_native_item(MenuItem::Cut) | ||
.add_native_item(MenuItem::Copy) | ||
.add_native_item(MenuItem::Paste), | ||
); | ||
|
||
Menu::new() | ||
.add_submenu(app_menu) | ||
.add_submenu(file_menu) | ||
.add_submenu(edit_menu) | ||
} | ||
|
||
pub fn menu_handler(event: WindowMenuEvent) { | ||
let win = Some(event.window()); | ||
|
||
match event.menu_item_id() { | ||
"new_chat" => { | ||
win.unwrap().emit("open_new_chat", "").unwrap(); | ||
} | ||
|
||
_ => {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use tauri::{ | ||
AppHandle, CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, | ||
SystemTrayMenuItem, | ||
}; | ||
|
||
pub fn create() -> SystemTray { | ||
let mut new_chat = CustomMenuItem::new("new_chat".to_string(), "Start a new chat"); | ||
new_chat.enabled = false; | ||
|
||
let mut explore_tipis = CustomMenuItem::new("explore_tipi".to_string(), "Explore Tipi"); | ||
explore_tipis.enabled = false; | ||
|
||
let tray_menu: SystemTrayMenu = SystemTrayMenu::new() | ||
.add_item(new_chat) | ||
.add_item(explore_tipis) | ||
.add_item(CustomMenuItem::new("show".to_string(), "Open Tipis AI")) | ||
.add_native_item(SystemTrayMenuItem::Separator) | ||
.add_item(CustomMenuItem::new("quit".to_string(), "Quit")); | ||
|
||
SystemTray::new().with_menu(tray_menu) | ||
} | ||
|
||
pub fn handler(app: &AppHandle, event: SystemTrayEvent) { | ||
let window = app.get_window("main").unwrap(); | ||
match event { | ||
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() { | ||
"quit" => { | ||
std::process::exit(0); | ||
} | ||
"show" => { | ||
window.show().unwrap(); | ||
window.set_focus().unwrap(); | ||
} | ||
"new_chat" => { | ||
window.emit("open_new_chat", "").unwrap(); | ||
} | ||
"explore_tipi" => { | ||
window.emit("open_explore_tipi", "").unwrap(); | ||
} | ||
_ => {} | ||
}, | ||
_ => {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.