From 041ffb7462eef86f12c0fa4a82ba02ab6b6d5669 Mon Sep 17 00:00:00 2001 From: lencx Date: Fri, 3 Feb 2023 01:11:56 +0800 Subject: [PATCH] fix: conf error (#295) --- src-tauri/src/conf.rs | 9 ++++++++- src-tauri/src/scripts/export.js | 13 +++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/conf.rs b/src-tauri/src/conf.rs index 99349d2..56e0439 100644 --- a/src-tauri/src/conf.rs +++ b/src-tauri/src/conf.rs @@ -76,7 +76,14 @@ impl AppConf { pub fn read() -> Self { match std::fs::read_to_string(Self::file_path()) { - Ok(v) => serde_json::from_str::(&v).unwrap(), + Ok(v) => { + if let Ok(v2) = serde_json::from_str::(&v) { + v2 + } else { + error!("conf_read_parse_error"); + Self::default() + } + } Err(err) => { error!("conf_read_error: {}", err); Self::default() diff --git a/src-tauri/src/scripts/export.js b/src-tauri/src/scripts/export.js index 08bf45b..fc96abd 100644 --- a/src-tauri/src/scripts/export.js +++ b/src-tauri/src/scripts/export.js @@ -274,7 +274,8 @@ function setIcon(type) { png: ``, pdf: ``, md: ``, - copy: `` + copy: ``, + cpok: `` }[type]; } @@ -289,12 +290,14 @@ function copyBtns() { btn.innerHTML = setIcon('copy'); i.querySelector('.self-end').appendChild(btn); btn.onclick = () => { - copyToClipboard(i?.innerText?.trim() || ''); + copyToClipboard(i?.innerText?.trim() || '', btn); } }) } -function copyToClipboard(text) { +function copyToClipboard(text, btn) { + window.clearTimeout(window.__cpTimeout); + btn.innerHTML = setIcon('cpok'); if (navigator.clipboard) { navigator.clipboard.writeText(text); } else { @@ -308,7 +311,9 @@ function copyToClipboard(text) { document.execCommand('copy', true); document.body.removeChild(textarea); } - message('Copied to clipboard'); + window.__cpTimeout = setTimeout(() => { + btn.innerHTML = setIcon('copy'); + }, 1000); } if (