Skip to content

Commit

Permalink
Merge pull request #6 from clearfeld/main
Browse files Browse the repository at this point in the history
v.0.6.0
  • Loading branch information
clearfeld authored Jan 8, 2025
2 parents e78204a + 373e059 commit 25d48fb
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 223 deletions.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "construct"
version = "0.5.0"
version = "0.6.0"
description = "A GUI API Client"
authors = ["clearfeld"]
edition = "2021"
Expand Down
10 changes: 3 additions & 7 deletions src-tauri/capabilities/desktop.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@
"permissions": [
"updater:default",
"updater:default",
{
"identifier": "fs:allow-exists",
"allow": [{ "path": "$APPDATA/*" }]
},
"fs:allow-appdata-read",
"fs:allow-exists",
"fs:allow-appdata-read-recursive",
"fs:allow-appdata-write",
"fs:allow-appdata-write-recursive"
"fs:allow-appdata-write-recursive",
"core:window:allow-destroy"
]
}
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "construct",
"version": "0.5.0",
"version": "0.6.0",
"identifier": "com.construct.app",
"build": {
"beforeDevCommand": "pnpm dev",
Expand Down
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ function App() {
path="/"
element={
<div>
<SessionSaveAndLoadManager />

<div
style={{
height: "var(--navbar-height)",
Expand All @@ -71,6 +69,8 @@ function App() {
<Navbar />
</div>

<SessionSaveAndLoadManager />

<Outlet />

{/* <main className="container">
Expand Down
61 changes: 41 additions & 20 deletions src/SessionSaveAndLoadManager.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
import {
exists,
BaseDirectory,
readTextFile,
} from "@tauri-apps/plugin-fs";
import { useEffect } from "react";
import * as stylex from "@stylexjs/stylex";
import { exists, BaseDirectory, readTextFile } from "@tauri-apps/plugin-fs";
import { useEffect, useState } from "react";
import useRequestStore from "./stores/request_store/index.ts";
import { useNavigate } from "react-router";

// TODO: have different file for local and prod version of app
const session_file = "last_session.json";

// import { listen } from "@tauri-apps/api/event";
import { LoadingSize, LoadingSpinner } from "@controlkit/ui";
import { appDataDir } from "@tauri-apps/api/path";

const session_file = import.meta.env.DEV ? "last_session_dev_mode.json" : "last_session.json";
const roaming_dir = await appDataDir(); // "com.construct.app";

const styles = stylex.create({
wrapper: {
backgroundColor: "var(--color-bg)",
position: "absolute",
width: "100%",
height: "calc(100% - var(--navbar-height))",
zIndex: 1000,
display: "flex",
flexDirection: "column",
gap: "1rem",
justifyContent: "center",
alignItems: "center",
},
});

export default function SessionSaveAndLoadManager() {
const navigate = useNavigate();

const [loading, setLoading] = useState<boolean>(true);

const setAllDataFromSessionSave = useRequestStore(
(state) => state.setAllDataFromSessionSave,
);
Expand Down Expand Up @@ -44,10 +58,8 @@ export default function SessionSaveAndLoadManager() {
// }
// };

// // TODO: need to figure this out in case of alt f4 or other types of window close events
// // listen("tauri://close-requested", async (event) => {
// // await AttemptToSaveLocalSession();
// // });
// TODO: need to figure this out in case of alt f4 or other types of window close events


// window.addEventListener("keydown", handleKeyDown);

Expand All @@ -56,20 +68,19 @@ export default function SessionSaveAndLoadManager() {
// };
}, []);


async function SetLocalSessionIfExists() {
// TODO: https://tauri.app/plugin/file-system/#read
// probably should use readTextFileLines or Binary data format for session file instead of raw json
// but its fine for now

// TODO: create a separate file within appConfig for settings store in the future

const previous_session_exists = await exists(session_file, {
const previous_session_exists = await exists(`${roaming_dir}/${session_file}`, {
baseDir: BaseDirectory.AppData,
});

if (previous_session_exists) {
const session_json = await readTextFile(session_file, {
const session_json = await readTextFile(`${roaming_dir}/${session_file}`, {
baseDir: BaseDirectory.AppData,
});

Expand All @@ -95,8 +106,18 @@ export default function SessionSaveAndLoadManager() {
} else {
console.log("doesnt exists");
}

setLoading(false);
}

return <></>;
return (
<>
{loading && (
<div {...stylex.props(styles.wrapper)}>
<LoadingSpinner size={LoadingSize.LARGE} />
<p>Checking for local session...</p>
</div>
)}
</>
);
}

Loading

0 comments on commit 25d48fb

Please sign in to comment.