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]
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<String>,
camoufox_config: Option<CamoufoxConfig>,
group_id: Option<String>,
) -> Result<BrowserProfile, String> {
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<String>,
camoufox_config: Option<CamoufoxConfig>,
group_id: Option<String>,
) -> Result<BrowserProfile, String> {
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
}
-25
View File
@@ -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<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)]
pub async fn create_profile_with_group(
&self,
+27 -19
View File
@@ -389,6 +389,21 @@ export default function Home() {
[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(
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<Set<string>>(
@@ -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<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(
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}
/>
<SettingsDialog
+5
View File
@@ -48,7 +48,9 @@ interface CreateProfileDialogProps {
releaseType: string;
proxyId?: string;
camoufoxConfig?: CamoufoxConfig;
groupId?: string;
}) => Promise<void>;
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,
});
}