resolve TypeScript and Rust warnings (#6612)
* chore: fix warnings * fix: add missing scrollContainerRef dependencies to React hooks * fix: typo * fix: remove unsupported fetch option and enable AsyncIterable types - Removed `connectTimeout` from fetch init (not supported in RequestInit) - Updated tsconfig to target ES2018 * chore: refactor rename * fix(hooks): update dependency arrays for useThreadScrolling effects * Add type.d.ts to extend requestinit with connectionTimeout * remove commentd unused import
This commit is contained in:
parent
157ecacb20
commit
247db95bad
12
extensions/llamacpp-extension/src/type.d.ts
vendored
Normal file
12
extensions/llamacpp-extension/src/type.d.ts
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
export {}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface RequestInit {
|
||||||
|
/**
|
||||||
|
* Tauri HTTP plugin option for connection timeout in milliseconds.
|
||||||
|
*/
|
||||||
|
connectTimeout?: number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -126,13 +126,13 @@ mod windows_impl {
|
|||||||
pub iOSDisplayIndex: c_int,
|
pub iOSDisplayIndex: c_int,
|
||||||
}
|
}
|
||||||
|
|
||||||
type ADL_MAIN_MALLOC_CALLBACK = Option<unsafe extern "C" fn(i32) -> *mut c_void>;
|
type AdlMainMallocCallback = Option<unsafe extern "C" fn(i32) -> *mut c_void>;
|
||||||
type ADL_MAIN_CONTROL_CREATE = unsafe extern "C" fn(ADL_MAIN_MALLOC_CALLBACK, c_int) -> c_int;
|
type ADLMAINCONTROLCREATE = unsafe extern "C" fn(AdlMainMallocCallback, c_int) -> c_int;
|
||||||
type ADL_MAIN_CONTROL_DESTROY = unsafe extern "C" fn() -> c_int;
|
type ADLMAINCONTROLDESTROY = unsafe extern "C" fn() -> c_int;
|
||||||
type ADL_ADAPTER_NUMBEROFADAPTERS_GET = unsafe extern "C" fn(*mut c_int) -> c_int;
|
type AdlAdapterNumberofadaptersGet = unsafe extern "C" fn(*mut c_int) -> c_int;
|
||||||
type ADL_ADAPTER_ADAPTERINFO_GET = unsafe extern "C" fn(*mut AdapterInfo, c_int) -> c_int;
|
type AdlAdapterAdapterinfoGet = unsafe extern "C" fn(*mut AdapterInfo, c_int) -> c_int;
|
||||||
type ADL_ADAPTER_ACTIVE_GET = unsafe extern "C" fn(c_int, *mut c_int) -> c_int;
|
type AdlAdapterActiveGet = unsafe extern "C" fn(c_int, *mut c_int) -> c_int;
|
||||||
type ADL_GET_DEDICATED_VRAM_USAGE =
|
type AdlGetDedicatedVramUsage =
|
||||||
unsafe extern "C" fn(*mut c_void, c_int, *mut c_int) -> c_int;
|
unsafe extern "C" fn(*mut c_void, c_int, *mut c_int) -> c_int;
|
||||||
|
|
||||||
// === ADL Memory Allocator ===
|
// === ADL Memory Allocator ===
|
||||||
@ -144,24 +144,24 @@ mod windows_impl {
|
|||||||
unsafe {
|
unsafe {
|
||||||
let lib = Library::new("atiadlxx.dll").or_else(|_| Library::new("atiadlxy.dll"))?;
|
let lib = Library::new("atiadlxx.dll").or_else(|_| Library::new("atiadlxy.dll"))?;
|
||||||
|
|
||||||
let adl_main_control_create: Symbol<ADL_MAIN_CONTROL_CREATE> =
|
let adlmaincontrolcreate: Symbol<ADLMAINCONTROLCREATE> =
|
||||||
lib.get(b"ADL_Main_Control_Create")?;
|
lib.get(b"AdlMainControlCreate")?;
|
||||||
let adl_main_control_destroy: Symbol<ADL_MAIN_CONTROL_DESTROY> =
|
let adlmaincontroldestroy: Symbol<ADLMAINCONTROLDESTROY> =
|
||||||
lib.get(b"ADL_Main_Control_Destroy")?;
|
lib.get(b"AdlMainControlDestroy")?;
|
||||||
let adl_adapter_number_of_adapters_get: Symbol<ADL_ADAPTER_NUMBEROFADAPTERS_GET> =
|
let adl_adapter_number_of_adapters_get: Symbol<AdlAdapterNumberofadaptersGet> =
|
||||||
lib.get(b"ADL_Adapter_NumberOfAdapters_Get")?;
|
lib.get(b"AdlAdapterNumberofadaptersGet")?;
|
||||||
let adl_adapter_adapter_info_get: Symbol<ADL_ADAPTER_ADAPTERINFO_GET> =
|
let adl_adapter_adapter_info_get: Symbol<AdlAdapterAdapterinfoGet> =
|
||||||
lib.get(b"ADL_Adapter_AdapterInfo_Get")?;
|
lib.get(b"AdlAdapterAdapterinfoGet")?;
|
||||||
let adl_adapter_active_get: Symbol<ADL_ADAPTER_ACTIVE_GET> =
|
let AdlAdapterActiveGet: Symbol<AdlAdapterActiveGet> =
|
||||||
lib.get(b"ADL_Adapter_Active_Get")?;
|
lib.get(b"AdlAdapterActiveGet")?;
|
||||||
let adl_get_dedicated_vram_usage: Symbol<ADL_GET_DEDICATED_VRAM_USAGE> =
|
let AdlGetDedicatedVramUsage: Symbol<AdlGetDedicatedVramUsage> =
|
||||||
lib.get(b"ADL2_Adapter_DedicatedVRAMUsage_Get")?;
|
lib.get(b"ADL2_Adapter_DedicatedVRAMUsage_Get")?;
|
||||||
|
|
||||||
// TODO: try to put nullptr here. then we don't need direct libc dep
|
// TODO: try to put nullptr here. then we don't need direct libc dep
|
||||||
if adl_main_control_create(Some(adl_malloc), 1) != 0 {
|
if adlmaincontrolcreate(Some(adl_malloc), 1) != 0 {
|
||||||
return Err("ADL initialization error!".into());
|
return Err("ADL initialization error!".into());
|
||||||
}
|
}
|
||||||
// NOTE: after this call, we must call ADL_Main_Control_Destroy
|
// NOTE: after this call, we must call AdlMainControlDestroy
|
||||||
// whenver we encounter an error
|
// whenver we encounter an error
|
||||||
|
|
||||||
let mut num_adapters: c_int = 0;
|
let mut num_adapters: c_int = 0;
|
||||||
@ -184,11 +184,11 @@ mod windows_impl {
|
|||||||
|
|
||||||
for adapter in adapter_info.iter() {
|
for adapter in adapter_info.iter() {
|
||||||
let mut is_active = 0;
|
let mut is_active = 0;
|
||||||
adl_adapter_active_get(adapter.iAdapterIndex, &mut is_active);
|
AdlAdapterActiveGet(adapter.iAdapterIndex, &mut is_active);
|
||||||
|
|
||||||
if is_active != 0 {
|
if is_active != 0 {
|
||||||
let mut vram_mb = 0;
|
let mut vram_mb = 0;
|
||||||
let _ = adl_get_dedicated_vram_usage(
|
let _ = AdlGetDedicatedVramUsage(
|
||||||
ptr::null_mut(),
|
ptr::null_mut(),
|
||||||
adapter.iAdapterIndex,
|
adapter.iAdapterIndex,
|
||||||
&mut vram_mb,
|
&mut vram_mb,
|
||||||
@ -202,7 +202,7 @@ mod windows_impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
adl_main_control_destroy();
|
adlmaincontroldestroy();
|
||||||
|
|
||||||
Ok(vram_usages)
|
Ok(vram_usages)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::time::Duration;
|
|
||||||
use sysinfo::{Pid, System};
|
use sysinfo::{Pid, System};
|
||||||
use tauri::{Manager, Runtime, State};
|
use tauri::{Manager, Runtime, State};
|
||||||
use tokio::time::timeout;
|
|
||||||
|
|
||||||
use crate::state::{LlamacppState, SessionInfo};
|
use crate::state::{LlamacppState, SessionInfo};
|
||||||
use jan_utils::generate_random_port;
|
use jan_utils::generate_random_port;
|
||||||
@ -56,6 +54,8 @@ pub async fn get_random_available_port<R: Runtime>(
|
|||||||
pub async fn graceful_terminate_process(child: &mut tokio::process::Child) {
|
pub async fn graceful_terminate_process(child: &mut tokio::process::Child) {
|
||||||
use nix::sys::signal::{kill, Signal};
|
use nix::sys::signal::{kill, Signal};
|
||||||
use nix::unistd::Pid;
|
use nix::unistd::Pid;
|
||||||
|
use std::time::Duration;
|
||||||
|
use tokio::time::timeout;
|
||||||
|
|
||||||
if let Some(raw_pid) = child.id() {
|
if let Some(raw_pid) = child.id() {
|
||||||
let raw_pid = raw_pid as i32;
|
let raw_pid = raw_pid as i32;
|
||||||
|
|||||||
@ -81,7 +81,6 @@ pub fn setup_library_path(library_path: Option<&str>, command: &mut tokio::proce
|
|||||||
pub fn setup_windows_process_flags(command: &mut tokio::process::Command) {
|
pub fn setup_windows_process_flags(command: &mut tokio::process::Command) {
|
||||||
#[cfg(all(windows, target_arch = "x86_64"))]
|
#[cfg(all(windows, target_arch = "x86_64"))]
|
||||||
{
|
{
|
||||||
use std::os::windows::process::CommandExt;
|
|
||||||
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
|
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
|
||||||
const CREATE_NEW_PROCESS_GROUP: u32 = 0x0000_0200;
|
const CREATE_NEW_PROCESS_GROUP: u32 = 0x0000_0200;
|
||||||
command.creation_flags(CREATE_NO_WINDOW | CREATE_NEW_PROCESS_GROUP);
|
command.creation_flags(CREATE_NO_WINDOW | CREATE_NEW_PROCESS_GROUP);
|
||||||
|
|||||||
@ -54,7 +54,6 @@ export const useThreadScrolling = (
|
|||||||
}
|
}
|
||||||
}, [scrollContainerRef])
|
}, [scrollContainerRef])
|
||||||
|
|
||||||
|
|
||||||
const handleScroll = useCallback((e: Event) => {
|
const handleScroll = useCallback((e: Event) => {
|
||||||
const target = e.target as HTMLDivElement
|
const target = e.target as HTMLDivElement
|
||||||
const { scrollTop, scrollHeight, clientHeight } = target
|
const { scrollTop, scrollHeight, clientHeight } = target
|
||||||
@ -69,7 +68,7 @@ export const useThreadScrolling = (
|
|||||||
setIsAtBottom(isBottom)
|
setIsAtBottom(isBottom)
|
||||||
setHasScrollbar(hasScroll)
|
setHasScrollbar(hasScroll)
|
||||||
lastScrollTopRef.current = scrollTop
|
lastScrollTopRef.current = scrollTop
|
||||||
}, [streamingContent])
|
}, [streamingContent, setIsAtBottom, setHasScrollbar])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const scrollContainer = scrollContainerRef.current
|
const scrollContainer = scrollContainerRef.current
|
||||||
@ -90,7 +89,7 @@ export const useThreadScrolling = (
|
|||||||
|
|
||||||
setIsAtBottom(isBottom)
|
setIsAtBottom(isBottom)
|
||||||
setHasScrollbar(hasScroll)
|
setHasScrollbar(hasScroll)
|
||||||
}, [scrollContainerRef])
|
}, [scrollContainerRef, setIsAtBottom, setHasScrollbar])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!scrollContainerRef.current) return
|
if (!scrollContainerRef.current) return
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user