settings modal for font size

This commit is contained in:
catto 2024-04-26 21:33:37 +02:00
parent 61d1776239
commit d6700e3066
3 changed files with 49 additions and 4 deletions

View File

@ -89,6 +89,17 @@ fn init_settings() {
.unwrap();
}
#[tauri::command]
fn save_settings(settings: String) {
fs::write(
home_dir()
.unwrap()
.join(".snotes-data/snotes-settings.json"),
settings,
)
.unwrap();
}
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
@ -101,7 +112,8 @@ fn main() {
delete_specific_note,
update_specific_note,
init_settings,
load_settings
load_settings,
save_settings
])
.run(tauri::generate_context!())
.expect("error while running tauri application");

View File

@ -8,7 +8,7 @@
},
"package": {
"productName": "snotes-deck",
"version": "0.0.9"
"version": "0.0.10"
},
"tauri": {
"allowlist": {

View File

@ -618,9 +618,42 @@ async function exportNote(contents: string | null) {
function handleOpenSettingsModal() {
const modalBg = document.getElementById("id-modal-bg");
const setingsModalContainer = document.getElementById("settings-modal-container");
const settingsFontsizeInput = document.getElementById("fontsize-setting-input");
const settingsFontsizeInput = document.getElementById("fontsize-setting-input") as HTMLInputElement;
if (modalBg && setingsModalContainer && settingsFontsizeInput) {
console.log("settings")
modalBg.style.display = "block";
setingsModalContainer.style.display = "block";
settingsFontsizeInput.focus();
settingsFontsizeInput.value = settings ? settings.fontSize : "16";
modalBg.addEventListener("click", () => {
setingsModalContainer.style.display = "none";
modalBg.style.display = "none";
});
settingsFontsizeInput.addEventListener("keydown", async (event: KeyboardEvent) => {
if (event.key === "Enter") {
console.log("saving settings..")
settings = {
fontSize: settingsFontsizeInput.value
}
await invoke("save_settings", {
settings: JSON.stringify(settings)
});
if (createNoteContentEl) {
createNoteContentEl.style.fontSize = settingsFontsizeInput.value + "px";
} else {
console.error("failed to get createNoteContentEl")
}
setingsModalContainer.style.display = "none";
modalBg.style.display = "none";
}
if (event.key === "Escape") {
setingsModalContainer.style.display = "none";
modalBg.style.display = "none";
}
});
} else {
console.error("Failed to get Settings Modal elements.");
}