mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 19:17:03 +00:00
changes
This commit is contained in:
1 parent
11df8697b1
commit
c090fb595f
61 files changed
+52534
-107
No files matched your search
+29
-15
@@ -6,9 +6,12 @@ mod pdf;
|
||||
mod project;
|
||||
mod proofing;
|
||||
|
||||
#[cfg(desktop)]
|
||||
use tauri::menu::{Menu, MenuItemBuilder, MenuItemKind, PredefinedMenuItem, SubmenuBuilder};
|
||||
#[cfg(desktop)]
|
||||
use tauri::{Emitter, Runtime};
|
||||
|
||||
#[cfg(desktop)]
|
||||
fn build_menu<R: Runtime>(handle: &tauri::AppHandle<R>) -> tauri::Result<Menu<R>> {
|
||||
let menu = Menu::default(handle)?;
|
||||
let new_book = MenuItemBuilder::with_id("new-book", "New Book")
|
||||
@@ -62,31 +65,42 @@ fn build_menu<R: Runtime>(handle: &tauri::AppHandle<R>) -> tauri::Result<Menu<R>
|
||||
pub fn run() {
|
||||
let context = tauri::generate_context!();
|
||||
|
||||
#[cfg_attr(mobile, allow(unused_mut))]
|
||||
let mut builder = tauri::Builder::default()
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.plugin(tauri_plugin_process::init());
|
||||
.plugin(tauri_plugin_dialog::init());
|
||||
|
||||
if context.config().plugins.0.contains_key("updater") {
|
||||
builder = builder.plugin(tauri_plugin_updater::Builder::new().build());
|
||||
#[cfg(desktop)]
|
||||
{
|
||||
builder = builder.plugin(tauri_plugin_process::init());
|
||||
if context.config().plugins.0.contains_key("updater") {
|
||||
builder = builder.plugin(tauri_plugin_updater::Builder::new().build());
|
||||
}
|
||||
}
|
||||
|
||||
builder
|
||||
builder = builder
|
||||
.manage(proofing::new_state())
|
||||
.manage(gdrive::GDriveState::default())
|
||||
.setup(|app| {
|
||||
gdrive::init_session(app.handle());
|
||||
Ok(())
|
||||
})
|
||||
.menu(|handle| build_menu(handle))
|
||||
.on_menu_event(|app, event| {
|
||||
if matches!(
|
||||
event.id().0.as_str(),
|
||||
"new-book" | "export-pdf" | "export-epub" | "check-updates"
|
||||
) {
|
||||
app.emit("menu-action", event.id().0.as_str()).ok();
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
#[cfg(desktop)]
|
||||
{
|
||||
builder = builder
|
||||
.menu(|handle| build_menu(handle))
|
||||
.on_menu_event(|app, event| {
|
||||
if matches!(
|
||||
event.id().0.as_str(),
|
||||
"new-book" | "export-pdf" | "export-epub" | "check-updates"
|
||||
) {
|
||||
app.emit("menu-action", event.id().0.as_str()).ok();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
builder
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
epub::package_epub,
|
||||
epub::unzip_epub,
|
||||
|
||||
@@ -59,11 +59,17 @@ fn read_words(contents: &str, set: &mut HashSet<String>) {
|
||||
for line in contents.lines() {
|
||||
let word = line.trim();
|
||||
if !word.is_empty() && !word.starts_with('#') {
|
||||
set.insert(word.to_string());
|
||||
set.insert(word.to_lowercase());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn load_tech(app: &tauri::AppHandle, set: &mut HashSet<String>) {
|
||||
if let Ok(contents) = dict_file(app, "tech.txt") {
|
||||
read_words(&contents, set);
|
||||
}
|
||||
}
|
||||
|
||||
fn load_custom(app: &tauri::AppHandle) -> HashSet<String> {
|
||||
let mut set = HashSet::new();
|
||||
if let Ok(path) = custom_dict_path(app) {
|
||||
@@ -98,6 +104,10 @@ fn is_word_char(c: char) -> bool {
|
||||
c.is_alphabetic()
|
||||
}
|
||||
|
||||
fn has_irregular_case(word: &str) -> bool {
|
||||
word.chars().skip(1).any(|c| c.is_uppercase())
|
||||
}
|
||||
|
||||
fn is_apostrophe(c: char) -> bool {
|
||||
c == '\'' || c == '\u{2019}'
|
||||
}
|
||||
@@ -128,7 +138,7 @@ fn collect_spelling(
|
||||
}
|
||||
let end = i;
|
||||
let word: String = chars[start..end].iter().collect();
|
||||
if speller.check(&word) || custom.contains(&word) {
|
||||
if has_irregular_case(&word) || speller.check(&word) || custom.contains(&word.to_lowercase()) {
|
||||
continue;
|
||||
}
|
||||
let mut suggestions = Vec::new();
|
||||
@@ -184,10 +194,12 @@ pub async fn proof_text(
|
||||
let state = app.state::<ProofState>();
|
||||
let mut guard = state.lock().map_err(|e| e.to_string())?;
|
||||
if guard.is_none() {
|
||||
let mut custom = load_custom(&app);
|
||||
load_tech(&app, &mut custom);
|
||||
*guard = Some(Engine {
|
||||
speller: None,
|
||||
harper: None,
|
||||
custom: load_custom(&app),
|
||||
custom,
|
||||
});
|
||||
}
|
||||
let engine = guard.as_mut().unwrap();
|
||||
@@ -232,7 +244,7 @@ pub fn remember_word(
|
||||
|
||||
let mut guard = state.inner().lock().map_err(|e| e.to_string())?;
|
||||
if let Some(engine) = guard.as_mut() {
|
||||
engine.custom.insert(word);
|
||||
engine.custom.insert(word.to_lowercase());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user