Skip to content

Commit

Permalink
feat: open the project using vscode (#135)
Browse files Browse the repository at this point in the history
Signed-off-by: 1111mp <The1111mp@outlook.com>
  • Loading branch information
1111mp committed Oct 31, 2024
1 parent 4fd584f commit 37abc56
Show file tree
Hide file tree
Showing 7 changed files with 462 additions and 388 deletions.
15 changes: 14 additions & 1 deletion src-tauri/src/cmds.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use std::path::PathBuf;
use std::{path::PathBuf, process::Command};

use crate::{
config::{Config, Group, ISettings, NVersion, Project},
Expand Down Expand Up @@ -157,6 +157,19 @@ pub async fn configration_import(
wrap_err!(configration::configration_import(&app_handle, sync).await)
}

/// open project with VsCode
#[tauri::command]
pub async fn open_with_vscode(path: String) -> CmdResult<()> {
#[cfg(windows)]
let cmd: &str = "code.cmd";

#[cfg(unix)]
let cmd = "code";

wrap_err!(Command::new(cmd).arg(&path).status())?;
Ok(())
}

/// open data dir `.nvmd`
#[tauri::command]
pub fn open_data_dir() -> CmdResult<()> {
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ fn main() -> tauri::Result<()> {
cmds::sync_project_version,
cmds::batch_update_project_version,
cmds::open_dir,
cmds::open_with_vscode,
// groups
cmds::group_list,
cmds::update_groups,
Expand Down
29 changes: 29 additions & 0 deletions src/components/vscode-logo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { forwardRef } from 'react';
import { cn } from '@/lib/utils';

export interface VsCodeLogoProps extends React.SVGAttributes<SVGSVGElement> {}

export const VsCodeLogo = forwardRef<SVGSVGElement, VsCodeLogoProps>(
({ className, ...props }, ref) => {
return (
<svg
ref={ref}
className={cn(
'w-[18px] h-[18px] text-primary cursor-pointer',
className
)}
viewBox='0 0 1024 1024'
version='1.1'
xmlns='http://www.w3.org/2000/svg'
p-id='19443'
{...props}
>
<path
d='M746.222933 102.239573l-359.799466 330.820267L185.347413 281.4976 102.2464 329.864533l198.20544 182.132054-198.20544 182.132053 83.101013 48.510293 201.076054-151.558826 359.799466 330.676906 175.527254-85.251413V187.4944z m0 217.57952v384.341334l-255.040853-192.177494z'
fill='currentColor'
p-id='19444'
></path>
</svg>
);
}
);
3 changes: 2 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,6 @@
"Invalid-project-path": "Invalid project path",
"Error-500": "Sorry, something went wrong.",
"Unzipping": "Unzipping",
"Set-as-default": "Set as the default version"
"Set-as-default": "Set as the default version",
"open-with-vscode": "Open with VsCode"
}
3 changes: 2 additions & 1 deletion src/locales/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,6 @@
"Invalid-project-path": "无效的项目路径",
"Error-500": "抱歉,出了点问题。",
"Unzipping": "解压中",
"Set-as-default": "设置为默认版本"
"Set-as-default": "设置为默认版本",
"open-with-vscode": "使用 VsCode 打开"
}
Loading

0 comments on commit 37abc56

Please sign in to comment.