From 6c105fdbd4ae91e13839456329ca432010874c19 Mon Sep 17 00:00:00 2001 From: "zeankun.dev" Date: Sat, 5 Nov 2022 18:51:50 +0700 Subject: [PATCH] add stop button --- language/am.json | 1 + language/de.json | 1 + language/en.json | 1 + language/es.json | 1 + language/id.json | 1 + language/jp.json | 1 + language/nl.json | 1 + language/sw.json | 1 + script/main.js | 83 +++++++++++++++++++++++++---------------- views/css/index.css | 20 ++++++++++ views/css/variables.css | 2 + 11 files changed, 80 insertions(+), 33 deletions(-) diff --git a/language/am.json b/language/am.json index 380ffde..85b6d6b 100644 --- a/language/am.json +++ b/language/am.json @@ -9,6 +9,7 @@ "downloads": "ውርዶች", "noDownloads": "ምንም ውርዶች የሉም። በቅርቡ ተመልሰው ይመልከቱ።", "play": "ይጫወቱ", + "stop": "ጨዋታ አቁም", "downloadAndInstall": "አውርድና ጫን", "refreshStore": "ሱቅ አድስ", "wineConfig": "የወይን ውቅር", diff --git a/language/de.json b/language/de.json index cbd4a94..fa7c9b8 100644 --- a/language/de.json +++ b/language/de.json @@ -9,6 +9,7 @@ "downloads": "Download", "noDownloads": "Keine Downloads. Schau bald wieder vorbei!", "play": "Spielen", + "stop": "Spiel beenden", "downloadAndInstall": "Herunterladen und installieren", "refreshStore": "Geschäft aktualisieren", "wineConfig": "Wine-Konfiguration", diff --git a/language/en.json b/language/en.json index 1aa2e76..8c7befd 100644 --- a/language/en.json +++ b/language/en.json @@ -9,6 +9,7 @@ "downloads": "Downloads", "noDownloads": "No downloads. Check back soon!", "play": "Play", + "stop": "Stop Game", "downloadAndInstall": "Download and Install", "refreshStore": "Refresh Store", "wineConfig": "Wine Configuration", diff --git a/language/es.json b/language/es.json index 4779e97..e2b3601 100644 --- a/language/es.json +++ b/language/es.json @@ -9,6 +9,7 @@ "downloads": "Descargas", "noDownloads": "Sin descargas. ¡Vuelve a consultar pronto!", "play": "Tocar", + "stop": "Detener el juego", "downloadAndInstall": "Descargar e instalar", "refreshStore": "Actualizar tienda", "wineConfig": "Configuración del Wine", diff --git a/language/id.json b/language/id.json index 8be7f02..a2ae8d5 100644 --- a/language/id.json +++ b/language/id.json @@ -9,6 +9,7 @@ "downloads": "Unduhan", "noDownloads": "Tidak ada unduhan. Coba lagi nanti.", "play": "Mainkan", + "stop": "Hentikan permainan", "downloadAndInstall": "Unduh dan pasang", "refreshStore": "Segarkan Toko", "wineConfig": "Konfigurasi Wine", diff --git a/language/jp.json b/language/jp.json index 7cdd0fd..8c7e29e 100644 --- a/language/jp.json +++ b/language/jp.json @@ -9,6 +9,7 @@ "downloads": "ダウンロード", "noDownloads": "ダウンロードはありません。 すぐにもう一度確認してください", "play": "遊ぶ", + "stop": "ゲームを停止", "downloadAndInstall": "ダウンロードとインストール", "refreshStore": "リフレッシュショップ", "wineConfig": "ワイン構成", diff --git a/language/nl.json b/language/nl.json index 37bee0a..aeb05f4 100644 --- a/language/nl.json +++ b/language/nl.json @@ -9,6 +9,7 @@ "downloads": "Downloads", "noDownloads": "Geen downloads. Kom snel terug.", "play": "Spelen", + "stop": "Spel stoppen", "downloadAndInstall": "Download en installeer", "refreshStore": "Winkel vernieuwen", "wineConfig": "Wine configuratie", diff --git a/language/sw.json b/language/sw.json index 1ac6ca5..2e643ac 100644 --- a/language/sw.json +++ b/language/sw.json @@ -9,6 +9,7 @@ "downloads": "Vipakuliwa", "noDownloads": "Hakuna vipakuliwa. Angalia tena hivi karibuni!", "play": "Cheza", + "stop": "Acha Mchezo", "downloadAndInstall": "Pakua na usakinishe", "refreshStore": "Onyesha upya duka", "wineConfig": "Mpangilio wa Wine", diff --git a/script/main.js b/script/main.js index 3dbad32..edcf919 100644 --- a/script/main.js +++ b/script/main.js @@ -39,6 +39,7 @@ let cus; let downAndI; let libText; let language; +let stop; fetch(app.getPath('userData') + '/config.json') .then(response => response.json()) .then(data => { @@ -68,6 +69,7 @@ fetch(app.getPath('userData') + '/config.json') document.getElementById('ref-internet').innerHTML = data.translations.refInternet document.getElementById('rec-for-u').innerHTML = data.translations.recForU play = data.translations.play; + stop = data.translations.stop; downAndI = data.translations.downloadAndInstall fetchStores(); getGames(); @@ -235,6 +237,7 @@ openMenu(event, 'home') }); }); }*/ + var proc; function getGames() { fetch(app.getPath('userData') + '/games.json') .then(response => response.json()) @@ -260,41 +263,55 @@ openMenu(event, 'home') gameButton.className = "play"; gameButton.innerHTML = `${play}`; gameButton.onclick = function() { - seconds = 0; - secElapsed.style.display = 'block'; - const timer = setInterval(function() { - seconds++ - secElapsed.innerHTML = `${seconds} seconds elapsed.
` - if (seconds > 59) notifDisplay('You have exceeded the maximum time of 1 minute.', 'Please take a rest') - }, 1000) - // downgraded to electron v4, now we can require child_process. - const { spawn } = require('child_process'); - if (game.enableWine != true) { - const process = spawn(game.exec, game.args); - process.on('error', (err) => { - console.log(err) - notifDisplay(err, 'Failed to launch!') - }); - process.on('exit', () => { - clearInterval(timer) - }) - } else { - if (platform == 'win32') notifDisplay('Wine is only available for Mac or Linux', 'Your OS is unsupported'); - else { - var cmdExist = require('command-exists'); - if (cmdExist('wine')) { - const process = spawn('wine', [game.exec]); - process.on('error', (err) => { - console.log(err) - notifDisplay(err, 'Failed to launch!') - }); - process.on('exit', () => { - clearInterval(timer) - }) - } else { - notifDisplay('Wine cannot be searched. Close Graycrown, install wine, then try again.', 'Unsupported!') + if (gameButton.className == "play") { + seconds = 0; + secElapsed.style.display = 'block'; + const timer = setInterval(function() { + seconds++ + secElapsed.innerHTML = `${seconds} seconds elapsed.
` + if (seconds > 59) notifDisplay('You have exceeded the maximum time of 1 minute.', 'Please take a rest') + }, 1000) + // downgraded to electron v4, now we can require child_process. + const { spawn } = require('child_process'); + if (game.enableWine != true) { + proc = spawn(game.exec, game.args); + gameButton.className = "stop"; + gameButton.innerHTML = stop; + proc.on('error', (err) => { + console.log(err) + notifDisplay(err, 'Failed to launch!') + }); + proc.on('exit', () => { + clearInterval(timer) + gameButton.className = "play"; + gameButton.innerHTML = play; + }) + } else { + if (platform == 'win32') notifDisplay('Wine is only available for Mac or Linux', 'Your OS is unsupported'); + else { + var cmdExist = require('command-exists'); + if (cmdExist('wine')) { + proc = spawn('wine', [game.exec]); + gameButton.className = "stop"; + gameButton.innerHTML = stop; + proc.on('error', (err) => { + console.log(err) + notifDisplay(err, 'Failed to launch!') + }); + proc.on('exit', () => { + clearInterval(timer) + gameButton.className = "play"; + gameButton.innerHTML = play; + }) + } else { + notifDisplay('Wine cannot be searched. Close Graycrown, install wine, then try again.', 'Unsupported!') + } } } + } else { + const { spawn } = require('child_process'); + console.log("KILLING PROCESS") + proc.kill() } } gameDisplay.appendChild(secElapsed) diff --git a/views/css/index.css b/views/css/index.css index 3cd0623..8f39b94 100644 --- a/views/css/index.css +++ b/views/css/index.css @@ -315,6 +315,7 @@ h1 { border-radius: 15px; color: var(--main-text); width: 240px; + transition: all 0.2s ease; cursor: url('../../assets/pointer.png'), auto; -webkit-animation: scale-down-center 0.4s cubic-bezier(0.250, 0.460, 0.450, 0.940) both; animation: scale-down-center 0.4s cubic-bezier(0.250, 0.460, 0.450, 0.940) both; @@ -324,6 +325,25 @@ h1 { -webkit-animation: scale-up-center 0.4s cubic-bezier(0.250, 0.460, 0.450, 0.940) both; animation: scale-up-center 0.4s cubic-bezier(0.250, 0.460, 0.450, 0.940) both; } +.stop { + background-color: var(--stop-color); + border: none; + display: inline-block; + font-family: system-ui; + padding: 10px; + border-radius: 15px; + color: var(--main-text); + width: 240px; + cursor: url('../../assets/pointer.png'), auto; + transition: all 0.2s ease; + -webkit-animation: scale-down-center 0.4s cubic-bezier(0.250, 0.460, 0.450, 0.940) both; + animation: scale-down-center 0.4s cubic-bezier(0.250, 0.460, 0.450, 0.940) both; +} +.stop:hover { + background-color: var(--stop-color-hover); + -webkit-animation: scale-up-center 0.4s cubic-bezier(0.250, 0.460, 0.450, 0.940) both; + animation: scale-up-center 0.4s cubic-bezier(0.250, 0.460, 0.450, 0.940) both; +} .store-display { background: var(--main-color); margin: 10px; diff --git a/views/css/variables.css b/views/css/variables.css index 7865394..1422009 100644 --- a/views/css/variables.css +++ b/views/css/variables.css @@ -57,6 +57,8 @@ --main-text: #fff; --play-color: #16c716; --play-color-hover: #2ae42a; + --stop-color: #ff0b0b; + --stop-color-hover: #ff2323; --download-color: #0362fc; --download-color-hover: #1e71f7; }