From 5fed6b7c3fad2c4121548152012bb5066d9dd254 Mon Sep 17 00:00:00 2001 From: zhom <2717306+zhom@users.noreply.github.com> Date: Thu, 7 Aug 2025 04:15:31 +0400 Subject: [PATCH] refactor: create profile in the currently selected group --- src-tauri/src/browser_runner.rs | 12 +++++-- src-tauri/src/profile/manager.rs | 25 ------------- src/app/page.tsx | 46 ++++++++++++++---------- src/components/create-profile-dialog.tsx | 5 +++ 4 files changed, 41 insertions(+), 47 deletions(-) diff --git a/src-tauri/src/browser_runner.rs b/src-tauri/src/browser_runner.rs index 2f05c36..2374036 100644 --- a/src-tauri/src/browser_runner.rs +++ b/src-tauri/src/browser_runner.rs @@ -1337,8 +1337,9 @@ impl BrowserRunner { } } +#[allow(clippy::too_many_arguments)] #[tauri::command] -pub async fn create_browser_profile( +pub async fn create_browser_profile_with_group( app_handle: tauri::AppHandle, name: String, browser: String, @@ -1346,10 +1347,11 @@ pub async fn create_browser_profile( release_type: String, proxy_id: Option, camoufox_config: Option, + group_id: Option, ) -> Result { let profile_manager = ProfileManager::instance(); profile_manager - .create_profile( + .create_profile_with_group( &app_handle, &name, &browser, @@ -1357,6 +1359,7 @@ pub async fn create_browser_profile( &release_type, proxy_id, camoufox_config, + group_id, ) .await .map_err(|e| format!("Failed to create profile: {e}")) @@ -1645,6 +1648,7 @@ pub async fn kill_browser_profile( .map_err(|e| format!("Failed to kill browser: {e}")) } +#[allow(clippy::too_many_arguments)] #[tauri::command] pub async fn create_browser_profile_new( app_handle: tauri::AppHandle, @@ -1654,10 +1658,11 @@ pub async fn create_browser_profile_new( release_type: String, proxy_id: Option, camoufox_config: Option, + group_id: Option, ) -> Result { let browser_type = BrowserType::from_str(&browser_str).map_err(|e| format!("Invalid browser type: {e}"))?; - create_browser_profile( + create_browser_profile_with_group( app_handle, name, browser_type.as_str().to_string(), @@ -1665,6 +1670,7 @@ pub async fn create_browser_profile_new( release_type, proxy_id, camoufox_config, + group_id, ) .await } diff --git a/src-tauri/src/profile/manager.rs b/src-tauri/src/profile/manager.rs index 3237ce4..9b332f9 100644 --- a/src-tauri/src/profile/manager.rs +++ b/src-tauri/src/profile/manager.rs @@ -34,31 +34,6 @@ impl ProfileManager { path } - #[allow(clippy::too_many_arguments)] - pub async fn create_profile( - &self, - app_handle: &tauri::AppHandle, - name: &str, - browser: &str, - version: &str, - release_type: &str, - proxy_id: Option, - camoufox_config: Option, - ) -> Result> { - self - .create_profile_with_group( - app_handle, - name, - browser, - version, - release_type, - proxy_id, - camoufox_config, - None, - ) - .await - } - #[allow(clippy::too_many_arguments)] pub async fn create_profile_with_group( &self, diff --git a/src/app/page.tsx b/src/app/page.tsx index 983c0ff..11ee724 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -389,6 +389,21 @@ export default function Home() { [currentProfileForProxy, loadProfiles], ); + const loadGroups = useCallback(async () => { + setGroupsLoading(true); + try { + const groupsWithCounts = await invoke( + "get_groups_with_profile_counts", + ); + setGroups(groupsWithCounts); + } catch (err) { + console.error("Failed to load groups with counts:", err); + setGroups([]); + } finally { + setGroupsLoading(false); + } + }, []); + const handleCreateProfile = useCallback( async (profileData: { name: string; @@ -397,6 +412,7 @@ export default function Home() { releaseType: string; proxyId?: string; camoufoxConfig?: CamoufoxConfig; + groupId?: string; }) => { setError(null); @@ -410,10 +426,14 @@ export default function Home() { releaseType: profileData.releaseType, proxyId: profileData.proxyId, camoufoxConfig: profileData.camoufoxConfig, + groupId: + profileData.groupId || + (selectedGroupId !== "default" ? selectedGroupId : undefined), }, ); await loadProfiles(); + await loadGroups(); // Trigger proxy data reload in the table } catch (error) { setError( @@ -424,7 +444,7 @@ export default function Home() { throw error; } }, - [loadProfiles], + [loadProfiles, loadGroups, selectedGroupId], ); const [runningProfiles, setRunningProfiles] = useState>( @@ -524,8 +544,9 @@ export default function Home() { // Give a small delay to ensure file system operations complete await new Promise((resolve) => setTimeout(resolve, 500)); - // Reload profiles to ensure UI is updated + // Reload profiles and groups to ensure UI is updated await loadProfiles(); + await loadGroups(); console.log("Profile deleted and profiles reloaded successfully"); } catch (err: unknown) { @@ -534,7 +555,7 @@ export default function Home() { setError(`Failed to delete profile: ${errorMessage}`); } }, - [loadProfiles], + [loadProfiles, loadGroups], ); const handleRenameProfile = useCallback( @@ -566,21 +587,6 @@ export default function Home() { [loadProfiles], ); - const loadGroups = useCallback(async () => { - setGroupsLoading(true); - try { - const groupsWithCounts = await invoke( - "get_groups_with_profile_counts", - ); - setGroups(groupsWithCounts); - } catch (err) { - console.error("Failed to load groups with counts:", err); - setGroups([]); - } finally { - setGroupsLoading(false); - } - }, []); - const handleDeleteSelectedProfiles = useCallback( async (profileNames: string[]) => { setError(null); @@ -615,6 +621,7 @@ export default function Home() { profileNames: selectedProfiles, }); await loadProfiles(); + await loadGroups(); setSelectedProfiles([]); setShowBulkDeleteConfirmation(false); } catch (error) { @@ -623,7 +630,7 @@ export default function Home() { } finally { setIsBulkDeleting(false); } - }, [selectedProfiles, loadProfiles]); + }, [selectedProfiles, loadProfiles, loadGroups]); const handleBulkGroupAssignment = useCallback(() => { if (selectedProfiles.length === 0) return; @@ -778,6 +785,7 @@ export default function Home() { setCreateProfileDialogOpen(false); }} onCreateProfile={handleCreateProfile} + selectedGroupId={selectedGroupId} /> Promise; + selectedGroupId?: string; } interface BrowserOption { @@ -99,6 +101,7 @@ export function CreateProfileDialog({ isOpen, onClose, onCreateProfile, + selectedGroupId, }: CreateProfileDialogProps) { const [profileName, setProfileName] = useState(""); const [activeTab, setActiveTab] = useState("regular"); @@ -272,6 +275,7 @@ export function CreateProfileDialog({ version: bestVersion.version, releaseType: bestVersion.releaseType, proxyId: selectedProxyId, + groupId: selectedGroupId !== "default" ? selectedGroupId : undefined, }); } else { // Anti-detect tab - always use Camoufox with best available version @@ -295,6 +299,7 @@ export function CreateProfileDialog({ releaseType: bestCamoufoxVersion.releaseType, proxyId: selectedProxyId, camoufoxConfig: finalCamoufoxConfig, + groupId: selectedGroupId !== "default" ? selectedGroupId : undefined, }); }