Skip to content

Commit

Permalink
Merge pull request #25 from KunalSin9h/commit
Browse files Browse the repository at this point in the history
Commit
  • Loading branch information
KunalSin9h authored Oct 4, 2023
2 parents b6531d2 + 9aebb3e commit 1eec3ba
Show file tree
Hide file tree
Showing 11 changed files with 415 additions and 195 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"name": "secops",
"private": true,
"scripts": {
"build": "tsc \u0026\u0026 vite build",
"build": "tsc && vite build",
"dev": "vite",
"format": "prettier --write \"src/**/*.{js,ts,json,md,jsx,tsx,mdx}\"",
"format:check": "prettier --check \"src/**/*.{js,ts,json,md,jsx,tsx,mdx}\"",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ features = ['derive']
version = '1.0'

[dependencies.tauri]
features = ['fs-read-file']
features = [ "fs-write-file", "fs-read-dir",'fs-read-file']
version = '1.4'

[dependencies.tokio]
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/core/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn check_folder(path: &PathBuf) -> Result<(), String> {
/// populate the default state file
fn fill_default_state_file(path: PathBuf) -> Result<(), String> {
let default_state_string = r#"{
"message": "Default State",
"message": "Current Settings",
"time": "$",
"commands": []
}"#;
Expand Down
12 changes: 5 additions & 7 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"all": false,
"fs": {
"readFile": true,
"scope": [
"$HOME/.secops/state/*"
]
"writeFile": true,
"readDir": true,
"scope": ["$HOME/.secops/*", "$HOME/.secops/state/*"]
},
"shell": {
"all": false,
Expand All @@ -32,9 +32,7 @@
"category": "Utility",
"copyright": "Kunal Singh \u003ckunal@kunalsin9h.com\u003e",
"deb": {
"depends": [
"policykit-1"
],
"depends": ["policykit-1"],
"desktopTemplate": "../assets/deb/secops.desktop"
},
"icon": [
Expand Down Expand Up @@ -68,4 +66,4 @@
}
]
}
}
}
121 changes: 106 additions & 15 deletions src/components/Header/Commit.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,117 @@
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";
import { useEffect, useState } from "react";
import {
Sheet,
SheetContent,
SheetDescription,
SheetHeader,
SheetTitle,
SheetTrigger,
} from "@/components/ui/sheet";
import { CommitIcon } from "@/lib/icons";
import { Button } from "../ui/button";
import {
type StateMeta,
getCommitStatus,
commitSettings,
} from "@/lib/settings";

export default function Commit() {
return (
<Dialog>
<DialogTrigger>
<Sheet>
<SheetTrigger>
<div className="bg-white text-black hover:bg-black/10 px-3 py-2 rounded-md cursor-pointer flex items-center gap-2">
<CommitIcon />
<span>Commit</span>
</div>
</DialogTrigger>
<DialogContent className="h-[80%] w-[80%] xl:w-[60%] ">
<Button variant={"default"}>Commit</Button>
<div className="m-2 p-2 xl:m-4 xl:p-4">
<ul>
<li>A</li>
<li>A</li>
<li>A</li>
</ul>
</SheetTrigger>
<SheetContent className=" w-2/3 xl:w-1/3">
<SheetHeader>
<SheetTitle>Commit Settings!</SheetTitle>
<SheetDescription>
Commit takes snapshot of settings and configs, so that you can revet
back and apply backups.
</SheetDescription>
</SheetHeader>
<div className="px-2 xl:px-4 py-4 xl:py-8">
<Commits />
</div>
</DialogContent>
</Dialog>
</SheetContent>
</Sheet>
);
}

function Commits() {
const [commitStatus, setCommitStatus] = useState<StateMeta[]>();

useEffect(() => {
(async () => {
const status = await getCommitStatus();
setCommitStatus(status);
})();
}, []);

if (commitStatus === undefined) return <div>Loading...</div>;

return (
<div>
<div className="flex flex-col gap-4 px-4 xl:px-16">
<span className="text-md">{commitStatus[0].message}</span>
<div className="flex gap-4 items-center">
<div
className={`${
commitStatus[0].commit ? "bg-green-100" : "bg-green-300"
} text-black ${
commitStatus[0].commit
? "pointer-events-none cursor-not-allowed opacity-60"
: "hover:bg-green-400/50"
} px-3 py-2 rounded-md `}
onClick={async (e) => {
e.preventDefault();
await commitSettings("new commit it is");
const status = await getCommitStatus();
setCommitStatus(status);
}}
>
<span className="text-xs uppercase font-bold">
{commitStatus[0].commit ? "All Good" : "Commit"}
</span>
</div>
<span className="opacity-60 text-xs">{commitStatus[0].time}</span>
</div>
</div>

<div className="py-4 xl:py-8">
{commitStatus.slice(1).map((item, index) => {
return <CommitBox key={index} {...item} />;
})}
</div>
</div>
);
}

