From 62ce7819938b8383e779d6ed2539e90568739d78 Mon Sep 17 00:00:00 2001 From: "844143714@qq,com" <844143714@qq,com> Date: Thu, 30 Apr 2026 01:49:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20AppKiller=20=E5=BC=95?= =?UTF-8?q?=E8=B5=B7=E7=9A=84=E6=AD=BB=E5=BE=AA=E7=8E=AF=E5=B4=A9=E6=BA=83?= =?UTF-8?q?=E5=92=8C=E5=89=8D=E7=AB=AF=E8=A7=A3=E6=9E=90=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/print_demo.html | 27 ++++++++++--------- .../com/stand/standapp/utils/AppKiller.kt | 17 +++++++----- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/app/src/main/assets/print_demo.html b/app/src/main/assets/print_demo.html index 24a48fd..39016e4 100644 --- a/app/src/main/assets/print_demo.html +++ b/app/src/main/assets/print_demo.html @@ -503,22 +503,23 @@ showPttResult("[回调] " + msg); }; - // ES6 特性测试函数 + // ES6 特性测试函数(通过 eval 避免阻塞旧版 JS 引擎整体解析) function testES6Features() { try { - const arr = [1, 2, 3]; - const [a, ...rest] = arr; - let sum = rest.reduce((acc, val) => acc + val, 0); - const myMap = new Map(); - myMap.set('key', `Sum is ${sum}`); - - new Promise((resolve) => { - setTimeout(() => resolve(myMap.get('key')), 100); - }).then(res => { - alert(`ES6 引擎测试成功!\n解构: a=${a}\nPromise/Map 返回: ${res}`); - }); + eval("\ + const arr = [1, 2, 3];\ + const [a, ...rest] = arr;\ + let sum = rest.reduce((acc, val) => acc + val, 0);\ + const myMap = new Map();\ + myMap.set('key', `Sum is ${sum}`);\ + new Promise((resolve) => {\ + setTimeout(() => resolve(myMap.get('key')), 100);\ + }).then(res => {\ + alert(`ES6 引擎测试成功!\\n解构: a=${a}\\nPromise/Map 返回: ${res}`);\ + });\ + "); } catch(e) { - alert("ES6 测试失败: " + e.message); + alert("ES6 测试失败 (当前环境可能不支持): " + e.message); } } function addExitText() { diff --git a/app/src/main/java/com/stand/standapp/utils/AppKiller.kt b/app/src/main/java/com/stand/standapp/utils/AppKiller.kt index 305af7a..1098190 100644 --- a/app/src/main/java/com/stand/standapp/utils/AppKiller.kt +++ b/app/src/main/java/com/stand/standapp/utils/AppKiller.kt @@ -5,7 +5,12 @@ import timber.log.Timber object AppKiller { + private var isKilling = false + fun killApp(context: Context, isCrash: Boolean = false) { + if (isKilling) return + isKilling = true + Timber.tag("AppKiller").i("Starting app cleanup. isCrash: $isCrash") try { @@ -30,12 +35,6 @@ object AppKiller { Timber.tag("AppKiller").e(e, "Printer close failed") } - try { - LogManager.shutdown() - } catch (e: Exception) { - // ignore - } - Timber.tag("AppKiller").i("Cleanup finished. Killing process.") if (!isCrash) { @@ -44,6 +43,12 @@ object AppKiller { } catch (e: Exception) {} } + try { + // LogManager.shutdown() 会关闭其内部的线程池 + // 调用后绝对不能再使用 Timber 打印日志,否则会抛出 RejectedExecutionException 导致死循环 + LogManager.shutdown() + } catch (e: Exception) {} + android.os.Process.killProcess(android.os.Process.myPid()) }