Merge pull request #11 from trippjoe/main

added basic data persistence for game installed
This commit is contained in:
tripp 2022-04-12 00:18:39 -04:00 committed by GitHub
commit af5f068548
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 96 additions and 10 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 602 KiB

After

Width:  |  Height:  |  Size: 574 KiB

17
main.js
View file

@ -3,6 +3,7 @@ import { actions, general_pane, files_pane, links_pane } from './components/sett
import { jak1_main, jak1_sidebar } from './components/jak1/jak1'; import { jak1_main, jak1_sidebar } from './components/jak1/jak1';
import { isoSeries } from './src/utils/iso'; import { isoSeries } from './src/utils/iso';
import { launchGame } from './src/utils/launch'; import { launchGame } from './src/utils/launch';
import { getInstallStatus } from './src/utils/store';
const sidebar = document.querySelector('.sidebar'); const sidebar = document.querySelector('.sidebar');
@ -40,11 +41,11 @@ class SupportedGame {
} }
} }
function isGameSetup(supportedGame) { async function isGameSetup(supportedGame) {
if (supportedGame == SupportedGame.Jak1) { if (supportedGame == SupportedGame.Jak1) {
// TODO - check the installation directory and such, wherever that ends up being // TODO - check the installation directory and such, wherever that ends up being
// return false for now const isInstalled = await getInstallStatus(supportedGame.name);
return false; return isInstalled;
} else { } else {
return false; return false;
} }
@ -55,12 +56,12 @@ let activeGame = SupportedGame.Jak1;
renderControls(); renderControls();
function renderControls() { export async function renderControls() {
if (document.getElementById("launcherControls") == undefined) { if (document.getElementById("launcherControls") == undefined) {
return; return;
} }
if (isGameSetup(activeGame)) { if (await isGameSetup(activeGame)) {
document.getElementById("launcherControls").innerHTML += `<button id="configBtn">CONFIG</button><button id="playBtn">PLAY</button>`; document.getElementById("launcherControls").innerHTML = `<button id="configBtn">CONFIG</button><button id="playBtn">PLAY</button>`;
document.getElementById("playBtn").onclick = () => { document.getElementById("playBtn").onclick = () => {
launchGame(); launchGame();
} }
@ -68,9 +69,9 @@ function renderControls() {
// TODO // TODO
} }
} else { } else {
document.getElementById("launcherControls").innerHTML += `<button id="setupBtn">SETUP</button>`; document.getElementById("launcherControls").innerHTML = `<button id="setupBtn">SETUP</button>`;
document.getElementById("setupBtn").onclick = () => { document.getElementById("setupBtn").onclick = () => {
isoSeries(); isoSeries();
} }
} }
} }

30
package-lock.json generated
View file

@ -9,7 +9,8 @@
"version": "0.0.0", "version": "0.0.0",
"dependencies": { "dependencies": {
"@tauri-apps/api": "^1.0.0-rc.3", "@tauri-apps/api": "^1.0.0-rc.3",
"bootstrap-icons": "^1.8.1" "bootstrap-icons": "^1.8.1",
"tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store"
}, },
"devDependencies": { "devDependencies": {
"@tauri-apps/cli": "^1.0.0-rc.8", "@tauri-apps/cli": "^1.0.0-rc.8",
@ -712,6 +713,20 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/tauri-plugin-store-api": {
"version": "0.1.0",
"resolved": "git+ssh://git@github.com/tauri-apps/tauri-plugin-store.git#7ac980a81683b49672d18b7f0d01cd04dc3a7ca0",
"license": "MIT",
"dependencies": {
"@tauri-apps/api": "1.0.0-rc.3",
"tslib": "2.3.1"
}
},
"node_modules/tslib": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz",
"integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw=="
},
"node_modules/type-fest": { "node_modules/type-fest": {
"version": "2.12.1", "version": "2.12.1",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.12.1.tgz", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.12.1.tgz",
@ -1115,6 +1130,19 @@
"integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==",
"dev": true "dev": true
}, },
"tauri-plugin-store-api": {
"version": "git+ssh://git@github.com/tauri-apps/tauri-plugin-store.git#7ac980a81683b49672d18b7f0d01cd04dc3a7ca0",
"from": "tauri-plugin-store-api@github:tauri-apps/tauri-plugin-store",
"requires": {
"@tauri-apps/api": "1.0.0-rc.3",
"tslib": "2.3.1"
}
},
"tslib": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz",
"integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw=="
},
"type-fest": { "type-fest": {
"version": "2.12.1", "version": "2.12.1",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.12.1.tgz", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.12.1.tgz",

View file

@ -14,6 +14,7 @@
}, },
"dependencies": { "dependencies": {
"@tauri-apps/api": "^1.0.0-rc.3", "@tauri-apps/api": "^1.0.0-rc.3",
"bootstrap-icons": "^1.8.1" "bootstrap-icons": "^1.8.1",
"tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store"
} }
} }

