File tree Expand file tree Collapse file tree 10 files changed +188
-26
lines changed Expand file tree Collapse file tree 10 files changed +188
-26
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ tauri-plugin-autostart = "2"
5454tauri-plugin-clipboard-manager = { workspace = true }
5555tauri-plugin-deep-link = { workspace = true }
5656tauri-plugin-dialog = { workspace = true }
57- tauri-plugin-fs = " 2 "
57+ tauri-plugin-fs = { workspace = true , features = [ " watch " ] }
5858tauri-plugin-global-shortcut = " 2"
5959tauri-plugin-http = { workspace = true }
6060tauri-plugin-os = " 2"
Original file line number Diff line number Diff line change 6464 "identifier" : " fs:allow-exists" ,
6565 "allow" : [{ "path" : " /Applications/*" }]
6666 },
67+ {
68+ "identifier" : " fs:allow-watch" ,
69+ "allow" : [
70+ { "path" : " $APPDATA/*" },
71+ { "path" : " $APPDATA/**" }
72+ ]
73+ },
6774 {
6875 "identifier" : " fs:allow-write-file" ,
6976 "allow" : [
Original file line number Diff line number Diff line change 1+ import { commands as localLlmCommands } from "@hypr/plugin-local-llm" ;
12import { createFileRoute , Outlet , useRouter } from "@tanstack/react-router" ;
3+ import { appDataDir , join } from "@tauri-apps/api/path" ;
24import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow" ;
5+ import { watch } from "@tauri-apps/plugin-fs" ;
36import { useEffect , useState } from "react" ;
47
58import { IndividualizationModal } from "@/components/individualization-modal" ;
@@ -54,6 +57,7 @@ function Component() {
5457 < LeftSidebarProvider >
5558 < RightPanelProvider >
5659 < AudioPermissions />
60+ < RestartLlmServer />
5761 < MainWindowStateEventSupport />
5862 < SettingsProvider >
5963 < NewNoteProvider >
@@ -105,6 +109,31 @@ function Component() {
105109 ) ;
106110}
107111
112+ function RestartLlmServer ( ) {
113+ const watchLlm = async ( ) => {
114+ const path = await appDataDir ( ) ;
115+ const llmPath = await join ( path , "llm.gguf" ) ;
116+
117+ return watch ( llmPath , ( _event ) => {
118+ localLlmCommands . restartServer ( ) ;
119+ } , { delayMs : 1000 } ) ;
120+ } ;
121+
122+ useEffect ( ( ) => {
123+ let unwatch : ( ) => void ;
124+
125+ watchLlm ( ) . then ( ( f ) => {
126+ unwatch = f ;
127+ } ) ;
128+
129+ return ( ) => {
130+ unwatch ?.( ) ;
131+ } ;
132+ } , [ ] ) ;
133+
134+ return null ;
135+ }
136+
108137function AudioPermissions ( ) {
109138 useEffect ( ( ) => {
110139 listenerCommands . checkMicrophoneAccess ( ) . then ( ( isGranted ) => {
Original file line number Diff line number Diff line change @@ -27,6 +27,9 @@ async startServer() : Promise<string> {
2727} ,
2828async stopServer ( ) : Promise < null > {
2929 return await TAURI_INVOKE ( "plugin:local-llm|stop_server" ) ;
30+ } ,
31+ async restartServer ( ) : Promise < string > {
32+ return await TAURI_INVOKE ( "plugin:local-llm|restart_server" ) ;
3033}
3134}
3235
Original file line number Diff line number Diff line change @@ -50,3 +50,10 @@ pub async fn start_server<R: tauri::Runtime>(app: tauri::AppHandle<R>) -> Result
5050pub async fn stop_server < R : tauri:: Runtime > ( app : tauri:: AppHandle < R > ) -> Result < ( ) , String > {
5151 app. stop_server ( ) . await . map_err ( |e| e. to_string ( ) )
5252}
53+
54+ #[ tauri:: command]
55+ #[ specta:: specta]
56+ pub async fn restart_server < R : tauri:: Runtime > ( app : tauri:: AppHandle < R > ) -> Result < String , String > {
57+ app. stop_server ( ) . await . map_err ( |e| e. to_string ( ) ) ?;
58+ app. start_server ( ) . await . map_err ( |e| e. to_string ( ) )
59+ }
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ fn make_specta_builder<R: tauri::Runtime>() -> tauri_specta::Builder<R> {
4848 commands:: download_model:: <Wry >,
4949 commands:: start_server:: <Wry >,
5050 commands:: stop_server:: <Wry >,
51+ commands:: restart_server:: <Wry >,
5152 ] )
5253 . error_handling ( tauri_specta:: ErrorHandlingMode :: Throw )
5354}
@@ -58,9 +59,12 @@ pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
5859 tauri:: plugin:: Builder :: new ( PLUGIN_NAME )
5960 . invoke_handler ( specta_builder. invoke_handler ( ) )
6061 . setup ( |app, _api| {
61- let model_path = app. path ( ) . app_data_dir ( ) . unwrap ( ) . join ( "llm.gguf" ) ;
62- let state: SharedState = Arc :: new ( Mutex :: new ( State :: new ( model_path) ) ) ;
63- app. manage ( state) ;
62+ {
63+ let model_path = app. path ( ) . app_data_dir ( ) . unwrap ( ) . join ( "llm.gguf" ) ;
64+ let state: SharedState = Arc :: new ( Mutex :: new ( State :: new ( model_path) ) ) ;
65+ app. manage ( state) ;
66+ }
67+
6468 Ok ( ( ) )
6569 } )
6670 . build ( )
Original file line number Diff line number Diff line change @@ -22,20 +22,23 @@ async isModelDownloading(model: SupportedModel) : Promise<boolean> {
2222async downloadModel ( model : SupportedModel , channel : TAURI_CHANNEL < number > ) : Promise < null > {
2323 return await TAURI_INVOKE ( "plugin:local-stt|download_model" , { model, channel } ) ;
2424} ,
25- async startServer ( ) : Promise < string > {
26- return await TAURI_INVOKE ( "plugin:local-stt|start_server" ) ;
27- } ,
28- async stopServer ( ) : Promise < null > {
29- return await TAURI_INVOKE ( "plugin:local-stt|stop_server" ) ;
25+ async listSupportedModels ( ) : Promise < SupportedModel [ ] > {
26+ return await TAURI_INVOKE ( "plugin:local-stt|list_supported_models" ) ;
3027} ,
3128async getCurrentModel ( ) : Promise < SupportedModel > {
3229 return await TAURI_INVOKE ( "plugin:local-stt|get_current_model" ) ;
3330} ,
3431async setCurrentModel ( model : SupportedModel ) : Promise < null > {
3532 return await TAURI_INVOKE ( "plugin:local-stt|set_current_model" , { model } ) ;
3633} ,
37- async listSupportedModels ( ) : Promise < SupportedModel [ ] > {
38- return await TAURI_INVOKE ( "plugin:local-stt|list_supported_models" ) ;
34+ async startServer ( ) : Promise < string > {
35+ return await TAURI_INVOKE ( "plugin:local-stt|start_server" ) ;
36+ } ,
37+ async stopServer ( ) : Promise < null > {
38+ return await TAURI_INVOKE ( "plugin:local-stt|stop_server" ) ;
39+ } ,
40+ async restartServer ( ) : Promise < string > {
41+ return await TAURI_INVOKE ( "plugin:local-stt|restart_server" ) ;
3942}
4043}
4144
Original file line number Diff line number Diff line change @@ -54,18 +54,6 @@ pub async fn download_model<R: tauri::Runtime>(
5454 . map_err ( |e| e. to_string ( ) )
5555}
5656
57- #[ tauri:: command]
58- #[ specta:: specta]
59- pub async fn start_server < R : tauri:: Runtime > ( app : tauri:: AppHandle < R > ) -> Result < String , String > {
60- app. start_server ( ) . await . map_err ( |e| e. to_string ( ) )
61- }
62-
63- #[ tauri:: command]
64- #[ specta:: specta]
65- pub async fn stop_server < R : tauri:: Runtime > ( app : tauri:: AppHandle < R > ) -> Result < ( ) , String > {
66- app. stop_server ( ) . await . map_err ( |e| e. to_string ( ) )
67- }
68-
6957#[ tauri:: command]
7058#[ specta:: specta]
7159pub fn get_current_model < R : tauri:: Runtime > (
@@ -82,3 +70,22 @@ pub fn set_current_model<R: tauri::Runtime>(
8270) -> Result < ( ) , String > {
8371 app. set_current_model ( model) . map_err ( |e| e. to_string ( ) )
8472}
73+
74+ #[ tauri:: command]
75+ #[ specta:: specta]
76+ pub async fn start_server < R : tauri:: Runtime > ( app : tauri:: AppHandle < R > ) -> Result < String , String > {
77+ app. start_server ( ) . await . map_err ( |e| e. to_string ( ) )
78+ }
79+
80+ #[ tauri:: command]
81+ #[ specta:: specta]
82+ pub async fn stop_server < R : tauri:: Runtime > ( app : tauri:: AppHandle < R > ) -> Result < ( ) , String > {
83+ app. stop_server ( ) . await . map_err ( |e| e. to_string ( ) )
84+ }
85+
86+ #[ tauri:: command]
87+ #[ specta:: specta]
88+ pub async fn restart_server < R : tauri:: Runtime > ( app : tauri:: AppHandle < R > ) -> Result < String , String > {
89+ app. stop_server ( ) . await . map_err ( |e| e. to_string ( ) ) ?;
90+ app. start_server ( ) . await . map_err ( |e| e. to_string ( ) )
91+ }
Original file line number Diff line number Diff line change @@ -38,11 +38,12 @@ fn make_specta_builder<R: tauri::Runtime>() -> tauri_specta::Builder<R> {
3838 commands:: is_model_downloaded:: <Wry >,
3939 commands:: is_model_downloading:: <Wry >,
4040 commands:: download_model:: <Wry >,
41- commands:: start_server:: <Wry >,
42- commands:: stop_server:: <Wry >,
41+ commands:: list_supported_models,
4342 commands:: get_current_model:: <Wry >,
4443 commands:: set_current_model:: <Wry >,
45- commands:: list_supported_models,
44+ commands:: start_server:: <Wry >,
45+ commands:: stop_server:: <Wry >,
46+ commands:: restart_server:: <Wry >,
4647 ] )
4748 . events ( tauri_specta:: collect_events![
4849 events:: RecordedProcessingEvent
You can’t perform that action at this time.
0 commit comments