move settings files to resource directory

main
reng 3 months ago
parent 0c6555d67e
commit 34e9f9b527
  1. 3
      vite/public/default.json
  2. 11
      vite/src-tauri/capabilities/default.json
  3. 57
      vite/src/util/useData.jsx

@ -7,6 +7,5 @@
"summary_prompt": "將以下一段話整理成一段文字,轉化成一句不超過 50 字的文字。文字抽象,保有遺憾的情緒。語氣沉靜。風格如一段未署名的詩、一句遠景旁白,帶有時間感與留白。不可直接描述事件細節,應使用象徵、比喻或殘句的方式呈現情緒。讓人讀完有重量,卻仍願意繼續前進。", "summary_prompt": "將以下一段話整理成一段文字,轉化成一句不超過 50 字的文字。文字抽象,保有遺憾的情緒。語氣沉靜。風格如一段未署名的詩、一句遠景旁白,帶有時間感與留白。不可直接描述事件細節,應使用象徵、比喻或殘句的方式呈現情緒。讓人讀完有重量,卻仍願意繼續前進。",
"speech_idle_time": "4000", "speech_idle_time": "4000",
"sd_prompt_prefix": "a hazy memory of a {{ ", "sd_prompt_prefix": "a hazy memory of a {{ ",
"sd_prompt_suffix": "}}, soft atmospheric blur, centered ghostly silhouette, fading contours, pastel glow, cinematic haze, (analog film grain), (shallow depth of field:1.3), impressionist style, ethereal light, dreamlike mood, memory fragment haze.", "sd_prompt_suffix": "}}, soft atmospheric blur, centered ghostly silhouette, fading contours, pastel glow, cinematic haze, (analog film grain), (shallow depth of field:1.3), impressionist style, ethereal light, dreamlike mood, memory fragment haze."
"id": 13
} }

@ -36,6 +36,11 @@
}, },
{ {
"path": "$APPDATA/**/*" "path": "$APPDATA/**/*"
},{
"path": "$RESOURCE"
},
{
"path": "$RESOURCE/**/*"
} }
] ]
}, },
@ -52,6 +57,12 @@
}, },
{ {
"path": "$APPDATA/**/*" "path": "$APPDATA/**/*"
},
{
"path": "$RESOURCE"
},
{
"path": "$RESOURCE/**/*"
} }
] ]
}, },

@ -8,6 +8,8 @@ const dataContext=createContext();
const filePath= 'param.json'; const filePath= 'param.json';
const GlobalSettingsPath='./GlobalSettings.json';
const PrivateSettingsPath='./PrivateSettings.json';
export function DataProvider({children}) { export function DataProvider({children}) {
@ -17,16 +19,36 @@ export function DataProvider({children}) {
try{ try{
const folder=await path.appDataDir(); // check exists
if (!(await exists(folder))) { const globalExists=await exists(GlobalSettingsPath, { baseDir: BaseDirectory.Resource });
const privateExists=await exists(PrivateSettingsPath, { baseDir: BaseDirectory.Resource });
console.log('Creating folder:', folder); console.log("GlobalSettings exists:", globalExists);
await mkdir(folder); console.log("PrivateSettings exists:", privateExists);
if(!globalExists){
// copy from public/default.json
const res=await fetch('default.json');
const defaultData=await res.json();
await writeTextFile(GlobalSettingsPath, JSON.stringify(defaultData),
{ baseDir: BaseDirectory.Resource });
console.log("Default global settings written to",
path(GlobalSettingsPath, { baseDir: BaseDirectory.Resource }));
}
if(!privateExists){
await writeTextFile(PrivateSettingsPath, JSON.stringify({}),
{ baseDir: BaseDirectory.Resource });
console.log("Empty private settings written to",
path(PrivateSettingsPath, { baseDir: BaseDirectory.Resource }));
} }
const contents=await readTextFile(filePath, { baseDir: BaseDirectory.AppData });
// const contents=await readTextFile(filePath, { baseDir: BaseDirectory.AppData });
const contents=await readTextFile(GlobalSettingsPath, { baseDir: BaseDirectory.Resource });
let output=await JSON.parse(contents); let output=await JSON.parse(contents);
const private_contents=await readTextFile(PrivateSettingsPath, { baseDir: BaseDirectory.Resource });
const private_output=await JSON.parse(private_contents);
output={...output, ...private_output};
// check if all keys in ParamKeys are present in output // check if all keys in ParamKeys are present in output
const missingKeys = ParamKeys.filter(key => !output.hasOwnProperty(key)); const missingKeys = ParamKeys.filter(key => !output.hasOwnProperty(key));
@ -58,10 +80,21 @@ export function DataProvider({children}) {
setData(towrite); setData(towrite);
} }
if(towrite.id){
try{
await writeTextFile(PrivateSettingsPath, JSON.stringify({
id: towrite.id
}), { baseDir: BaseDirectory.Resource });
console.log("Private settings written successfully");
}catch(error){
console.error("Error writing private settings:", error);
}
}
try{ try{
const folder = await path.appDataDir(); const res_write=await writeTextFile(GlobalSettingsPath, JSON.stringify(towrite), { baseDir: BaseDirectory.Resource });
const res_write=await writeTextFile(`${folder}\\${filePath}`, JSON.stringify(towrite)) console.log("File written successfully", GlobalSettingsPath, towrite);
console.log("File written successfully", `${folder}\\${filePath}`);
}catch(error){ }catch(error){
console.error("Error writing file:", error); console.error("Error writing file:", error);
} }
@ -87,9 +120,9 @@ export function DataProvider({children}) {
read, read,
write, write,
openFile: async () => { openFile: async () => {
const folder = await path.appDataDir(); const folder = await path.resourceDir();
const file = await path.join(folder, filePath); // const file = await path.join(folder, GlobalSettingsPath);
await openPath(file); await openPath(folder);
}, },
}}> }}>
{children} {children}

Loading…
Cancel
Save