-
-
Notifications
You must be signed in to change notification settings - Fork 25
feat: add customizable keyboard shortcuts via textpod.toml #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,6 +59,30 @@ struct AppState { | |
| notes_file: PathBuf, | ||
| } | ||
|
|
||
| #[derive(Deserialize, Default)] | ||
| struct Config { | ||
| #[serde(default)] | ||
| shortcuts: ShortcutsConfig, | ||
| } | ||
|
|
||
| #[derive(Deserialize, Serialize)] | ||
| struct ShortcutsConfig { | ||
| #[serde(default = "default_save_shortcut")] | ||
| save: String, | ||
| } | ||
|
|
||
| impl Default for ShortcutsConfig { | ||
| fn default() -> Self { | ||
| Self { | ||
| save: default_save_shortcut(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn default_save_shortcut() -> String { | ||
| "Ctrl+Enter".to_string() | ||
| } | ||
|
Comment on lines
+62
to
+84
|
||
|
|
||
| const CONTENT_LENGTH_LIMIT: usize = 500 * 1024 * 1024; // allow uploading up to 500mb files... overkill? | ||
|
|
||
| #[tokio::main] | ||
|
|
@@ -74,6 +98,17 @@ async fn main() { | |
| } | ||
| } | ||
|
|
||
| let config: Config = match fs::read_to_string("textpod.toml") { | ||
| Ok(contents) => match toml::from_str(&contents) { | ||
| Ok(cfg) => cfg, | ||
| Err(e) => { | ||
| error!("failed to parse textpod.toml: {e}; using defaults"); | ||
| Config::default() | ||
| } | ||
| }, | ||
| Err(_) => Config::default(), | ||
| }; | ||
|
|
||
| if let Err(e) = fs::create_dir_all("attachments") { | ||
| error!( | ||
| "could not create attachments directory in {}: {e}", | ||
|
|
@@ -83,10 +118,15 @@ async fn main() { | |
| } | ||
|
|
||
| let favicon = Base64Display::new(FAVICON_SVG, &STANDARD); | ||
| let html = INDEX_HTML.replace( | ||
| "{{FAVICON}}", | ||
| format!("data:image/svg+xml;base64,{favicon}").as_str(), | ||
| ); | ||
| let shortcuts_json = | ||
| serde_json::to_string(&config.shortcuts).expect("failed to serialize shortcuts config"); | ||
| let html = INDEX_HTML | ||
| .replace( | ||
| "{{FAVICON}}", | ||
| format!("data:image/svg+xml;base64,{favicon}").as_str(), | ||
| ) | ||
| .replace("{{SHORTCUTS_CONFIG}}", &shortcuts_json) | ||
| .replace("{{SAVE_SHORTCUT_DISPLAY}}", &config.shortcuts.save); | ||
|
freetonik marked this conversation as resolved.
|
||
|
|
||
| let notes = Arc::new(Mutex::new(load_notes(&args.notes_file))); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The matchShortcut function has a case-sensitivity issue. The event.key property returns capitalized key names (e.g., "Enter", "Escape") but the function performs a strict equality comparison without normalizing the case. This means a configuration like
save = "Cmd+enter"(lowercase) would fail to match. Consider normalizing both sides to lowercase for the key comparison, or document that key names must match the exact case returned by event.key (e.g., "Enter" not "enter").