diff --git a/android-app/android/app/src/main/java/com/woer/smartscale/MainActivity.java b/android-app/android/app/src/main/java/com/woer/smartscale/MainActivity.java index 3009db9..a8c5e5e 100644 --- a/android-app/android/app/src/main/java/com/woer/smartscale/MainActivity.java +++ b/android-app/android/app/src/main/java/com/woer/smartscale/MainActivity.java @@ -43,6 +43,9 @@ public class MainActivity extends Activity { webView.setBackgroundColor(Color.rgb(248, 250, 248)); webView.setWebViewClient(new WebViewClient()); webView.setWebChromeClient(new WebChromeClient()); + // 工业终端只响应点击操作,禁止长按选择文字、弹出菜单及震动反馈。 + webView.setLongClickable(false); + webView.setHapticFeedbackEnabled(false); // 开启应用运行、接口访问和本地配置所需的 WebView 能力。 WebSettings settings = webView.getSettings(); diff --git a/app/globals.css b/app/globals.css index faa88b0..eb5c24d 100644 --- a/app/globals.css +++ b/app/globals.css @@ -11,9 +11,16 @@ --cream: #f2f4ee; } -* { box-sizing: border-box; } +* { + box-sizing: border-box; + /* 禁止所有页面长按选择文字及弹出系统复制菜单。 */ + -webkit-touch-callout: none; + -webkit-user-select: none; + user-select: none; +} html { background: #dfe8e2; } body { margin: 0; color: var(--ink); font-family: Arial, "PingFang SC", "Microsoft YaHei", sans-serif; } +img, a { -webkit-user-drag: none; } button, input { font: inherit; } button { cursor: pointer; } button:disabled { cursor: not-allowed; opacity: .55; } diff --git a/tests/rendered-html.test.mjs b/tests/rendered-html.test.mjs index e095e93..840bb65 100644 --- a/tests/rendered-html.test.mjs +++ b/tests/rendered-html.test.mjs @@ -51,3 +51,22 @@ test("正式代码不包含历史人员、机台或重量模拟数据", async () assert.match(page, /evaluateStability\(stableSamples\.current\)/); assert.match(utilities, /返回值统一为千克/); }); + +test("网页和 Android 原生层均禁用长按功能", async () => { + const [css, androidActivity] = await Promise.all([ + readFile(new URL("../app/globals.css", import.meta.url), "utf8"), + readFile( + new URL( + "../android-app/android/app/src/main/java/com/woer/smartscale/MainActivity.java", + import.meta.url, + ), + "utf8", + ), + ]); + + assert.match(css, /-webkit-touch-callout:\s*none/); + assert.match(css, /-webkit-user-select:\s*none/); + assert.match(css, /user-select:\s*none/); + assert.match(androidActivity, /webView\.setLongClickable\(false\)/); + assert.match(androidActivity, /webView\.setHapticFeedbackEnabled\(false\)/); +});