diff --git a/GrepolisRemoteControl.user.js b/GrepolisRemoteControl.user.js index f60ec63..292459b 100644 --- a/GrepolisRemoteControl.user.js +++ b/GrepolisRemoteControl.user.js @@ -6,6 +6,8 @@ // @author Dimitrios // @match https://*.grepolis.com/game/* // @grant unsafeWindow +// @updateURL https://git.haunter-pets.top/haunter/grepo-remote/raw/branch/main/GrepolisRemoteControl.user.js +// @downloadURL https://git.haunter-pets.top/haunter/grepo-remote/raw/branch/main/GrepolisRemoteControl.user.js // ==/UserScript== (function () { @@ -128,11 +130,11 @@ // ---------------------------------------------------------------- // Report command result back to relay // ---------------------------------------------------------------- - function reportResult(cmdId, success, message) { + function reportResult(cmdId, status, message) { fetch(`${BASE_URL}/api/commands/${cmdId}/result`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ status: success ? 'done' : 'failed', message }) + body: JSON.stringify({ status, message }) }).catch(e => log(`reportResult failed: ${e}`)); } @@ -153,7 +155,7 @@ const hasCurator = uw.GameDataPremium?.isAdvisorActivated?.('curator'); const maxQueue = hasCurator ? 7 : 2; if (queueLen >= maxQueue) { - return { ok: false, msg: `Build queue full (${queueLen}/${maxQueue})` }; + return { ok: false, requeue: true, msg: `Build queue full (${queueLen}/${maxQueue})` }; } // Check resources @@ -248,8 +250,9 @@ result = { ok: false, msg: `Exception: ${e.message}` }; } - log(`Command #${cmd.id} result: ${result.ok ? '✅' : '❌'} ${result.msg}`); - reportResult(cmd.id, result.ok, result.msg); + const finalStatus = result.requeue ? 'pending' : (result.ok ? 'done' : 'failed'); + log(`Command #${cmd.id} result: ${finalStatus === 'done' ? '✅' : (finalStatus === 'pending' ? '⏳' : '❌')} ${result.msg}`); + reportResult(cmd.id, finalStatus, result.msg); } // ---------------------------------------------------------------- diff --git a/routes/dashboard.py b/routes/dashboard.py index 65a7b45..6e000a6 100644 --- a/routes/dashboard.py +++ b/routes/dashboard.py @@ -113,15 +113,14 @@ def create_command(): # ------------------------------------------------------------------ # DELETE /dashboard/commands/ -# Cancel a pending command from the dashboard. +# Fully delete a command from the dashboard history. # ------------------------------------------------------------------ @dashboard.route('/dashboard/commands/', methods=['DELETE']) def cancel_command(cmd_id): conn = get_db() conn.execute(''' - UPDATE commands SET status = 'cancelled', updated_at = ? - WHERE id = ? AND status = 'pending' - ''', (datetime.utcnow().isoformat(), cmd_id)) + DELETE FROM commands WHERE id = ? + ''', (cmd_id,)) conn.commit() conn.close() return jsonify({'ok': True}) diff --git a/templates/dashboard.html b/templates/dashboard.html index 0887161..81ed26f 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -489,9 +489,7 @@ function renderLog(cmds) { ? `Build: ${p.building_id}` : `Recruit: ${p.amount}x ${p.unit_id}`; const statusClass = `status-${cmd.status}`; - const cancelBtn = cmd.status === 'pending' - ? `` - : ''; + const cancelBtn = ``; return ` #${cmd.id}