wip add apps to clipboard history ignore list

This commit is contained in:
Sergey Kurdin 2024-07-30 23:07:08 -04:00
parent d8c0c09112
commit 4ca78f601e
13 changed files with 102 additions and 11 deletions

View File

@ -1,4 +1,3 @@
-- Rollback for clipboard_history table
CREATE TABLE clipboard_history_new ( CREATE TABLE clipboard_history_new (
history_id VARCHAR(50) PRIMARY KEY NOT NULL, history_id VARCHAR(50) PRIMARY KEY NOT NULL,
title VARCHAR(255), title VARCHAR(255),

View File

@ -1,2 +1,2 @@
-- Adding new column to items table -- Adding new column to clipboard_history table
ALTER TABLE clipboard_history ADD COLUMN history_options TEXT; ALTER TABLE clipboard_history ADD COLUMN history_options TEXT;

View File

@ -0,0 +1,49 @@
-- down.sql
CREATE TABLE clipboard_history_new (
history_id VARCHAR(50) PRIMARY KEY NOT NULL,
title VARCHAR(255),
value VARCHAR(255),
value_preview VARCHAR(150),
value_more_preview_lines INT DEFAULT 0,
value_more_preview_chars INT DEFAULT 0,
value_hash VARCHAR(255),
is_image BOOLEAN DEFAULT FALSE,
image_path_full_res VARCHAR(255),
image_data_low_res BLOB,
image_preview_height INT DEFAULT 0,
image_height INT DEFAULT 0,
image_width INT DEFAULT 0,
image_data_url VARCHAR(255),
image_hash VARCHAR(255),
is_image_data BOOLEAN DEFAULT FALSE,
is_masked BOOLEAN DEFAULT FALSE,
is_text BOOLEAN DEFAULT FALSE,
is_code BOOLEAN DEFAULT FALSE,
is_link BOOLEAN DEFAULT FALSE,
is_video BOOLEAN DEFAULT FALSE,
has_emoji BOOLEAN DEFAULT FALSE,
has_masked_words BOOLEAN DEFAULT FALSE,
is_pinned BOOLEAN DEFAULT FALSE,
is_favorite BOOLEAN DEFAULT FALSE,
links TEXT,
detected_language VARCHAR(20),
pinned_order_number INT DEFAULT 0,
created_at BIGINT NOT NULL,
updated_at BIGINT NOT NULL,
created_date TIMESTAMP NOT NULL,
updated_date TIMESTAMP NOT NULL,
history_options TEXT
);
INSERT INTO clipboard_history_new SELECT
history_id, title, value, value_preview, value_more_preview_lines,
value_more_preview_chars, value_hash, is_image, image_path_full_res,
image_data_low_res, image_preview_height, image_height, image_width,
image_data_url, image_hash, is_image_data, is_masked, is_text, is_code,
is_link, is_video, has_emoji, has_masked_words, is_pinned, is_favorite,
links, detected_language, pinned_order_number, created_at, updated_at,
created_date, updated_date, history_options
FROM clipboard_history;
DROP TABLE clipboard_history;
ALTER TABLE clipboard_history_new RENAME TO clipboard_history;

View File

@ -0,0 +1,3 @@
-- Adding new column to clipboard_history table
ALTER TABLE clipboard_history ADD COLUMN copied_from_app VARCHAR(255);

View File

@ -234,6 +234,7 @@ Set: Set
Set Password: Set Password Set Password: Set Password
Show Large View: Show Large View Show Large View: Show Large View
Show all: Show all Show all: Show all
'Source:': 'Source:'
Split History Window: Split History Window Split History Window: Split History Window
Star: Star Star: Star
Star Selected: Star Selected Star Selected: Star Selected

View File

@ -11,6 +11,7 @@ Add Tab: Add Tab
Add to: Add to Add to: Add to
Add to Menu: Add to Menu Add to Menu: Add to Menu
AddTo: AddTo:
Add to Ignore: Add to Ignore
Clip on Board: Clip on Board Clip on Board: Clip on Board
Paste Menu: Paste Menu Paste Menu: Paste Menu
After: After After: After

View File

@ -320,6 +320,11 @@ export function ClipboardHistoryRowComponent({
: undefined, : undefined,
}} }}
ref={isDragPreview && !(isHovering || isSelected) ? null : setNodeRef} ref={isDragPreview && !(isHovering || isSelected) ? null : setNodeRef}
title={
clipboard?.copiedFromApp && isHovering
? `${t('Source:')} ${clipboard?.copiedFromApp}`
: ''
}
{...(isSelected || isHovering ? listeners : {})} {...(isSelected || isHovering ? listeners : {})}
> >
<Box ref={rowRef}> <Box ref={rowRef}>
@ -1014,6 +1019,7 @@ export function ClipboardHistoryRowComponent({
</ContextMenuTrigger> </ContextMenuTrigger>
<ClipboardHistoryRowContextMenu <ClipboardHistoryRowContextMenu
historyId={clipboard.historyId} historyId={clipboard.historyId}
copiedFromApp={clipboard.copiedFromApp}
isMasked={clipboard.isMasked} isMasked={clipboard.isMasked}
setSavingItem={setSavingItem} setSavingItem={setSavingItem}
value={clipboard.value} value={clipboard.value}

View File

@ -16,6 +16,7 @@ import {
ArrowDownToLine, ArrowDownToLine,
CheckSquare, CheckSquare,
ClipboardPaste, ClipboardPaste,
ClipboardX,
EqualNot, EqualNot,
Expand, Expand,
GalleryVertical, GalleryVertical,
@ -64,6 +65,7 @@ interface ClipboardHistoryRowContextMenuProps {
arrLinks: string[] arrLinks: string[]
isImage: boolean isImage: boolean
isText: boolean isText: boolean
copiedFromApp: string | null
isMasked: boolean isMasked: boolean
isImageData: boolean isImageData: boolean
isMp3: boolean | undefined isMp3: boolean | undefined
@ -88,6 +90,7 @@ interface ClipboardHistoryRowContextMenuProps {
export default function ClipboardHistoryRowContextMenu({ export default function ClipboardHistoryRowContextMenu({
historyId, historyId,
value, value,
copiedFromApp,
arrLinks, arrLinks,
isImage, isImage,
isText, isText,
@ -354,6 +357,25 @@ export default function ClipboardHistoryRowContextMenu({
</ContextMenuSubContent> </ContextMenuSubContent>
</ContextMenuSub> </ContextMenuSub>
{copiedFromApp && (
<ContextMenuSub>
<ContextMenuSubTrigger>{copiedFromApp} ...</ContextMenuSubTrigger>
<ContextMenuSubContent>
<ContextMenuItem
onClick={() => {
hasDashboardItemCreate.value = CreateDashboardItemType.CLIP
createClipHistoryItemIds.value = [historyId]
}}
>
{t('AddTo:::Add to Ignore', { ns: 'contextMenus' })}
<div className="ml-auto pl-2">
<ClipboardX size={15} />
</div>
</ContextMenuItem>
</ContextMenuSubContent>
</ContextMenuSub>
)}
<ContextMenuSeparator /> <ContextMenuSeparator />
{(arrLinks?.length > 0 && !detectedLanguage) || {(arrLinks?.length > 0 && !detectedLanguage) ||
(isText && ( (isText && (

View File

@ -21,6 +21,7 @@ export type ClipboardHistoryItem = {
noLinkCard: boolean noLinkCard: boolean
} | null } | null
historyOptions: string | null historyOptions: string | null
copiedFromApp: string | null
title: string | null title: string | null
value: string | null value: string | null

View File

@ -95,19 +95,15 @@ where
.and_then(|s| s.value_bool) .and_then(|s| s.value_bool)
.unwrap_or(true); .unwrap_or(true);
let copied_from_app = match get_active_window() {
Ok(active_window) => Some(active_window.app_name),
Err(()) => None,
};
if let Ok(mut text) = clipboard_text { if let Ok(mut text) = clipboard_text {
text = text.trim().to_string(); text = text.trim().to_string();
if !text.is_empty() { if !text.is_empty() {
match get_active_window() {
Ok(active_window) => {
println!("active window: {:#?}", active_window);
}
Err(()) => {
println!("error occurred while getting the active window");
}
}
let mut is_excluded = false; let mut is_excluded = false;
if let Some(setting) = settings_map.get("isExclusionListEnabled") { if let Some(setting) = settings_map.get("isExclusionListEnabled") {
if let Some(value_bool) = setting.value_bool { if let Some(value_bool) = setting.value_bool {
@ -185,6 +181,7 @@ where
text, text,
detect_options, detect_options,
should_auto_star_on_double_copy, should_auto_star_on_double_copy,
copied_from_app,
)); ));
} }
} }
@ -192,6 +189,7 @@ where
do_refresh_clipboard = Some(history_service::add_clipboard_history_from_image( do_refresh_clipboard = Some(history_service::add_clipboard_history_from_image(
image_binary, image_binary,
should_auto_star_on_double_copy, should_auto_star_on_double_copy,
copied_from_app,
)); ));
} }

View File

@ -115,6 +115,7 @@ pub struct UpdatedItemData {
pub struct UpdatedHistoryData { pub struct UpdatedHistoryData {
pub history_id: Option<String>, pub history_id: Option<String>,
pub history_options: Option<String>, pub history_options: Option<String>,
pub copied_from_app: Option<String>,
pub title: Option<String>, pub title: Option<String>,
pub value: Option<String>, pub value: Option<String>,
pub is_text: Option<bool>, pub is_text: Option<bool>,
@ -274,6 +275,7 @@ pub struct ClipboardHistory {
pub created_date: NaiveDateTime, pub created_date: NaiveDateTime,
pub updated_date: NaiveDateTime, pub updated_date: NaiveDateTime,
pub history_options: Option<String>, pub history_options: Option<String>,
pub copied_from_app: Option<String>,
} }
#[derive( #[derive(

View File

@ -35,6 +35,7 @@ diesel::table! {
created_date -> Timestamp, created_date -> Timestamp,
updated_date -> Timestamp, updated_date -> Timestamp,
history_options -> Nullable<Text>, history_options -> Nullable<Text>,
copied_from_app -> Nullable<Text>,
} }
} }

View File

@ -102,6 +102,7 @@ pub struct RecentClipboardHistoryData {
pub struct ClipboardHistoryWithMetaData { pub struct ClipboardHistoryWithMetaData {
pub history_id: String, pub history_id: String,
pub history_options: Option<String>, pub history_options: Option<String>,
pub copied_from_app: Option<String>,
pub title: Option<String>, pub title: Option<String>,
pub value: Option<String>, pub value: Option<String>,
pub value_preview: Option<String>, pub value_preview: Option<String>,
@ -177,6 +178,7 @@ impl ClipboardHistoryWithMetaData {
created_date: history.created_date, created_date: history.created_date,
updated_date: history.updated_date, updated_date: history.updated_date,
history_options: history.history_options, history_options: history.history_options,
copied_from_app: history.copied_from_app,
link_metadata, link_metadata,
}; };
@ -188,6 +190,7 @@ impl ClipboardHistoryWithMetaData {
pub fn add_clipboard_history_from_image( pub fn add_clipboard_history_from_image(
image_data: ImageData, image_data: ImageData,
should_auto_star_on_double_copy: bool, should_auto_star_on_double_copy: bool,
_copied_from_app: Option<String>,
) -> String { ) -> String {
let image = match ImageBuffer::from_raw( let image = match ImageBuffer::from_raw(
image_data image_data
@ -277,6 +280,7 @@ pub fn add_clipboard_history_from_image(
_preview_height.try_into().unwrap(), _preview_height.try_into().unwrap(),
_image_height.try_into().unwrap(), _image_height.try_into().unwrap(),
_image_width.try_into().unwrap(), _image_width.try_into().unwrap(),
_copied_from_app,
); );
let _ = insert_clipboard_history(&new_history); let _ = insert_clipboard_history(&new_history);
@ -320,10 +324,12 @@ fn create_new_history(
_image_preview_height: i32, _image_preview_height: i32,
_image_height: i32, _image_height: i32,
_image_width: i32, _image_width: i32,
_copied_from_app: Option<String>,
) -> ClipboardHistory { ) -> ClipboardHistory {
ClipboardHistory { ClipboardHistory {
history_id: _history_id, history_id: _history_id,
history_options: None, history_options: None,
copied_from_app: _copied_from_app,
title: None, title: None,
value: None, value: None,
value_preview: None, value_preview: None,
@ -362,6 +368,7 @@ pub fn add_clipboard_history_from_text(
text: String, text: String,
detect_options: LanguageDetectOptions, detect_options: LanguageDetectOptions,
should_auto_star_on_double_copy: bool, should_auto_star_on_double_copy: bool,
_copied_from_app: Option<String>,
) -> String { ) -> String {
let mut _is_image_data = is_base64_image(&text); let mut _is_image_data = is_base64_image(&text);
let mut _text_as_json = String::new(); let mut _text_as_json = String::new();
@ -498,6 +505,7 @@ pub fn add_clipboard_history_from_text(
let new_history = ClipboardHistory { let new_history = ClipboardHistory {
history_id: new_history_id, history_id: new_history_id,
history_options: None, history_options: None,
copied_from_app: _copied_from_app,
title: None, title: None,
value: if !_text_as_json.is_empty() { value: if !_text_as_json.is_empty() {
Some(_text_as_json) Some(_text_as_json)