refactor: create profile in the currently selected group

This commit is contained in:
zhom
2025-08-07 04:15:31 +04:00
parent 9ba51cd4e3
commit 5fed6b7c3f
4 changed files with 41 additions and 47 deletions
+9 -3
View File
@@ -1337,8 +1337,9 @@ impl BrowserRunner {
} }
} }
#[allow(clippy::too_many_arguments)]
#[tauri::command] #[tauri::command]
pub async fn create_browser_profile( pub async fn create_browser_profile_with_group(
app_handle: tauri::AppHandle, app_handle: tauri::AppHandle,
name: String, name: String,
browser: String, browser: String,
@@ -1346,10 +1347,11 @@ pub async fn create_browser_profile(
release_type: String, release_type: String,
proxy_id: Option<String>, proxy_id: Option<String>,
camoufox_config: Option<CamoufoxConfig>, camoufox_config: Option<CamoufoxConfig>,
group_id: Option<String>,
) -> Result<BrowserProfile, String> { ) -> Result<BrowserProfile, String> {
let profile_manager = ProfileManager::instance(); let profile_manager = ProfileManager::instance();
profile_manager profile_manager
.create_profile( .create_profile_with_group(
&app_handle, &app_handle,
&name, &name,
&browser, &browser,
@@ -1357,6 +1359,7 @@ pub async fn create_browser_profile(
&release_type, &release_type,
proxy_id, proxy_id,
camoufox_config, camoufox_config,
group_id,
) )
.await .await
.map_err(|e| format!("Failed to create profile: {e}")) .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}")) .map_err(|e| format!("Failed to kill browser: {e}"))
} }
#[allow(clippy::too_many_arguments)]
#[tauri::command] #[tauri::command]
pub async fn create_browser_profile_new( pub async fn create_browser_profile_new(
app_handle: tauri::AppHandle, app_handle: tauri::AppHandle,
@@ -1654,10 +1658,11 @@ pub async fn create_browser_profile_new(
release_type: String, release_type: String,
proxy_id: Option<String>, proxy_id: Option<String>,
camoufox_config: Option<CamoufoxConfig>, camoufox_config: Option<CamoufoxConfig>,
group_id: Option<String>,
) -> Result<BrowserProfile, String> { ) -> Result<BrowserProfile, String> {
let browser_type = let browser_type =
BrowserType::from_str(&browser_str).map_err(|e| format!("Invalid browser type: {e}"))?; BrowserType::from_str(&browser_str).map_err(|e| format!("Invalid browser type: {e}"))?;
create_browser_profile( create_browser_profile_with_group(
app_handle, app_handle,
name, name,
browser_type.as_str().to_string(), browser_type.as_str().to_string(),
@@ -1665,6 +1670,7 @@ pub async fn create_browser_profile_new(
release_type, release_type,
proxy_id, proxy_id,
camoufox_config, camoufox_config,
group_id,
) )
.await .await
} }
-25
View File
@@ -34,31 +34,6 @@ impl ProfileManager {
path 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<String>,
camoufox_config: Option<CamoufoxConfig>,
) -> Result<BrowserProfile, Box<dyn std::error::Error>> {
self
.create_profile_with_group(
app_handle,
name,
browser,
version,
release_type,
proxy_id,
camoufox_config,
None,
)
.await
}
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub async fn create_profile_with_group( pub async fn create_profile_with_group(
&self, &self,
+27 -19
View File
@@ -389,6 +389,21 @@ export default function Home() {
[currentProfileForProxy, loadProfiles], [currentProfileForProxy, loadProfiles],
); );
const loadGroups = useCallback(async () => {
setGroupsLoading(true);
try {
const groupsWithCounts = await invoke<GroupWithCount[]>(
"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( const handleCreateProfile = useCallback(
async (profileData: { async (profileData: {
name: string; name: string;
@@ -397,6 +412,7 @@ export default function Home() {
releaseType: string; releaseType: string;
proxyId?: string; proxyId?: string;
camoufoxConfig?: CamoufoxConfig; camoufoxConfig?: CamoufoxConfig;
groupId?: string;
}) => { }) => {
setError(null); setError(null);
@@ -410,10 +426,14 @@ export default function Home() {
releaseType: profileData.releaseType, releaseType: profileData.releaseType,
proxyId: profileData.proxyId, proxyId: profileData.proxyId,
camoufoxConfig: profileData.camoufoxConfig, camoufoxConfig: profileData.camoufoxConfig,
groupId:
profileData.groupId ||
(selectedGroupId !== "default" ? selectedGroupId : undefined),
}, },
); );
await loadProfiles(); await loadProfiles();
await loadGroups();
// Trigger proxy data reload in the table // Trigger proxy data reload in the table
} catch (error) { } catch (error) {
setError( setError(
@@ -424,7 +444,7 @@ export default function Home() {
throw error; throw error;
} }
}, },
[loadProfiles], [loadProfiles, loadGroups, selectedGroupId],
); );
const [runningProfiles, setRunningProfiles] = useState<Set<string>>( const [runningProfiles, setRunningProfiles] = useState<Set<string>>(
@@ -524,8 +544,9 @@ export default function Home() {
// Give a small delay to ensure file system operations complete // Give a small delay to ensure file system operations complete
await new Promise((resolve) => setTimeout(resolve, 500)); 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 loadProfiles();
await loadGroups();
console.log("Profile deleted and profiles reloaded successfully"); console.log("Profile deleted and profiles reloaded successfully");
} catch (err: unknown) { } catch (err: unknown) {
@@ -534,7 +555,7 @@ export default function Home() {
setError(`Failed to delete profile: ${errorMessage}`); setError(`Failed to delete profile: ${errorMessage}`);
} }
}, },
[loadProfiles], [loadProfiles, loadGroups],
); );
const handleRenameProfile = useCallback( const handleRenameProfile = useCallback(
@@ -566,21 +587,6 @@ export default function Home() {
[loadProfiles], [loadProfiles],
); );
const loadGroups = useCallback(async () => {
setGroupsLoading(true);
try {
const groupsWithCounts = await invoke<GroupWithCount[]>(
"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( const handleDeleteSelectedProfiles = useCallback(
async (profileNames: string[]) => { async (profileNames: string[]) => {
setError(null); setError(null);
@@ -615,6 +621,7 @@ export default function Home() {
profileNames: selectedProfiles, profileNames: selectedProfiles,
}); });
await loadProfiles(); await loadProfiles();
await loadGroups();
setSelectedProfiles([]); setSelectedProfiles([]);
setShowBulkDeleteConfirmation(false); setShowBulkDeleteConfirmation(false);
} catch (error) { } catch (error) {
@@ -623,7 +630,7 @@ export default function Home() {
} finally { } finally {
setIsBulkDeleting(false); setIsBulkDeleting(false);
} }
}, [selectedProfiles, loadProfiles]); }, [selectedProfiles, loadProfiles, loadGroups]);
const handleBulkGroupAssignment = useCallback(() => { const handleBulkGroupAssignment = useCallback(() => {
if (selectedProfiles.length === 0) return; if (selectedProfiles.length === 0) return;
@@ -778,6 +785,7 @@ export default function Home() {
setCreateProfileDialogOpen(false); setCreateProfileDialogOpen(false);
}} }}
onCreateProfile={handleCreateProfile} onCreateProfile={handleCreateProfile}
selectedGroupId={selectedGroupId}
/> />
<SettingsDialog <SettingsDialog
+5
View File
@@ -48,7 +48,9 @@ interface CreateProfileDialogProps {
releaseType: string; releaseType: string;
proxyId?: string; proxyId?: string;
camoufoxConfig?: CamoufoxConfig; camoufoxConfig?: CamoufoxConfig;
groupId?: string;
}) => Promise<void>; }) => Promise<void>;
selectedGroupId?: string;
} }
interface BrowserOption { interface BrowserOption {
@@ -99,6 +101,7 @@ export function CreateProfileDialog({
isOpen, isOpen,
onClose, onClose,
onCreateProfile, onCreateProfile,
selectedGroupId,
}: CreateProfileDialogProps) { }: CreateProfileDialogProps) {
const [profileName, setProfileName] = useState(""); const [profileName, setProfileName] = useState("");
const [activeTab, setActiveTab] = useState("regular"); const [activeTab, setActiveTab] = useState("regular");
@@ -272,6 +275,7 @@ export function CreateProfileDialog({
version: bestVersion.version, version: bestVersion.version,
releaseType: bestVersion.releaseType, releaseType: bestVersion.releaseType,
proxyId: selectedProxyId, proxyId: selectedProxyId,
groupId: selectedGroupId !== "default" ? selectedGroupId : undefined,
}); });
} else { } else {
// Anti-detect tab - always use Camoufox with best available version // Anti-detect tab - always use Camoufox with best available version
@@ -295,6 +299,7 @@ export function CreateProfileDialog({
releaseType: bestCamoufoxVersion.releaseType, releaseType: bestCamoufoxVersion.releaseType,
proxyId: selectedProxyId, proxyId: selectedProxyId,
camoufoxConfig: finalCamoufoxConfig, camoufoxConfig: finalCamoufoxConfig,
groupId: selectedGroupId !== "default" ? selectedGroupId : undefined,
}); });
} }