Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/desktop/src/components/FileMenuAction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
}),
shortcutService.on('clone-repo', async () => {
goto(clonePath());
}),
shortcutService.on('clone-window', async () => {
const url = new URL(window.location.href);
const currentProjectId = url.pathname.split('/')[1];
if (currentProjectId) {
await projectsService.openProjectInNewWindow(currentProjectId);
}
})
)
);
Expand Down
4 changes: 4 additions & 0 deletions apps/desktop/src/lib/project/projectsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ function injectEndpoints(api: ClientState['backendApi']) {
openProjectInWindow: build.mutation<void, { id: string }>({
extraOptions: { command: 'open_project_in_window' },
query: (args) => args
}),
getCurrentProjectId: build.query<string | null, void>({
extraOptions: { command: 'get_current_project_id' },
query: () => undefined
})
})
});
Expand Down
1 change: 1 addition & 0 deletions crates/gitbutler-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ fn main() {
projects::list_projects,
projects::set_project_active,
projects::open_project_in_window,
projects::get_current_project_id,
repo::git_get_local_config,
repo::git_set_local_config,
repo::check_signing_settings,
Expand Down
9 changes: 9 additions & 0 deletions crates/gitbutler-tauri/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ pub fn build<R: Runtime>(
.accelerator("CmdOrCtrl+Shift+O")
.build(handle)?,
&PredefinedMenuItem::separator(handle)?,
&MenuItemBuilder::with_id("file/clone-window", "Clone Window")
.accelerator("CmdOrCtrl+Shift+N")
.build(handle)?,
&PredefinedMenuItem::separator(handle)?,
])
.build()?;

Expand Down Expand Up @@ -265,6 +269,11 @@ pub fn handle_event<R: Runtime>(
return;
}

if event.id() == "file/clone-window" {
emit(webview, SHORTCUT_EVENT, "clone-window");
return;
}

#[cfg(any(debug_assertions, feature = "devtools"))]
{
if event.id() == "view/devtools" {
Expand Down
10 changes: 10 additions & 0 deletions crates/gitbutler-tauri/src/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ pub fn open_project_in_window(handle: tauri::AppHandle, id: ProjectId) -> Result
Ok(())
}

/// Get the current project ID for a window, if any.
#[tauri::command]
#[instrument(skip(window_state, window), err(Debug))]
pub fn get_current_project_id(
window_state: State<'_, WindowState>,
window: Window,
) -> Result<Option<ProjectId>, Error> {
Ok(window_state.get_project_for_window(window.label()))
}

#[derive(serde::Deserialize, serde::Serialize)]
pub struct ProjectForFrontend {
#[serde(flatten)]
Expand Down
6 changes: 6 additions & 0 deletions crates/gitbutler-tauri/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ pub(crate) mod state {
.map(|state| state.project_id)
.collect()
}

/// Get the current project ID for a specific window, if any.
pub fn get_project_for_window(&self, window: &WindowLabelRef) -> Option<ProjectId> {
let state_by_label = self.state.lock();
state_by_label.get(window).map(|state| state.project_id)
}
}
}

Expand Down
Loading