Skip to content

Commit b5d7a0f

Browse files
committed
feat: add functionality to create new windows in the Tauri application
- Implemented a new command to create a new window in the Tauri app, allowing users to open multiple instances. - Added a button in the AppHeader component to trigger the new window creation. - Updated capability configurations to support the new window functionality.
1 parent cc5fa89 commit b5d7a0f

File tree

5 files changed

+54
-8
lines changed

5 files changed

+54
-8
lines changed

src-tauri/capabilities/default.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
"identifier": "default",
44
"description": "Capability for the main window",
55
"windows": [
6-
"main"
6+
"main",
7+
"main-*"
78
],
89
"permissions": [
910
"core:default",
11+
"core:event:default",
12+
"core:event:allow-listen",
13+
"core:event:allow-emit",
1014
"core:window:allow-start-dragging",
1115
"core:window:allow-set-title",
16+
"core:webview:default",
1217
"dialog:default",
1318
"dialog:allow-ask",
1419
"dialog:allow-message",

src-tauri/capabilities/desktop.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"linux"
77
],
88
"windows": [
9-
"main"
9+
"main",
10+
"main-*"
1011
],
1112
"permissions": [
1213
"updater:default"

src-tauri/src/commands.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,25 @@ pub async fn find_rollout_path_for_session(session_uuid: String) -> Result<Optio
135135

136136
Ok(rollout_path)
137137
}
138+
139+
#[tauri::command]
140+
pub async fn create_new_window(app: AppHandle) -> Result<(), String> {
141+
use tauri::{WebviewUrl, WebviewWindowBuilder};
142+
143+
let window_label = format!("main-{}", chrono::Utc::now().timestamp_millis());
144+
145+
let window = WebviewWindowBuilder::new(&app, &window_label, WebviewUrl::default())
146+
.title("Codexia")
147+
.inner_size(1200.0, 800.0)
148+
.min_inner_size(800.0, 600.0)
149+
.decorations(true)
150+
.resizable(true)
151+
.fullscreen(false)
152+
.build()
153+
.map_err(|e| format!("Failed to create new window: {}", e))?;
154+
155+
// Focus the new window
156+
window.set_focus().map_err(|e| format!("Failed to focus window: {}", e))?;
157+
158+
Ok(())
159+
}

src-tauri/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ mod state;
99
mod utils;
1010

1111
use commands::{
12-
approve_execution, approve_patch, check_codex_version, close_session, delete_session_file,
13-
find_rollout_path_for_session, get_latest_session_id, get_running_sessions, get_session_files,
14-
load_sessions_from_disk, pause_session, read_history_file, read_session_file, send_message,
15-
start_codex_session,
12+
approve_execution, approve_patch, check_codex_version, close_session, create_new_window,
13+
delete_session_file, find_rollout_path_for_session, get_latest_session_id,
14+
get_running_sessions, get_session_files, load_sessions_from_disk, pause_session,
15+
read_history_file, read_session_file, send_message, start_codex_session,
1616
};
1717
use config::{
1818
add_or_update_model_provider, add_or_update_profile, delete_profile, ensure_default_providers,
@@ -81,6 +81,7 @@ pub fn run() {
8181
read_history_file,
8282
find_rollout_path_for_session,
8383
check_codex_version,
84+
create_new_window,
8485
read_directory,
8586
get_default_directories,
8687
search_files,

src/components/layout/AppHeader.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
Brain,
1010
Palette,
1111
Users,
12+
ExternalLink,
1213
} from "lucide-react";
1314
import { Button } from "@/components/ui/button";
1415
import { Badge } from "@/components/ui/badge";
@@ -54,6 +55,14 @@ export function AppHeader() {
5455
}
5556
};
5657

58+
const handleNewWindow = async () => {
59+
try {
60+
await invoke("create_new_window");
61+
} catch (error) {
62+
console.error("Failed to create new window:", error);
63+
}
64+
};
65+
5766
useEffect(() => {
5867
const checkVersion = async () => {
5968
try {
@@ -92,9 +101,18 @@ export function AppHeader() {
92101

93102
{/* Welcome button to projects page */}
94103
<Link to="/" className="flex hover:text-primary items-center gap-1">
95-
<PartyPopper className="w-5 h-5" /> Projects
104+
<PartyPopper className="w-5 h-5" />
96105
</Link>
97106

107+
<Button
108+
variant="ghost"
109+
onClick={handleNewWindow}
110+
className="h-6 w-6"
111+
title="Open New Window"
112+
>
113+
<ExternalLink />
114+
</Button>
115+
98116
{location.pathname === "/chat" && (
99117
<Button
100118
variant="ghost"
@@ -131,7 +149,6 @@ export function AppHeader() {
131149
<Button variant="ghost" onClick={toggleChatPane} className="h-6 w-6">
132150
<Brain />
133151
</Button>
134-
135152
<Button variant="ghost" className="h-6 w-6" onClick={toggleTheme}>
136153
{theme === "dark" ? <Sun /> : <Moon />}
137154
</Button>

0 commit comments

Comments
 (0)