Skip to content

Commit a4aacc1

Browse files
authored
feat: support context menu in debug mode
1 parent 9aa7d23 commit a4aacc1

7 files changed

Lines changed: 47 additions & 18 deletions

File tree

docs/content.en/docs/release-notes/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Information about release notes of Coco App is provided here.
2020
- feat: add extension uninstall option in settings #855
2121
- feat: impl extension settings 'hide_before_open' #862
2222
- feat: index both en/zh_CN app names and show app name in chosen language #875
23+
- feat: support context menu in debug mode #882
2324

2425
### 🐛 Bug fix
2526

src-tauri/Cargo.lock

Lines changed: 26 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ sysinfo = "0.35.2"
108108
indexmap = { version = "2.10.0", features = ["serde"] }
109109
strum = { version = "0.27.2", features = ["derive"] }
110110
sys-locale = "0.3.2"
111+
tauri-plugin-prevent-default = "1"
111112

112113
[target."cfg(target_os = \"macos\")".dependencies]
113114
tauri-nspanel = { git = "https://github.com/ahkohd/tauri-nspanel", branch = "v2" }
@@ -134,4 +135,4 @@ semver = { version = "1", features = ["serde"] }
134135

135136
[target."cfg(target_os = \"windows\")".dependencies]
136137
enigo="0.3"
137-
windows = { version = "0.61.3", features = ["Win32_Foundation", "Win32_System_Com", "Win32_System_Ole", "Win32_System_Search", "Win32_UI_Shell_PropertiesSystem", "Win32_Data"] }
138+
windows = { version = "0.61.3", features = ["Win32_Foundation", "Win32_System_Com", "Win32_System_Ole", "Win32_System_Search", "Win32_UI_Shell_PropertiesSystem", "Win32_Data"] }

src-tauri/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ mod util;
1212
use crate::common::register::SearchSourceRegistry;
1313
use crate::common::{CHECK_WINDOW_LABEL, MAIN_WINDOW_LABEL, SETTINGS_WINDOW_LABEL};
1414
use crate::server::servers::{load_or_insert_default_server, load_servers_token};
15+
use crate::util::prevent_default;
1516
use autostart::change_autostart;
1617
use lazy_static::lazy_static;
1718
use std::sync::Mutex;
@@ -92,7 +93,8 @@ pub fn run() {
9293
.build(),
9394
)
9495
.plugin(tauri_plugin_windows_version::init())
95-
.plugin(tauri_plugin_opener::init());
96+
.plugin(tauri_plugin_opener::init())
97+
.plugin(prevent_default::init());
9698

9799
// Conditional compilation for macOS
98100
#[cfg(target_os = "macos")]

src-tauri/src/util/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub(crate) mod app_lang;
22
pub(crate) mod file;
33
pub(crate) mod platform;
4+
pub(crate) mod prevent_default;
45
pub(crate) mod system_lang;
56
pub(crate) mod updater;
67

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pub fn init() -> tauri::plugin::TauriPlugin<tauri::Wry> {
2+
#[cfg(debug_assertions)]
3+
{
4+
use tauri_plugin_prevent_default::Flags;
5+
6+
tauri_plugin_prevent_default::Builder::new()
7+
.with_flags(Flags::all().difference(Flags::CONTEXT_MENU))
8+
.build()
9+
}
10+
11+
#[cfg(not(debug_assertions))]
12+
tauri_plugin_prevent_default::init()
13+
}

src/routes/outlet.tsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import { useEffect } from "react";
22
import { Outlet, useLocation } from "react-router-dom";
33
import { useTranslation } from "react-i18next";
4-
import {
5-
useAsyncEffect,
6-
useEventListener,
7-
useMount,
8-
useTextSelection,
9-
} from "ahooks";
4+
import { useAsyncEffect, useEventListener, useMount } from "ahooks";
105
import { isArray, isString } from "lodash-es";
116

127
import { useAppStore } from "@/stores/appStore";
@@ -95,15 +90,6 @@ export default function LayoutOutlet() {
9590

9691
useSettingsWindow();
9792

98-
const { text: selectionText } = useTextSelection();
99-
100-
// Disable right-click for production environment
101-
useEventListener("contextmenu", (event) => {
102-
if (import.meta.env.DEV || selectionText) return;
103-
104-
event.preventDefault();
105-
});
106-
10793
useModifierKeyPress();
10894

10995
useEventListener("unhandledrejection", ({ reason }) => {

0 commit comments

Comments
 (0)