Skip to content

Commit

Permalink
Improve path display. Bump to v0.1.1
Browse files Browse the repository at this point in the history
Fix format on Windows.
  • Loading branch information
HuakunShen committed May 6, 2024
1 parent ad30788 commit f44f414
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 10 deletions.
2 changes: 1 addition & 1 deletion devclean-ui/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2021"
tauri-build = { version = "1", features = [] }

[dependencies]
tauri = { version = "1", features = [ "updater", "window-start-dragging", "fs-exists", "dialog-open", "clipboard-write-text", "shell-open"] }
tauri = { version = "1", features = [ "os-all", "updater", "window-start-dragging", "fs-exists", "dialog-open", "clipboard-write-text", "shell-open"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
devclean = { path = "../../devclean" }
Expand Down
11 changes: 7 additions & 4 deletions devclean-ui/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
},
"package": {
"productName": "devclean-ui",
"version": "0.1.0"
"version": "0.1.1"
},
"tauri": {
"allowlist": {
"all": false,
"os": {
"all": true
},
"clipboard": {
"all": false,
"readText": false,
Expand All @@ -30,7 +33,7 @@
},
"shell": {
"all": false,
"open": true
"open": ".*"
},
"window": {
"all": false,
Expand Down Expand Up @@ -72,8 +75,8 @@
"windows": [
{
"title": "devclean-ui",
"width": 800,
"height": 600,
"width": 1200,
"height": 800,
"titleBarStyle": "Overlay"
}
],
Expand Down
13 changes: 12 additions & 1 deletion devclean-ui/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "./App.css";
import { useState } from "react";
import { useEffect, useState } from "react";
import { Button } from "@/components/ui/button";
import { ThemeProvider } from "@/components/theme-provider";
import { ModeToggle } from "./components/mode-toggle";
Expand All @@ -22,6 +22,17 @@ function App() {
const [scanning, setScanning] = useState(false);
const { toast } = useToast();

useEffect(() => {
const cacheScanFolder = localStorage.getItem("cache-scan-folder");
if (cacheScanFolder) {
setPickedFolder(cacheScanFolder);
}
}, []);

useEffect(() => {
localStorage.setItem("cache-scan-folder", pickedFolder);
}, [pickedFolder]);

return (
<ThemeProvider defaultTheme="dark" storageKey="vite-ui-theme">
<Toaster />
Expand Down
25 changes: 22 additions & 3 deletions devclean-ui/src/components/path-highlight.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
import { platform } from "@tauri-apps/api/os";
import { useEffect, useMemo, useState } from "react";

export function PathHighlight({ path }: { path: string }) {
const [platformName, setPlatformName] = useState<string>();
const separator = useMemo(
() => (platformName === "win32" ? "\\" : "/"),
[platformName]
);

useEffect(() => {
(async () => {
const p = await platform();
setPlatformName(p);
})();
}, []);
function getFileName(p: string) {
return p.split("/").pop();
return p.split(separator).pop();
}
function getDirName(p: string) {
return p.split("/").slice(0, -1).join("/");
return p.split(separator).slice(0, -1).join(separator);
}
return (
<pre>
{getDirName(path)}/<span className=" text-red-500 dark:text-green-400">{getFileName(path)}</span>
{getDirName(path)}
{separator}
<span className=" text-red-500 dark:text-green-400">
{getFileName(path)}
</span>
</pre>
);
}
14 changes: 13 additions & 1 deletion devclean-ui/src/components/table/display-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ import prettyBytes from "pretty-bytes";
import { delete_dir } from "@/lib/command";
import { toast, useToast } from "@/components/ui/use-toast";
import { Progress } from "@/components/ui/progress";
import { PathHighlight } from "../path-highlight";
import { PathHighlight } from "@/components/path-highlight";
import {open} from '@tauri-apps/api/shell';

export const columns: ColumnDef<PathDisplayRow>[] = [
{
Expand Down Expand Up @@ -128,6 +129,17 @@ export const columns: ColumnDef<PathDisplayRow>[] = [
>
Copy Path
</DropdownMenuItem>
<DropdownMenuItem onClick={() => {
open(row.getValue("path")).catch(err => {
toast({
variant: "destructive",
title: "Error",
description: err,
});
})
}}>
Open Directory
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => {
delete_dir(row.getValue("path")).then(() => {
Expand Down

0 comments on commit f44f414

Please sign in to comment.