Skip to content

Commit

Permalink
Merge pull request #123 from Lazap-Development/nightly
Browse files Browse the repository at this point in the history
Commit(s) that were left out for v0.6.2 release
  • Loading branch information
p0ryae authored Feb 2, 2023
2 parents a1bbf95 + 8f676a6 commit 1a4b945
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ features = ["sqlite"]
[dependencies]
serde_json = "1.0.85"
serde = { version = "1.0.144", features = ["derive"] }
tauri = { version = "1.2.0", features = ["devtools", "dialog-all", "fs-create-dir", "fs-read-dir", "fs-read-file", "fs-rename-file", "fs-write-file", "global-shortcut-all", "http-request", "os-all", "path-all", "protocol-asset", "shell-execute", "system-tray", "window-center", "window-close", "window-create", "window-hide", "window-maximize", "window-minimize", "window-show", "window-start-dragging", "window-unmaximize", "window-unminimize"] }
tauri = { version = "1.2.0", features = ["devtools", "dialog-all", "global-shortcut-all", "http-request", "os-all", "path-all", "protocol-asset", "shell-execute", "system-tray", "window-center", "window-close", "window-create", "window-hide", "window-maximize", "window-minimize", "window-show", "window-start-dragging", "window-unmaximize", "window-unminimize"] }
window-shadows = "0.2.0"
html_parser = "0.6.3"
thiserror = "*"
Expand Down
22 changes: 19 additions & 3 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ fn main() {
write_file,
d_f_exists,
read_dir,
write_binary_file
write_binary_file,
rename_file,
remove_file
])
.run(tauri::generate_context!())
.expect("error while running lazap");
Expand Down Expand Up @@ -205,7 +207,9 @@ fn main() {
write_file,
d_f_exists,
read_dir,
write_binary_file
write_binary_file,
rename_file,
remove_file
])
.run(tauri::generate_context!())
.expect("error while running lazap");
Expand Down Expand Up @@ -266,7 +270,9 @@ fn main() {
write_file,
d_f_exists,
read_dir,
write_binary_file
write_binary_file,
rename_file,
remove_file
])
.run(tauri::generate_context!())
.expect("error while running lazap");
Expand Down Expand Up @@ -361,6 +367,16 @@ async fn d_f_exists(path: String) -> Result<bool, Error> {
Ok(Path::new(&path).exists())
}

#[tauri::command]
async fn rename_file(from: String, to: String) {
fs::rename(from, to).expect("Unable to rename file.");
}

#[tauri::command]
async fn remove_file(file_path: String) {
fs::remove_file(file_path).expect("Unable to remove file.");
}

#[tauri::command]
async fn read_dir(dir_path: String) -> Vec<String> {
let mut file_list = Vec::new();
Expand Down
8 changes: 0 additions & 8 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@
"dialog": {
"all": true
},
"fs": {
"createDir": true,
"readDir": true,
"readFile": true,
"renameFile": true,
"writeFile": true,
"scope": ["**"]
},
"globalShortcut": {
"all": true
},
Expand Down
43 changes: 24 additions & 19 deletions src/components/AllGames.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
</template>

<script>
const fs = window.__TAURI__.fs;
const invoke = window.__TAURI__.invoke;
const dialog = window.__TAURI__.dialog;
const path = window.__TAURI__.path;
Expand All @@ -86,18 +85,19 @@ export default {
let reader = new FileReader();
reader.onload = async function () {
await fs.write(
(await path.appDir()) +
`storage/cache/games/banners/newcustombanner.png`,
reader.result
);
await invoke("write_binary_file", {
filePath:
(await path.appDir()) +
`cache/games/banners/newcustombanner.png`,
fileContent: [...new Uint8Array(reader.result)],
});
document.getElementById(
"addGameCustomBannerOutput"
).style.backgroundImage =
`url(` +
tauri.convertFileSrc(
(await path.appDir()) +
`storage/cache/games/banners/newcustombanner.png`
`cache/games/banners/newcustombanner.png`
) +
`?${new Date().getSeconds()}` +
`)`;
Expand All @@ -108,6 +108,7 @@ export default {
},
async mounted() {
let newGameLocation;
let createGameElement = this.$root.$refs.findGamesMod.createGameElement;
document
.getElementById("addGameBtn")
Expand All @@ -123,9 +124,11 @@ export default {
document.getElementById("inputGameName").value = "";
document.getElementById("addGameCustomBannerTxt").style.opacity = "1";
try {
await fs.removeFile(
(await path.appDir()) + `cache/games/banners/newcustombanner.png`
);
await invoke("remove_file", {
file_path:
(await path.appDir()) +
`cache/games/banners/newcustombanner.png`,
});
} catch (e) {
return e;
}
Expand All @@ -152,17 +155,19 @@ export default {
};
try {
await fs.renameFile(
(await path.appDir()) +
`storage/cache/games/banners/newcustombanner.png`,
(await path.appDir()) +
`storage/cache/games/banners/${require("./modules/sha256.js").sha256(
await invoke("rename_file", {
from:
(await path.appDir()) +
`cache/games/banners/newcustombanner.png`,
to:
(await path.appDir()) +
`cache/games/banners/${require("./modules/sha256.js").sha256(
document
.getElementById("inputGameName")
.value.replaceAll(" ", "_")
)}.png`
);
this.$root.$refs.findGamesMod.Elements.createGameElement(
)}.png`,
});
createGameElement(
scheme,
"allGamesList"
);
Expand All @@ -177,7 +182,7 @@ export default {
fileContent: JSON.stringify(data),
});
} catch (e) {
this.$root.$refs.findGamesMod.Elements.createGameElement(
createGameElement(
scheme,
"allGamesList"
);
Expand Down

0 comments on commit 1a4b945

Please sign in to comment.