Skip to content

Commit

Permalink
Merge pull request #29 from station0x/dev
Browse files Browse the repository at this point in the history
0.2.2
  • Loading branch information
ElRakabawi authored Jan 21, 2023
2 parents 691ad0d + 3a7e53b commit ea15fcd
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 45 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "final_cypher",
"private": true,
"version": "0.1.9",
"version": "0.2.2",
"type": "module",
"bin": "dist/server.js",
"scripts": {
Expand Down
14 changes: 11 additions & 3 deletions server/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -219,7 +221,8 @@ websocketServer.on("connection", (webSocketClient) => {
name,
isUpdating,
dirSize,
readyToPlay: false
readyToPlay: false,
totalUpdateFiles: assetsURL
}))
time = now
}
Expand All @@ -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 }))
Expand Down
13 changes: 12 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
Expand All @@ -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)
Expand Down Expand Up @@ -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");
}
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"package": {
"productName": "FinalCypher Launcher",
"version": "0.1.0"
"version": "0.2.2"
},
"tauri": {
"allowlist": {
Expand Down
38 changes: 33 additions & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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)
}
}
}
</script>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Titlebar.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div v-if="!$store.state.isSplash" data-tauri-drag-region class="titlebar">
<div v-if="!isUpdater" data-tauri-drag-region class="titlebar">
<div @click="minimizeWindow" class="titlebar-button" id="titlebar-minimize">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 12H4"></path></svg>
</div>
Expand Down Expand Up @@ -27,6 +27,7 @@ import { appWindow } from '@tauri-apps/api/window'
}
},
created() {
console.log(this.$route.fullPath)
if(this.$route.fullPath === '/updater') this.isUpdater = true
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ document.documentElement.classList.add('dark')
// disable dev mode
if(isProd) {
// disable conext-menu and reloads
// document.addEventListener('contextmenu', event => event.preventDefault());
// document.addEventListener('keydown', (e) => {
// e = e || window.event;
// if(e.keyCode == 116 || (e.ctrlKey && e.keyCode == 82)){
// e.preventDefault();
// }
// });
document.addEventListener('contextmenu', event => event.preventDefault());
document.addEventListener('keydown', (e) => {
e = e || window.event;
if(e.keyCode == 116 || (e.ctrlKey && e.keyCode == 82)){
e.preventDefault();
}
});
}
// document.addEventListener('DOMContentLoaded', async () => {
// await invoke("close_splashscreen");
Expand Down
2 changes: 1 addition & 1 deletion src/views/Auth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
</form>
<div class="h-full w-full flex flex-col gap-1 justify-end mb-4 px-14 text-center">
<div v-if="$store.state.launcherVersion" class="text-xs text-white text-opacity-20 tracking-normal hover:text-opacity-40">Launcher Version v{{ $store.state.launcherVersion.split('v')[1] }}</div>
<div v-if="$store.state.clientVersion" class="text-xs text-white text-opacity-20 tracking-normal hover:text-opacity-40">Client Version v{{ $store.state.clientVersion }}</div>
<div v-if="$store.state.clientVersion" class="text-xs text-white text-opacity-20 tracking-normal hover:text-opacity-40">Client Version {{ $store.state.clientVersion }}</div>
</div>
</div>
<div id="right-section" class="flex items-center col-span-7 justify-center px-4 py-6 bg-primary-600 lg:py-0 sm:px-0">
Expand Down
11 changes: 9 additions & 2 deletions src/views/Updater.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,23 @@
import { appWindow } from '@tauri-apps/api/window'
import { emit } from '@tauri-apps/api/event'
import { listen } from '@tauri-apps/api/event'
import { relaunch } from '@tauri-apps/api/process'
export default {
methods: {
minimizeWindow() {
appWindow.minimize()
}
},
created() {
listen('tauri://update-status', function (res) {
async created() {
listen('tauri://update-status', async function (res) {
console.log('New status: ', res)
if(true) // some condition
{
await invoke('resize', { w: 465 , h: 590 })
await relaunch()
}
})
emit('tauri://update-install')
}
Expand Down
23 changes: 0 additions & 23 deletions src/views/games/FinalCypher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,11 @@

<script>
import { appWindow } from '@tauri-apps/api/window'
import { Command, open } from '@tauri-apps/api/shell'
import { invoke } from '@tauri-apps/api/tauri'
import { auth } from '../../../firebaseConfig'
import PlayBtn from '../../components/PlayBtn.vue'
import InstallProgress from '../../components/InstallProgress.vue'
import axios from 'axios'
import { checkUpdate, installUpdate } from '@tauri-apps/api/updater'
import { relaunch } from '@tauri-apps/api/process'
import Logo from '../Logo.vue'
// import { getAuth } from '@firebase/auth'
Expand Down Expand Up @@ -176,26 +173,6 @@ export default {
},
async created() {
window.addEventListener('click', this.onClickApp)
try {
const { shouldUpdate, manifest } = await checkUpdate()
if (shouldUpdate) {
// display dialog
console.log(manifest)
await invoke('resize', { w: 465 , h: 590 })
this.$router.push({ name: 'Updater' })
// await installUpdate()
// install complete, restart the app
// await relaunch()
} else {
let self = this
setTimeout(()=> {
self.splash = false
self.$store.commit('SET_IS_SPLASH', false)
}, 4000)
}
} catch (error) {
console.log(error)
}
},
destroyed() {
window.removeEventListener('click', this.onClickApp)
Expand Down

0 comments on commit ea15fcd

Please sign in to comment.