[go: nahoru, domu]

Skip to content

Commit

Permalink
feat: add app data logic
Browse files Browse the repository at this point in the history
  • Loading branch information
iGoodie committed Sep 18, 2022
1 parent 7818540 commit f028d19
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
},
"tauri": {
"allowlist": {
"all": true
"all": true,
"fs": {
"writeFile": true,
"readFile": true,
"createDir": true,
"readDir": true,
"scope": ["*"]
}
},
"bundle": {
"active": true,
Expand Down Expand Up @@ -57,7 +64,7 @@
"fullscreen": false,
"height": 600,
"resizable": true,
"title": "ArcDPS Updater | For DX11",
"title": "Arcdps Updater | For DX11",
"width": 800
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from "react";
import reactLogo from "./assets/react.svg";
import TauriAPI from "@tauri-apps/api/tauri";
import * as TauriAPI from "@tauri-apps/api/tauri";
import "./App.css";

function App() {
Expand Down
5 changes: 4 additions & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import "./style.css";
import "@/utils/appdata.util.ts";

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
const rootElement = document.getElementById("root") as HTMLElement;

ReactDOM.createRoot(rootElement).render(
<React.StrictMode>
<App />
</React.StrictMode>
Expand Down
53 changes: 53 additions & 0 deletions src/utils/appdata.util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {
BaseDirectory,
exists,
createDir,
readTextFile,
writeTextFile,
} from "@tauri-apps/api/fs";

const APP_DATA_FOLDER = "ArcdpsUpdaterDx11";
const CONFIG_FILE_NAME = "app.config.json";

/* ------------------------- */

interface AppConfig {
gameDir?: string;
}

console.log("Loading App Config...");

let appConfig: AppConfig = {
gameDir: "",
};
appConfig = await readConfigJson();

console.log("App Config loaded successfully.", appConfig);

/* ------------------------- */

export async function createDataFolder() {
return createDir(APP_DATA_FOLDER, {
dir: BaseDirectory.Data,
recursive: true,
});
}

export async function readConfigJson() {
const filepath = `${APP_DATA_FOLDER}/${CONFIG_FILE_NAME}`;
try {
exists(filepath, { dir: BaseDirectory.Data });
const filedata = await readTextFile(filepath, { dir: BaseDirectory.Data });
return JSON.parse(filedata);
} catch (error) {
saveConfigJson();
return appConfig;
}
}

export async function saveConfigJson() {
const filepath = `${APP_DATA_FOLDER}/${CONFIG_FILE_NAME}`;
writeTextFile(filepath, JSON.stringify(appConfig, undefined, 3), {
dir: BaseDirectory.Data,
});
}
7 changes: 5 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
Expand All @@ -14,7 +14,10 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
"jsx": "react-jsx",
"paths": {
"@/*": ["./src"]
}
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
Expand Down
6 changes: 6 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -24,4 +25,9 @@ export default defineConfig({
// produce sourcemaps for debug builds
sourcemap: !!process.env.TAURI_DEBUG,
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
});

0 comments on commit f028d19

Please sign in to comment.