13
src-tauri/Cargo.lock generated
View file

@ -61,6 +61,7 @@ dependencies = [
"serde_json", "serde_json",
"tauri", "tauri",
"tauri-build", "tauri-build",
"tauri-plugin-store",
] ]
[[package]] [[package]]
@ -3103,6 +3104,18 @@ dependencies = [
"tauri-utils", "tauri-utils",
] ]
[[package]]
name = "tauri-plugin-store"
version = "0.0.0"
source = "git+https://github.com/tauri-apps/tauri-plugin-store#7ac980a81683b49672d18b7f0d01cd04dc3a7ca0"
dependencies = [
"log",
"serde",
"serde_json",
"tauri",
"thiserror",
]
[[package]] [[package]]
name = "tauri-runtime" name = "tauri-runtime"
version = "0.3.4" version = "0.3.4"

View file

@ -19,6 +19,10 @@ serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.0.0-rc.5", features = ["api-all"] } tauri = { version = "1.0.0-rc.5", features = ["api-all"] }
[dependencies.tauri-plugin-store]
git = "https://github.com/tauri-apps/tauri-plugin-store"
#branch = "main"
[features] [features]
# by default Tauri runs in production mode # by default Tauri runs in production mode
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL # when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL

View file

@ -3,8 +3,11 @@
windows_subsystem = "windows" windows_subsystem = "windows"
)] )]
use tauri_plugin_store::PluginBuilder;
fn main() { fn main() {
tauri::Builder::default() tauri::Builder::default()
.plugin(PluginBuilder::default().build())
.run(tauri::generate_context!()) .run(tauri::generate_context!())
.expect("error while running tauri application"); .expect("error while running tauri application");
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 514 KiB

After

Width:  |  Height:  |  Size: 7.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 483 KiB

After

Width:  |  Height:  |  Size: 1.1 MiB

View file

@ -2,6 +2,7 @@ import { message } from "@tauri-apps/api/dialog";
import { platform } from "@tauri-apps/api/os"; import { platform } from "@tauri-apps/api/os";
import { appDir, join } from "@tauri-apps/api/path"; import { appDir, join } from "@tauri-apps/api/path";
import { Command } from "@tauri-apps/api/shell"; import { Command } from "@tauri-apps/api/shell";
import { setInstallStatus } from '../utils/store';
export async function buildGame() { export async function buildGame() {
const userPlatform = await platform(); const userPlatform = await platform();
@ -23,6 +24,7 @@ export async function buildGame() {
console.log(`Compiler finished with code ${data.code} and signal ${data.signal}`); console.log(`Compiler finished with code ${data.code} and signal ${data.signal}`);
if (data.code === 0) { if (data.code === 0) {
message('Game Ready to play!'); message('Game Ready to play!');
setInstallStatus();
return 'Compiler finished'; return 'Compiler finished';
} else { } else {
message('Game Ready to play!'); message('Game Ready to play!');

34
src/utils/store.js Normal file
View file

@ -0,0 +1,34 @@
import { Store } from 'tauri-plugin-store-api';
import { renderControls } from '../../main';
import { readTextFile, writeFile } from '@tauri-apps/api/fs';
import { appDir, join } from '@tauri-apps/api/path';
const store = new Store('settings.json');
(async function initStore() {
const path = await join(await appDir(), 'settings.json');
try {
await readTextFile(path);
} catch (error) {
const initSettings = `{"Jak 1": {"installed": false},"Jak 2": {"installed": false},"Jak 3": {"installed": false}}`;
const x = await writeFile({ contents: initSettings, path: path });
console.log('Created settings.json file');
// once again probably not a good idea to use this render function here
renderControls();
}
})();
export async function getInstallStatus(game) {
await store.load();
const { installed } = await store.get(game);
return installed;
}
export async function setInstallStatus() {
await store.load();
await store.set("Jak 1", { "installed": true });
await store.save();
// calling this render function from here is probably a bad idea but im not sure how else to rerender the page
renderControls();
return;
}