Skip to content

Commit

Permalink
add conf
Browse files Browse the repository at this point in the history
  • Loading branch information
joe committed Jun 27, 2024
1 parent 6ba681c commit 1779002
Show file tree
Hide file tree
Showing 4 changed files with 296 additions and 74 deletions.
2 changes: 1 addition & 1 deletion 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 = [ "window-hide", "system-tray", "shell-open" , "icon-png"] }
tauri = { version = "1", features = [ "fs-read-file", "window-hide", "system-tray", "shell-open" , "icon-png"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
image = "0.25"
Expand Down
15 changes: 15 additions & 0 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@
},
"allowlist": {
"all": false,
"fs": {
"readFile": true,
"scope": [
"*",
"$APP",
"$APP/*",
"$CACHE",
"$CACHE/*",
"$CONFIG",
"$CONFIG/*",
"$LOG",
"$LOG/*",
"$HOME/*"
]
},
"window": {
"hide": true
},
Expand Down
43 changes: 31 additions & 12 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { Select, SelectItem } from "@nextui-org/react";

import { Tabs, Tab, Card, CardBody } from "@nextui-org/react";

import { readTextFile, BaseDirectory } from "@tauri-apps/api/fs";

async function fetchSetting(key: string) {
const value = await invoke("get_setting", { key });
return value;
Expand Down Expand Up @@ -50,11 +52,40 @@ function App() {

const [selectedPair2, setSelectedPair2] = useState("");

const [pairs, setPairs] = useState([
{ label: "BTC/USDT", value: "BTC/USDT" },
{ label: "ETH/USDT", value: "ETH/USDT" },
{ label: "LTC/USDT", value: "LTC/USDT" },
{ label: "BOME/USDT", value: "BOME/USDT" },
]);

const [stocks, setStocks] = useState([
{ label: "上证指数", value: "sh000001" },
{ label: "沪深300", value: "sh000300" },
{ label: "隆基绿能", value: "sh601012" },
]);

useEffect(() => {
// 这里的代码会在组件首次渲染后执行
console.log("组件已挂载");

const fetchData = async () => {
try {
const conf: any = await readTextFile("app.conf.json", {
dir: BaseDirectory.AppConfig,
});

const contents = JSON.parse(conf);
console.log(BaseDirectory.AppConfig);

setPairs(contents["pairs"]);
setStocks(contents["stocks"]);

console.log(stocks);
} catch (err) {
console.log(err);
}

const response = (await fetchSetting("config")) as string;
console.log(`fetchData ${response}`);
try {
Expand Down Expand Up @@ -110,19 +141,7 @@ function App() {
await updateSetting("config", JSON.stringify(data));
console.log("submit success");
};
const pairs = [
{ label: "BTC/USDT", value: "BTC/USDT" },
{ label: "ETH/USDT", value: "ETH/USDT" },
{ label: "LTC/USDT", value: "LTC/USDT" },
{ label: "BOME/USDT", value: "BOME/USDT" },
];

//sh000300
const stocks = [
{ label: "上证指数", value: "sh000001" },
{ label: "沪深300", value: "sh000300" },
{ label: "隆基绿能", value: "sh601012" },
];
const updateIntervals = [
{ label: "Price updates", value: "Every 5 seconds" },
//{ label: "News updates", value: "Every 5 minutes" },
Expand Down
Loading

0 comments on commit 1779002

Please sign in to comment.