diff --git a/package.json b/package.json index 8748a75..344ab62 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "final_cypher", "private": true, - "version": "0.1.9", + "version": "0.2.2", "type": "module", "bin": "dist/server.js", "scripts": { diff --git a/server/index.cjs b/server/index.cjs index 631763c..c7cada2 100644 --- a/server/index.cjs +++ b/server/index.cjs @@ -140,6 +140,7 @@ websocketServer.on("connection", (webSocketClient) => { } let localVersion = (JSON.parse(localVersionCacheFile)).localVersion let isUpdating = localVersion === remoteBatchVersion ? false : true + console.log(localVersion, remoteBatchVersion, isUpdating) // console.log(localVersionCacheFile) let diffIds = [] for(let diff in localDiffs) { @@ -156,22 +157,23 @@ websocketServer.on("connection", (webSocketClient) => { for(let asset in releaseAssets) { asset = releaseAssets[asset] - totalSize += asset.size if(diffIds.includes(asset.id)) { let assetArr = [] assetArr.push(asset.browser_download_url) assetArr.push(asset.name) assetArr.push(asset.size) assetsURL.push(assetArr) + totalSize += asset.size } // console.log(asset) } let totalDownloaded = 0 let dirSize = 0 - if(!isUpdating) { + if(isUpdating) { dirSize = await du(fcDir) totalDownloaded += dirSize + totalSize += dirSize // totalSize += dirSize } let totalSwap = 0 @@ -219,7 +221,8 @@ websocketServer.on("connection", (webSocketClient) => { name, isUpdating, dirSize, - readyToPlay: false + readyToPlay: false, + totalUpdateFiles: assetsURL })) time = now } @@ -232,6 +235,11 @@ websocketServer.on("connection", (webSocketClient) => { // console.log(diffDownloader) try { await diffDownloader.download(); + if(isUpdating) { + fs.writeFileSync(`${cacheDir}/batchVersionCache.json`, JSON.stringify({ + localVersion: remoteBatchVersion + }), "utf-8"); + } } catch (error) { console.log(error); webSocketClient.send(JSON.stringify({ error })) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index d8abfa3..2d1dc16 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -18,6 +18,7 @@ use std::process::Command; fn greet(name: &str) -> String { format!("Hello, {}! You've been greeted from Rust!!!!", name) } + #[tauri::command] fn resize(w: u32, h: u32, window: tauri::Window) -> Result<(), String> { window.set_size(Size::Physical(tauri::PhysicalSize { width: w, height: h })) @@ -27,6 +28,16 @@ fn resize(w: u32, h: u32, window: tauri::Window) -> Result<(), String> { Ok(()) } +#[tauri::command] +fn center_window(window: tauri::Window) -> Result<(), String> { + window.center() + // window.set_size(tauri:Size::Physical(())) + // window.set_size(tauri::Size::Physical(Size::Physical(()) )) + .map_err(|e| e.to_string())?; + Ok(()) +} + + #[tauri::command] fn open_exe(exe_path: String, auth_token: String) -> Result<(), String> { Command::new(exe_path) @@ -103,7 +114,7 @@ fn main() { } _ => {} }) - .invoke_handler(tauri::generate_handler![greet, close_splashscreen, open_exe, resize]) + .invoke_handler(tauri::generate_handler![greet, close_splashscreen, open_exe, resize, center_window]) .run(tauri::generate_context!()) .expect("error while running tauri application"); } \ No newline at end of file diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 5dbab95..f07da8b 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "FinalCypher Launcher", - "version": "0.1.0" + "version": "0.2.2" }, "tauri": { "allowlist": { diff --git a/src/App.vue b/src/App.vue index 6a71a31..27567ca 100644 --- a/src/App.vue +++ b/src/App.vue @@ -52,9 +52,10 @@ import Loader from "./components/Loader.vue" import { sendEmailVerification } from 'firebase/auth' import { mapGetters } from "vuex" - import { appCacheDir } from '@tauri-apps/api/path'; + import { appCacheDir } from '@tauri-apps/api/path' import { checkUpdate, installUpdate } from '@tauri-apps/api/updater' import { relaunch } from '@tauri-apps/api/process' + import { invoke } from '@tauri-apps/api/tauri' import { listen, TauriEvent } from "@tauri-apps/api/event" import { Command } from "@tauri-apps/api/shell" import axios from 'axios' @@ -136,10 +137,14 @@ console.log('WS connected and opened.') let clientExists = (await axios.get('http://localhost:6212/clientExists')).data.exists - let { clientVersion, launcherVersion } = (await axios.get('http://localhost:6212/getVersions')).data - this.$store.commit('SET_CLIENT_VERSION', clientVersion) - this.$store.commit('SET_LAUNCHER_VERSION', launcherVersion) - + try { + let { clientVersion, launcherVersion } = (await axios.get('http://localhost:6212/getVersions')).data + this.$store.commit('SET_CLIENT_VERSION', clientVersion) + this.$store.commit('SET_LAUNCHER_VERSION', launcherVersion) + } catch(err) { + this.$store.commit('SET_CLIENT_VERSION', "0.1.3") + this.$store.commit('SET_LAUNCHER_VERSION', "0.1.9") + } // this.logs = clientExists if(!clientExists){ this.connection.send(JSON.stringify({ @@ -216,6 +221,29 @@ child.kill(); }) }) + + try { + const { shouldUpdate, manifest } = await checkUpdate() + if (shouldUpdate) { + // display dialog + console.log(manifest) + await invoke('resize', { w: 465 , h: 590 }) + await invoke('center_window') + this.$router.push({ name: 'Updater' }) + await installUpdate() + await relaunch() + } else { + let self = this + setTimeout(async() => { + this.$store.commit('SET_IS_SPLASH', false) + console.log(this.$store.state) + await invoke('resize', { w: 1500 , h: 800 }) + await invoke('center_window') + }, 4000) + } + } catch (error) { + console.log(error) + } } } diff --git a/src/components/Titlebar.vue b/src/components/Titlebar.vue index 7441014..a54a420 100644 --- a/src/components/Titlebar.vue +++ b/src/components/Titlebar.vue @@ -1,5 +1,5 @@