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

30
package-lock.json generated
View file

@ -9,7 +9,8 @@
"version": "0.0.0",
"dependencies": {
"@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": {
"@tauri-apps/cli": "^1.0.0-rc.8",
@ -712,6 +713,20 @@
"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": {
"version": "2.12.1",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.12.1.tgz",
@ -1115,6 +1130,19 @@
"integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==",
"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": {
"version": "2.12.1",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.12.1.tgz",

View file

@ -14,6 +14,7 @@
},
"dependencies": {
"@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",
"tauri",
"tauri-build",
"tauri-plugin-store",
]
[[package]]
@ -3103,6 +3104,18 @@ dependencies = [
"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]]
name = "tauri-runtime"
version = "0.3.4"

View file

@ -19,6 +19,10 @@ serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
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]
# 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

View file

@ -3,8 +3,11 @@
windows_subsystem = "windows"
)]
use tauri_plugin_store::PluginBuilder;
fn main() {
tauri::Builder::default()
.plugin(PluginBuilder::default().build())
.run(tauri::generate_context!())
.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 { appDir, join } from "@tauri-apps/api/path";
import { Command } from "@tauri-apps/api/shell";
import { setInstallStatus } from '../utils/store';
export async function buildGame() {
const userPlatform = await platform();
@ -23,6 +24,7 @@ export async function buildGame() {
console.log(`Compiler finished with code ${data.code} and signal ${data.signal}`);
if (data.code === 0) {
message('Game Ready to play!');
setInstallStatus();
return 'Compiler finished';
} else {
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;
}