chore: update native apis

This commit is contained in:
Louis 2025-03-26 13:02:34 +07:00
parent 27fad2b0b2
commit e112583a87
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2
6 changed files with 55 additions and 11 deletions

View File

@ -28,7 +28,7 @@ const getJanDataFolderPath = (): Promise<string> => globalThis.core.api?.getJanD
* @returns {Promise<any>} A promise that resolves when the file explorer is opened. * @returns {Promise<any>} A promise that resolves when the file explorer is opened.
*/ */
const openFileExplorer: (path: string) => Promise<any> = (path) => const openFileExplorer: (path: string) => Promise<any> = (path) =>
globalThis.core.api?.openFileExplorer(path) globalThis.core.api?.openFileExplorer({ path })
/** /**
* Joins multiple paths together. * Joins multiple paths together.

View File

@ -4,7 +4,7 @@ use std::fs;
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
use tar::Archive; use tar::Archive;
use tauri::{process, AppHandle}; use tauri::AppHandle;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::path::PathBuf; use std::path::PathBuf;
@ -155,6 +155,48 @@ pub fn relaunch(app: AppHandle) {
app.restart() app.restart()
} }
#[tauri::command]
pub fn open_app_directory(app: AppHandle) {
let app_path = app.path().app_data_dir().unwrap();
if cfg!(target_os = "windows") {
std::process::Command::new("explorer")
.arg(app_path)
.spawn()
.expect("Failed to open app directory");
} else if cfg!(target_os = "macos") {
std::process::Command::new("open")
.arg(app_path)
.spawn()
.expect("Failed to open app directory");
} else {
std::process::Command::new("xdg-open")
.arg(app_path)
.spawn()
.expect("Failed to open app directory");
}
}
#[tauri::command]
pub fn open_file_explorer(app: AppHandle, path: String) {
let path = PathBuf::from(path);
if cfg!(target_os = "windows") {
std::process::Command::new("explorer")
.arg(path)
.spawn()
.expect("Failed to open file explorer");
} else if cfg!(target_os = "macos") {
std::process::Command::new("open")
.arg(path)
.spawn()
.expect("Failed to open file explorer");
} else {
std::process::Command::new("xdg-open")
.arg(path)
.spawn()
.expect("Failed to open file explorer");
}
}
#[tauri::command] #[tauri::command]
pub fn get_active_extensions(app: AppHandle) -> Vec<serde_json::Value> { pub fn get_active_extensions(app: AppHandle) -> Vec<serde_json::Value> {
let mut path = get_jan_extensions_path(app); let mut path = get_jan_extensions_path(app);

View File

@ -14,8 +14,7 @@ struct AppState {
#[command] #[command]
fn app_token(state: State<'_, AppState>) -> Option<String> { fn app_token(state: State<'_, AppState>) -> Option<String> {
// state.app_token.clone() state.app_token.clone()
None
} }
fn generate_app_token() -> String { fn generate_app_token() -> String {
@ -62,6 +61,8 @@ pub fn run() {
handlers::cmd::get_jan_data_folder_path, handlers::cmd::get_jan_data_folder_path,
handlers::cmd::get_jan_extensions_path, handlers::cmd::get_jan_extensions_path,
handlers::cmd::relaunch, handlers::cmd::relaunch,
handlers::cmd::open_app_directory,
handlers::cmd::open_file_explorer,
app_token, app_token,
]) ])
.manage(AppState { .manage(AppState {
@ -77,6 +78,7 @@ pub fn run() {
} }
// Setup sidecar // Setup sidecar
let app_state = app.state::<AppState>();
let sidecar_command = app.shell().sidecar("cortex-server").unwrap().args([ let sidecar_command = app.shell().sidecar("cortex-server").unwrap().args([
"--start-server", "--start-server",
"--port", "--port",
@ -96,8 +98,9 @@ pub fn run() {
.unwrap() .unwrap()
.to_str() .to_str()
.unwrap(), .unwrap(),
// "config", "config",
// "--api_keys", "--api_keys",
app_state.inner().app_token.as_deref().unwrap_or("")
]); ]);
let (mut rx, mut _child) = sidecar_command.spawn().expect("Failed to spawn sidecar"); let (mut rx, mut _child) = sidecar_command.spawn().expect("Failed to spawn sidecar");

View File

@ -13,9 +13,9 @@
"macOSPrivateApi": true, "macOSPrivateApi": true,
"windows": [ "windows": [
{ {
"title": "jan-app", "title": "Jan",
"width": 800, "width": 1000,
"height": 600, "height": 700,
"resizable": true, "resizable": true,
"fullscreen": false, "fullscreen": false,
"hiddenTitle": true, "hiddenTitle": true,

View File

@ -36,7 +36,7 @@ export const themeDataAtom = atomWithStorage<Theme | undefined>(
) )
export const reduceTransparentAtom = atomWithStorage<boolean>( export const reduceTransparentAtom = atomWithStorage<boolean>(
REDUCE_TRANSPARENT, REDUCE_TRANSPARENT,
false, true,
undefined, undefined,
{ getOnInit: true } { getOnInit: true }
) )

View File

@ -60,7 +60,6 @@ export default function AppearanceOptions() {
[ [
janDataFolderPath, janDataFolderPath,
reduceTransparent, reduceTransparent,
setReduceTransparent,
setSelectedIdTheme, setSelectedIdTheme,
setTheme, setTheme,
setThemeData, setThemeData,