Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
Merge branch 'feat/new_desktop_feature' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
AruSeito committed May 7, 2024
2 parents 274699a + 5a7266d commit 74aa434
Show file tree
Hide file tree
Showing 18 changed files with 349 additions and 104 deletions.
4 changes: 2 additions & 2 deletions apps/agent/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "agent",
"private": true,
"version": "0.0.0",
"version": "0.1.2",
"type": "module",
"scripts": {
"dev": "vite --force",
Expand Down Expand Up @@ -42,7 +42,6 @@
"@illa-public/illa-net": "workspace:^",
"@illa-public/illa-storage": "workspace:^",
"@illa-public/illa-web-socket": "workspace:^",
"@illa-public/invite-modal": "workspace:^",
"@illa-public/layout-auto-change": "workspace:^",
"@illa-public/market-share": "workspace:^",
"@illa-public/new-invite-modal": "workspace:^",
Expand All @@ -56,6 +55,7 @@
"@illa-public/user-data": "workspace:^",
"@illa-public/user-role-utils": "workspace:^",
"@illa-public/utils": "workspace:^",
"@illa-public/cross-platform-utils": "workspace:^",
"@mui/material": "^5.15.3",
"@mui/x-data-grid-premium": "^6.19.6",
"@reduxjs/toolkit": "^2.2.1",
Expand Down
76 changes: 76 additions & 0 deletions apps/agent/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/agent/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tauri-build = { version = "1.5.1", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.6.1", features = [ "updater", "system-tray"] }
tauri = { version = "1.6.1", features = [ "shell-open", "updater", "system-tray"] }

[features]
# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled.
Expand Down
31 changes: 31 additions & 0 deletions apps/agent/src-tauri/src/cmd.rs
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
38 changes: 35 additions & 3 deletions apps/agent/src-tauri/src/main.rs
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");
}
51 changes: 51 additions & 0 deletions apps/agent/src-tauri/src/menu.rs
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();
}

_ => {}
}
}
44 changes: 44 additions & 0 deletions apps/agent/src-tauri/src/tray.rs
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();
}
_ => {}
},
_ => {}
}
}
9 changes: 6 additions & 3 deletions apps/agent/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"package": {
"productName": "Tipis",
"version": "0.1.2"
"version": "../package.json"
},
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
"build": {
Expand All @@ -16,7 +16,10 @@
"iconAsTemplate": true
},
"allowlist": {
"all": false
"all": false,
"shell": {
"open": true
}
},
"bundle": {
"active": true,
Expand Down Expand Up @@ -72,7 +75,7 @@
"height": 720,
"minWidth": 1280,
"minHeight": 720,
"resizable": false,
"resizable": true,
"fullscreen": false
}
]
Expand Down
Loading

0 comments on commit 74aa434

Please sign in to comment.