function CommitBox({
message,
commit,
time,
}: {
message: string;
commit: boolean;
time: string;
}) {
return (
<div className="flex flex-col gap-4 px-4 xl:px-16">
<span className="text-md">{message}</span>
<div className="flex gap-4 items-center">
<div
className={`${commit ? "bg-red-300" : "bg-green-300"} text-black ${
commit ? "hover:bg-red-400/80" : "hover:bg-green-400/50"
} px-3 py-2 rounded-md cursor-pointer`}
>
<span className="text-xs uppercase font-bold">
{commit ? "Revert" : "Commit"}
</span>
</div>
<span className="opacity-60 text-xs">{time}</span>
</div>
</div>
);
}
38 changes: 19 additions & 19 deletions src/components/Header/Export.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
Sheet,
SheetContent,
SheetDescription,
SheetHeader,
SheetTitle,
SheetTrigger,
} from "@/components/ui/sheet";
import { ExportIcon } from "@/lib/icons";

export default function Export() {
export default function Commit() {
return (
<Dialog>
<DialogTrigger>
<Sheet>
<SheetTrigger>
<div className="bg-white text-black hover:bg-black/10 px-3 py-2 rounded-md cursor-pointer flex items-center gap-2">
<ExportIcon />
<span>Export</span>
</div>
</DialogTrigger>
<DialogContent className="h-[80%] w-[80%] xl:w-[60%]">
<DialogHeader className="">
<DialogTitle>Are you sure absolutely sure?</DialogTitle>
<DialogDescription>
</SheetTrigger>
<SheetContent className="w-1/3">
<SheetHeader>
<SheetTitle>Are you sure absolutely sure?</SheetTitle>
<SheetDescription>
This action cannot be undone. This will permanently delete your
account and remove your data from our servers.
</DialogDescription>
</DialogHeader>
</DialogContent>
</Dialog>
</SheetDescription>
</SheetHeader>
</SheetContent>
</Sheet>
);
}
38 changes: 19 additions & 19 deletions src/components/Header/Import.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
Sheet,
SheetContent,
SheetDescription,
SheetHeader,
SheetTitle,
SheetTrigger,
} from "@/components/ui/sheet";
import { ImportIcon } from "@/lib/icons";

export default function Import() {
export default function Commit() {
return (
<Dialog>
<DialogTrigger>
<Sheet>
<SheetTrigger>
<div className="bg-white text-black hover:bg-black/10 px-3 py-2 rounded-md cursor-pointer flex items-center gap-2">
<ImportIcon />
<span>Import</span>
</div>
</DialogTrigger>
<DialogContent className="h-[80%] w-[80%] xl:w-[60%]">
<DialogHeader className="">
<DialogTitle>Are you sure absolutely sure?</DialogTitle>
<DialogDescription>
</SheetTrigger>
<SheetContent className="w-1/3">
<SheetHeader>
<SheetTitle>Are you sure absolutely sure?</SheetTitle>
<SheetDescription>
This action cannot be undone. This will permanently delete your
account and remove your data from our servers.
</DialogDescription>
</DialogHeader>
</DialogContent>
</Dialog>
</SheetDescription>
</SheetHeader>
</SheetContent>
</Sheet>
);
}
18 changes: 9 additions & 9 deletions src/components/Home/Services.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function AllServices() {

// This refresh state is to fetch new data when ever a new
// interaction will happen by the use
const [refresh, setRefresh] = useState(false);
const [refresh, setRefresh] = useState(0);

useEffect(() => {
const timer = setInterval(async () => {
Expand Down Expand Up @@ -73,7 +73,7 @@ export default function AllServices() {
onClick={(e) => {
e.preventDefault();
invoke("get_status", { service }).catch(toastError);
setRefresh(!refresh);
setRefresh(refresh + 1);
}}
>
Status
Expand All @@ -86,7 +86,7 @@ export default function AllServices() {
toastError,
);

setRefresh(!refresh);
setRefresh(refresh + 1);
}}
>
Enable
Expand All @@ -99,7 +99,7 @@ export default function AllServices() {
toastError,
);

setRefresh(!refresh);
setRefresh(refresh + 1);
}}
>
Disable
Expand All @@ -111,7 +111,7 @@ export default function AllServices() {
invoke("stop_service", { service }).catch(
toastError,
);
setRefresh(!refresh);
setRefresh(refresh + 1);
}}
>
Stop
Expand Down Expand Up @@ -155,7 +155,7 @@ export default function AllServices() {
e.preventDefault();
invoke("get_status", { service }).catch(toastError);

setRefresh(!refresh);
setRefresh(refresh + 1);
}}
>
Status
Expand All @@ -168,7 +168,7 @@ export default function AllServices() {
toastError,
);

setRefresh(!refresh);
setRefresh(refresh + 1);
}}
>
Enable
Expand All @@ -181,7 +181,7 @@ export default function AllServices() {
toastError,
);

setRefresh(!refresh);
setRefresh(refresh + 1);
}}
>
Disable
Expand All @@ -195,7 +195,7 @@ export default function AllServices() {
toastError,
);

setRefresh(!refresh);
setRefresh(refresh + 1);
}}
>
Start
Expand Down
Loading

0 comments on commit 1eec3ba

Please sign in to comment.