From 9fa4b53cf7f2a40402179bb39eb9afbc172c54e5 Mon Sep 17 00:00:00 2001 From: Kareem Ebrahim <89863279+kareemmahlees@users.noreply.github.com> Date: Wed, 21 Aug 2024 20:54:22 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20logging=20=E2=9C=A8=F0=9F=94=8A=20(#87)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/rare-islands-cheer.md | 5 + Cargo.lock | 306 +++++++++++++++++- Cargo.toml | 1 + apps/core/package.json | 1 + apps/core/src-tauri/Cargo.toml | 3 + apps/core/src-tauri/capabilities/main.json | 19 +- .../core/src-tauri/src/commands/connection.rs | 9 +- apps/core/src-tauri/src/commands/fs.rs | 15 +- apps/core/src-tauri/src/commands/row.rs | 7 +- apps/core/src-tauri/src/main.rs | 46 ++- apps/core/src-tauri/src/state.rs | 6 +- apps/core/src/bindings.ts | 2 +- .../components/keybindings-tab.tsx | 1 - .../components/sheets/create-row-sheet.tsx | 7 +- apps/core/src/keybindings/manager.ts | 12 +- apps/core/src/lib/utils.tsx | 6 +- apps/core/src/main.tsx | 10 +- apps/core/src/routes/__root.tsx | 22 +- bun.lockb | Bin 442088 -> 442496 bytes crates/handlers/Cargo.toml | 1 + crates/handlers/src/handler.rs | 51 ++- crates/handlers/src/mysql/mod.rs | 53 ++- crates/handlers/src/postgres/mod.rs | 59 ++-- crates/handlers/src/sqlite/mod.rs | 58 ++-- crates/keybindings/Cargo.toml | 1 + crates/keybindings/src/fs.rs | 4 +- crates/lib/Cargo.toml | 1 + crates/lib/src/events.rs | 4 +- crates/lib/src/fs.rs | 16 +- crates/settings/Cargo.toml | 1 + crates/settings/src/fs.rs | 4 + crates/settings/src/schema.rs | 2 +- 32 files changed, 554 insertions(+), 179 deletions(-) create mode 100644 .changeset/rare-islands-cheer.md diff --git a/.changeset/rare-islands-cheer.md b/.changeset/rare-islands-cheer.md new file mode 100644 index 00000000..62279d13 --- /dev/null +++ b/.changeset/rare-islands-cheer.md @@ -0,0 +1,5 @@ +--- +"@tablex/core": patch +--- + +Adds logging to stdout and to log file diff --git a/Cargo.lock b/Cargo.lock index f98dd6f5..16dd60bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -82,6 +82,23 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" +[[package]] +name = "android_log-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ecc8056bf6ab9892dcd53216c83d1597487d7dacac16c8df6b877d127df9937" + +[[package]] +name = "android_logger" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b07e8e73d720a1f2e4b6014766e6039fd2e96a4fa44e2a78d0e1fa2ff49826" +dependencies = [ + "android_log-sys", + "env_filter", + "log", +] + [[package]] name = "android_system_properties" version = "0.1.5" @@ -173,6 +190,12 @@ dependencies = [ "x11rb", ] +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + [[package]] name = "ashpd" version = "0.8.1" @@ -414,6 +437,18 @@ dependencies = [ "serde", ] +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + [[package]] name = "block" version = "0.1.6" @@ -451,6 +486,30 @@ dependencies = [ "piper", ] +[[package]] +name = "borsh" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d4d6dafc1a3bb54687538972158f07b2c948bc57d5890df22c0739098b3028" +dependencies = [ + "borsh-derive", + "cfg_aliases 0.1.1", +] + +[[package]] +name = "borsh-derive" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf4918709cc4dd777ad2b6303ed03cb37f3ca0ccede8c1b0d28ac6db8f4710e0" +dependencies = [ + "once_cell", + "proc-macro-crate 2.0.2", + "proc-macro2", + "quote", + "syn 2.0.72", + "syn_derive", +] + [[package]] name = "brotli" version = "6.0.0" @@ -478,6 +537,39 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +[[package]] +name = "byte-unit" +version = "5.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ac19bdf0b2665407c39d82dbc937e951e7e2001609f0fb32edd0af45a2d63e" +dependencies = [ + "rust_decimal", + "serde", + "utf8-width", +] + +[[package]] +name = "bytecheck" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23cdc57ce23ac53c931e88a43d06d070a6fd142f2617be5855eb75efc9beb1c2" +dependencies = [ + "bytecheck_derive", + "ptr_meta", + "simdutf8", +] + +[[package]] +name = "bytecheck_derive" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3db406d29fbcd95542e92559bed4d8ad92636d1ca8b3b72ede10b4bcc010e659" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "bytemuck" version = "1.16.1" @@ -611,6 +703,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "cfg_aliases" version = "0.2.1" @@ -1284,6 +1382,16 @@ dependencies = [ "syn 2.0.72", ] +[[package]] +name = "env_filter" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" +dependencies = [ + "log", + "regex", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -1374,6 +1482,15 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "fern" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9f0c14694cbd524c8720dd69b0e3179344f04ebb5f90f2e4a440c6ea3b2f1ee" +dependencies = [ + "log", +] + [[package]] name = "field-offset" version = "0.3.6" @@ -1493,6 +1610,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + [[package]] name = "futf" version = "0.1.5" @@ -1942,6 +2065,9 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash 0.7.8", +] [[package]] name = "hashbrown" @@ -2500,6 +2626,9 @@ name = "log" version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +dependencies = [ + "value-bag", +] [[package]] name = "loom" @@ -2828,6 +2957,15 @@ dependencies = [ "syn 2.0.72", ] +[[package]] +name = "num_threads" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" +dependencies = [ + "libc", +] + [[package]] name = "objc" version = "0.2.7" @@ -3498,6 +3636,26 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "ptr_meta" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1" +dependencies = [ + "ptr_meta_derive", +] + +[[package]] +name = "ptr_meta_derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "qoi" version = "0.4.1" @@ -3571,6 +3729,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + [[package]] name = "rand" version = "0.7.3" @@ -3760,6 +3924,15 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +[[package]] +name = "rend" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71fe3824f5629716b1589be05dacd749f6aa084c87e00e016714a8cdfccc997c" +dependencies = [ + "bytecheck", +] + [[package]] name = "reqwest" version = "0.12.5" @@ -3843,6 +4016,35 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rkyv" +version = "0.7.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cba464629b3394fc4dbc6f940ff8f5b4ff5c7aef40f29166fd4ad12acbc99c0" +dependencies = [ + "bitvec", + "bytecheck", + "bytes", + "hashbrown 0.12.3", + "ptr_meta", + "rend", + "rkyv_derive", + "seahash", + "tinyvec", + "uuid", +] + +[[package]] +name = "rkyv_derive" +version = "0.7.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7dddfff8de25e6f62b9d64e6e432bf1c6736c57d20323e15ee10435fbda7c65" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "rsa" version = "0.6.1" @@ -3863,6 +4065,22 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rust_decimal" +version = "1.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1790d1c4c0ca81211399e0e0af16333276f375209e71a37b67698a373db5b47a" +dependencies = [ + "arrayvec", + "borsh", + "bytes", + "num-traits", + "rand 0.8.5", + "rkyv", + "serde", + "serde_json", +] + [[package]] name = "rustc-demangle" version = "0.1.24" @@ -4006,6 +4224,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "seahash" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" + [[package]] name = "security-framework" version = "2.11.1" @@ -4261,6 +4485,12 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" +[[package]] +name = "simdutf8" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" + [[package]] name = "siphasher" version = "0.3.11" @@ -4299,7 +4529,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d623bff5d06f60d738990980d782c8c866997d9194cfe79ecad00aa2f76826dd" dependencies = [ "bytemuck", - "cfg_aliases", + "cfg_aliases 0.2.1", "core-graphics 0.23.2", "foreign-types 0.5.0", "js-sys", @@ -4619,6 +4849,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn_derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1329189c02ff984e9736652b1631330da25eaa6bc639089ed4915d25446cbe7b" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.72", +] + [[package]] name = "sync_wrapper" version = "1.0.1" @@ -4644,6 +4886,7 @@ version = "0.3.4" dependencies = [ "clap", "json-patch", + "log", "open", "regex", "serde", @@ -4656,9 +4899,11 @@ dependencies = [ "tauri-plugin-clipboard-manager", "tauri-plugin-dialog", "tauri-plugin-fs", + "tauri-plugin-log", "tauri-plugin-shell", "tauri-plugin-updater", "tauri-specta", + "time", "tokio", "tx_handlers", "tx_keybindings", @@ -4718,6 +4963,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "tar" version = "0.4.41" @@ -4850,9 +5101,9 @@ dependencies = [ [[package]] name = "tauri-plugin" -version = "2.0.0-beta.19" +version = "2.0.0-rc.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1abe0b85472516d1033ba251ac81b9f18f02725aadcaad697c8b727e6505a6ad" +checksum = "ec01af01098a286d3e430c1fa947bfd77bc8011ecb209438af4444b02d82b29e" dependencies = [ "anyhow", "glob", @@ -4918,6 +5169,28 @@ dependencies = [ "uuid", ] +[[package]] +name = "tauri-plugin-log" +version = "2.0.0-rc.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380d27f23c39cde6a73024e65d8ec9b5b0af861e968dbe16b3aad86cd2c578e5" +dependencies = [ + "android_logger", + "byte-unit", + "cocoa 0.25.0", + "fern", + "log", + "objc", + "serde", + "serde_json", + "serde_repr", + "swift-rs", + "tauri", + "tauri-plugin", + "thiserror", + "time", +] + [[package]] name = "tauri-plugin-shell" version = "2.0.0-beta.9" @@ -5162,7 +5435,9 @@ checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa 1.0.11", + "libc", "num-conv", + "num_threads", "powerfmt", "serde", "time-core", @@ -5455,6 +5730,7 @@ name = "tx_handlers" version = "0.3.4" dependencies = [ "async-trait", + "log", "serde_json", "sqlx", "tokio", @@ -5465,6 +5741,7 @@ dependencies = [ name = "tx_keybindings" version = "0.3.4" dependencies = [ + "log", "serde", "specta", "tauri", @@ -5478,6 +5755,7 @@ version = "0.3.4" dependencies = [ "async-trait", "chrono", + "log", "serde", "serde_json", "specta", @@ -5491,6 +5769,7 @@ dependencies = [ name = "tx_settings" version = "0.3.4" dependencies = [ + "log", "schemars", "serde", "serde_json", @@ -5639,6 +5918,12 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" +[[package]] +name = "utf8-width" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86bd8d4e895da8537e5315b8254664e6b769c4ff3db18321b297a1e7004392e3" + [[package]] name = "utf8parse" version = "0.2.2" @@ -5673,6 +5958,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "value-bag" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a84c137d37ab0142f0f2ddfe332651fdbf252e7b7dbb4e67b6c1f1b2e925101" + [[package]] name = "vcpkg" version = "0.2.15" @@ -6380,6 +6671,15 @@ dependencies = [ "x11-dl", ] +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + [[package]] name = "x11" version = "2.21.0" diff --git a/Cargo.toml b/Cargo.toml index ebc03d4f..9268836b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,3 +37,4 @@ sqlx = { version = "0.6.3", features = [ async-trait = "0.1.80" specta = { version = "2.0.0-rc.20", features = ["serde", "serde_json"] } tauri-specta = { version = "2.0.0-rc.17", features = ["derive", "typescript"] } +log = { version = "0.4.22" } diff --git a/apps/core/package.json b/apps/core/package.json index 4317bec0..3a182c4a 100644 --- a/apps/core/package.json +++ b/apps/core/package.json @@ -37,6 +37,7 @@ "@tauri-apps/plugin-clipboard-manager": "2.1.0-beta.5", "@tauri-apps/plugin-dialog": "^2.0.0-rc.0", "@tauri-apps/plugin-fs": "^2.0.0-beta.7", + "@tauri-apps/plugin-log": "^2.0.0-rc.0", "@tauri-apps/plugin-os": "2.0.0-beta.7", "@tauri-apps/plugin-shell": "2.0.0-beta.7", "@tauri-apps/plugin-updater": "^2.0.0-rc.0", diff --git a/apps/core/src-tauri/Cargo.toml b/apps/core/src-tauri/Cargo.toml index f205b494..a6c47804 100644 --- a/apps/core/src-tauri/Cargo.toml +++ b/apps/core/src-tauri/Cargo.toml @@ -36,6 +36,9 @@ tauri-plugin-shell = "2.0.0-beta.9" tauri-plugin-fs = "2.0.0-beta.11" tauri-plugin-updater = "2.0.0-beta.10" json-patch = "2.0.0" +tauri-plugin-log = "2.0.0-rc.0" +log = { workspace = true } +time = "0.3.36" [features] # this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled. diff --git a/apps/core/src-tauri/capabilities/main.json b/apps/core/src-tauri/capabilities/main.json index f111c4c2..c4faff67 100644 --- a/apps/core/src-tauri/capabilities/main.json +++ b/apps/core/src-tauri/capabilities/main.json @@ -15,12 +15,21 @@ "updater:allow-check", "clipboard-manager:allow-write-text", { - "identifier":"fs:allow-read-file", - "allow": [{"path": "*/*.(db|db3|s3db|sl3|sqlite|sqlite3)"}] + "identifier": "fs:allow-read-file", + "allow": [ + { + "path": "*/*.(db|db3|s3db|sl3|sqlite|sqlite3)" + } + ] }, { - "identifier": "fs:allow-read-text-file", - "allow": [{ "path": "$APPDATA/*.json" }] - } + "identifier": "fs:allow-read-text-file", + "allow": [ + { + "path": "$APPDATA/*.json" + } + ] + }, + "log:default" ] } \ No newline at end of file diff --git a/apps/core/src-tauri/src/commands/connection.rs b/apps/core/src-tauri/src/commands/connection.rs index e60422f1..89f89686 100644 --- a/apps/core/src-tauri/src/commands/connection.rs +++ b/apps/core/src-tauri/src/commands/connection.rs @@ -47,9 +47,11 @@ pub fn create_connection_record( conn_name, }; let id = Uuid::new_v4().to_string(); - contents.insert(id, connection); + contents.insert(id.clone(), connection); write_into_json(&connections_file_path, contents)?; + log::info!(id = id.as_str() ;"New connection created"); + Ok(String::from("Successfully created connection")) } @@ -64,7 +66,11 @@ pub fn delete_connection_record(app: tauri::AppHandle, conn_id: String) -> Resul .ok_or(TxError::Io(std::io::ErrorKind::Other.into()))?; write_into_json(&connections_file_path, contents)?; + log::info!(id = conn_id.as_str(); "Connection deleted"); + ConnectionsChanged.emit(&app).unwrap(); + log::debug!("Event emitted: {:?}", ConnectionsChanged); + Ok(String::from("Successfully deleted connection")) } @@ -169,6 +175,7 @@ pub fn get_connection_details(app: tauri::AppHandle, conn_id: String) -> Result< /// Make sure `connections.json` file exist, if not will create an empty json file for it. pub fn ensure_connections_file_exist(path: &PathBuf) -> Result<()> { if path.exists() { + log::debug!("{} exists, skipping creation.", CONNECTIONS_FILE_NAME); return Ok(()); } create_json_file_recursively(path)?; diff --git a/apps/core/src-tauri/src/commands/fs.rs b/apps/core/src-tauri/src/commands/fs.rs index ac074564..0dc606f6 100644 --- a/apps/core/src-tauri/src/commands/fs.rs +++ b/apps/core/src-tauri/src/commands/fs.rs @@ -27,6 +27,7 @@ pub fn open_in_external_editor(app: AppHandle, file: ConfigFile) -> Result<(), T ConfigFile::Keybindings => get_keybindings_file_path(&app)?, ConfigFile::Settings => get_settings_file_path(&app)?, }; + log::debug!("Opening {} in external editor.", path.to_str().unwrap()); Ok(open::that_detached(path)?) } @@ -39,6 +40,9 @@ pub fn load_settings_file(app: AppHandle) -> Result { merge(&mut default_settings, &settings); let settings = serde_json::from_value::(settings)?; + + log::debug!("Loaded settings."); + Ok(settings) } @@ -48,7 +52,14 @@ pub fn write_into_settings_file(app: AppHandle, settings: Value) -> Result<(), T let mut stored_settings = read_from_json::(&get_settings_file_path(&app)?)?; merge(&mut stored_settings, &settings); - write_into_json(&get_settings_file_path(&app)?, stored_settings)?; + let parsed_settings = serde_json::from_value::(stored_settings)?; + + if parsed_settings.page_size > 2000 { + log::warn!(page_size = parsed_settings.page_size;"Setting page size to a high value can cause performance issues."); + }; + + write_into_json(&get_settings_file_path(&app)?, parsed_settings)?; + log::info!("Settings updated."); Ok(()) } @@ -59,5 +70,7 @@ pub fn write_into_keybindings_file( keybindings: Vec, ) -> Result<(), TxError> { write_into_json(&get_keybindings_file_path(&app)?, keybindings)?; + log::info!("Keybindings updated."); + Ok(()) } diff --git a/apps/core/src-tauri/src/commands/row.rs b/apps/core/src-tauri/src/commands/row.rs index 8494256d..be0108fc 100644 --- a/apps/core/src-tauri/src/commands/row.rs +++ b/apps/core/src-tauri/src/commands/row.rs @@ -55,7 +55,8 @@ pub async fn delete_rows( .delete_rows(pool, pk_col_name, table_name, params) .await; if result.is_ok() { - TableContentsChanged.emit(&app).unwrap() + TableContentsChanged.emit(&app).unwrap(); + log::debug!("Event emitted: {:?}", TableContentsChanged); } result } @@ -81,7 +82,7 @@ pub async fn create_row( let values = data .values() .map(|value| { - // Hack: handle json quotation marks until a better + // HACK: handle json quotation marks until a better // solution is found. let mut value = value.to_string(); if value.starts_with("\"{") && value.ends_with("}\"") { @@ -99,6 +100,7 @@ pub async fn create_row( let result = handler.create_row(pool, table_name, columns, values).await; if result.is_ok() { TableContentsChanged.emit(&app).unwrap(); + log::debug!("Event emitted: {:?}", TableContentsChanged); } result } @@ -131,6 +133,7 @@ pub async fn update_row( .await; if result.is_ok() { TableContentsChanged.emit(&app).unwrap(); + log::debug!("Event emitted: {:?}", TableContentsChanged); } result } diff --git a/apps/core/src-tauri/src/main.rs b/apps/core/src-tauri/src/main.rs index e6a28d67..6a0ec286 100644 --- a/apps/core/src-tauri/src/main.rs +++ b/apps/core/src-tauri/src/main.rs @@ -7,23 +7,15 @@ mod state; #[cfg(not(debug_assertions))] mod updater; -// use commands::{ -// connection::{ -// connections_exist, create_connection_record, delete_connection_record, -// ensure_connections_file_exist, establish_connection, get_connection_details, -// get_connections, get_connections_file_path, test_connection, -// }, -// fs::{load_settings_file, open_in_external_editor}, -// row::{create_row, delete_rows, get_fk_relations, get_paginated_rows, update_row}, -// table::{execute_raw_query, get_columns_props, get_tables}, -// }; use commands::{connection::*, fs::*, row::*, table::*}; #[cfg(not(debug_assertions))] use updater::check_for_update; +use log::Level; use specta_typescript::{BigIntExportBehavior, Typescript}; use state::SharedState; use tauri::{async_runtime::Mutex, AppHandle, Manager, Window, WindowEvent}; +use tauri_plugin_log::{RotationStrategy, Target, TargetKind, TimezoneStrategy}; use tauri_specta::{collect_commands, collect_events, Builder}; use tx_keybindings::*; use tx_lib::{events::*, TxError}; @@ -97,6 +89,37 @@ fn main() { let (args, cmd) = cli::parse_cli_args(); let tauri_builder = tauri::Builder::default() + .plugin( + tauri_plugin_log::Builder::new() + .clear_targets() + .targets([ + Target::new(TargetKind::LogDir { file_name: None }).filter(|metadata| { + metadata.level() != Level::Debug + && metadata.level() != Level::Trace + && !metadata.target().starts_with("tao") + }), + Target::new(TargetKind::Stdout), + ]) + .max_file_size(2_000_000) + .format(|out, message, record| { + out.finish(format_args!( + "{} [{}] {}", + TimezoneStrategy::UseUtc + .get_now() + .format( + &time::format_description::parse( + "[year]-[month]-[day] [hour]:[minute]:[second]" + ) + .unwrap() + ) + .unwrap(), + record.level(), + message + )) + }) + .rotation_strategy(RotationStrategy::KeepAll) + .build(), + ) .plugin(tauri_plugin_fs::init()) .plugin(tauri_plugin_clipboard_manager::init()) .plugin(tauri_plugin_shell::init()) @@ -106,9 +129,10 @@ fn main() { .setup(move |app| { let app_handle = app.app_handle(); let rt = tokio::runtime::Runtime::new().unwrap(); - let _settings = load_settings_file(app_handle.clone())?; ensure_config_files_exist(app_handle)?; + let _settings = load_settings_file(app_handle.clone())?; + builder.mount_events(app); rt.block_on(cli::handle_cli_args(app_handle, args, cmd)); diff --git a/apps/core/src-tauri/src/state.rs b/apps/core/src-tauri/src/state.rs index 29200933..5129ea3b 100644 --- a/apps/core/src-tauri/src/state.rs +++ b/apps/core/src-tauri/src/state.rs @@ -15,13 +15,15 @@ pub struct SharedState { impl SharedState { pub async fn cleanup(&mut self) { if let Some(pool) = &self.pool { - pool.close().await + pool.close().await; + log::debug!("Connection pool closed."); } #[cfg(feature = "metax")] { if let Some(metax) = self.metax.take() { - metax.kill().expect("unable to kill sidecar") + metax.kill().expect("unable to kill sidecar"); + log::debug!("MetaX shutdown."); } } } diff --git a/apps/core/src/bindings.ts b/apps/core/src/bindings.ts index e50bd954..3c47554f 100644 --- a/apps/core/src/bindings.ts +++ b/apps/core/src/bindings.ts @@ -175,8 +175,8 @@ tableContentsChanged: "table-contents-changed" /** user-defined constants **/ -export const KEYBINDINGS_FILE_NAME = "keybindings.json" as const; export const SETTINGS_FILE_NAME = "settings.json" as const; +export const KEYBINDINGS_FILE_NAME = "keybindings.json" as const; /** user-defined types **/ diff --git a/apps/core/src/components/dialogs/preferences/components/keybindings-tab.tsx b/apps/core/src/components/dialogs/preferences/components/keybindings-tab.tsx index 79ceddc3..c4cb0e06 100644 --- a/apps/core/src/components/dialogs/preferences/components/keybindings-tab.tsx +++ b/apps/core/src/components/dialogs/preferences/components/keybindings-tab.tsx @@ -62,7 +62,6 @@ const KeybindingsTab = () => { size={"sm"} onClick={async () => { await commands.writeIntoKeybindingsFile(keybindings.bindings) - console.log(editedKeybindings) keybindings.reRegister(editedKeybindings) }} > diff --git a/apps/core/src/components/sheets/create-row-sheet.tsx b/apps/core/src/components/sheets/create-row-sheet.tsx index ff359dd4..e783152b 100644 --- a/apps/core/src/components/sheets/create-row-sheet.tsx +++ b/apps/core/src/components/sheets/create-row-sheet.tsx @@ -18,6 +18,7 @@ import { FormLabel, FormMessage } from "@/components/ui/form" +import { ScrollArea } from "@/components/ui/scroll-area" import { useGetGeneralColsData } from "@/hooks/row" import { useCreateRowSheetState } from "@/state/sheetState" import { zodResolver } from "@hookform/resolvers/zod" @@ -45,11 +46,13 @@ const AddRowBtn = ({ tableName }: AddRowBtnProps) => { - + Add new row - + + + diff --git a/apps/core/src/keybindings/manager.ts b/apps/core/src/keybindings/manager.ts index 758a7c60..be435466 100644 --- a/apps/core/src/keybindings/manager.ts +++ b/apps/core/src/keybindings/manager.ts @@ -4,6 +4,7 @@ import { KEYBINDINGS_FILE_NAME } from "@/bindings" import { BaseDirectory, readTextFile } from "@tauri-apps/plugin-fs" +import { debug } from "@tauri-apps/plugin-log" import hotkeys from "hotkeys-js" import { createContext, useContext } from "react" @@ -45,7 +46,12 @@ export class KeybindingsManager { ) if (binding) { this.registeredKeybindings.push(keybinding) - hotkeys(binding.shortcuts.join(","), keybinding.handler) + hotkeys(binding.shortcuts.join(","), (_, event) => { + debug( + `Keybinding activated: { shortcut: ${event.shortcut}, command: ${keybinding.command} }` + ) + keybinding.handler() + }) } }) } @@ -66,11 +72,11 @@ export class KeybindingsManager { } } -export const KeybindingsManagerContext = createContext(new KeybindingsManager()) +export const KeybindingsContext = createContext(new KeybindingsManager()) /** * A react context hook to access the {@link KeybindingsManager} from anywhere in the application. */ export const useKeybindings = () => { - return useContext(KeybindingsManagerContext) + return useContext(KeybindingsContext) } diff --git a/apps/core/src/lib/utils.tsx b/apps/core/src/lib/utils.tsx index 9e639514..36b28811 100644 --- a/apps/core/src/lib/utils.tsx +++ b/apps/core/src/lib/utils.tsx @@ -1,8 +1,9 @@ import type { ColumnProps, TxError } from "@/bindings" import ErrorDialog from "@/components/dialogs/error-dialog" import { Separator } from "@/components/ui/separator" +import { error } from "@tauri-apps/plugin-log" import { ErrorIcon, toast } from "react-hot-toast" -import { Drivers, type ConnectionStringParams } from "./types" +import { ConnectionStringParams, Drivers } from "./types" /** * creates connection string for the specified driver accordingly @@ -34,6 +35,9 @@ export function customToast( id?: string ) { if (commandResult.status === "error") { + error( + `message: ${commandResult.error.message}, details: ${commandResult.error.details}.` + ) return toast(

{commandResult.error.message}

diff --git a/apps/core/src/main.tsx b/apps/core/src/main.tsx index 499a32eb..910201bf 100644 --- a/apps/core/src/main.tsx +++ b/apps/core/src/main.tsx @@ -2,7 +2,9 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query" import { RouterProvider, createRouter } from "@tanstack/react-router" import ReactDOM from "react-dom/client" import "./index.css" +import { KeybindingsContext, KeybindingsManager } from "./keybindings/manager" import { routeTree } from "./routeTree.gen" +import { SettingsContext, SettingsManager } from "./settings/manager" // Set up a Router instance const router = createRouter({ @@ -18,6 +20,8 @@ declare module "@tanstack/react-router" { } const client = new QueryClient() +const keybindingsManager = new KeybindingsManager() +const settingsManager = new SettingsManager() const rootElement = document.getElementById("app")! @@ -25,7 +29,11 @@ if (!rootElement.innerHTML) { const root = ReactDOM.createRoot(rootElement) root.render( - + + + + + ) } diff --git a/apps/core/src/routes/__root.tsx b/apps/core/src/routes/__root.tsx index a54653d9..19c62e53 100644 --- a/apps/core/src/routes/__root.tsx +++ b/apps/core/src/routes/__root.tsx @@ -1,9 +1,4 @@ import { commands } from "@/bindings" -import { - KeybindingsManager, - KeybindingsManagerContext -} from "@/keybindings/manager" -import { SettingsContext, SettingsManager } from "@/settings/manager" import { createRootRoute, Outlet } from "@tanstack/react-router" import React, { Suspense } from "react" import { Toaster } from "react-hot-toast" @@ -18,23 +13,16 @@ const TanStackRouterDevtools = })) ) -const keybindingsManager = new KeybindingsManager() -const settingsManager = new SettingsManager() - export const Route = createRootRoute({ onEnter: commands.closeSplashscreen, component: () => { return (
- - - - - - -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2e=NHmQ2a`eznrv$L!en$T(%WSem1+4{)6{T|Kq&>9qYSUdD!$;5w0_@N$VyqJ-K2frm8D% zqVOuv{R3R5Y{OIg-M{qtwG}M^^TZ$osLO@VXuMbMDZn#l+F04v6(J=}9A>~o(L~Qo zOZdloy+u`Ve(KMAZU$1?qfh6GiKyb{f-KDiV(n<%FWz-5_?b^W+21+O2i+PM8Do#c zZiMUL?|=n=FTVHq`b>-JDp2Hor}=inyVP~`cjF3s`gZT`i!fgjFkkSb%3CQB9~Yw+ z(3wJ^73#48uJg?A zk9=lr{p`C-jUr@Q@(YcDErSYhoqz89`{tqRX6*aGh{KN*zrFs7fUd5C&=q^V8$En= z3;@~^6Pbv$U!gc#h{s&&0P{#Rj$V)47TRm}Yt=@iF%FYNaLeooaGjLiALV)AKLgIQT(4YW3o8H zf^K@IMZ|c$i)Z0DeA?nF953?5>#11Nt$u2}u6iyWZ}P;Ai=HphozIuJujnP(Kk6Rj zobsr9xu>(+GWX9SJ@4OWZmc}JQ8d=M<0nb9-{juC?NNzeu5;&K*1Cw%o7_)$?yNI| c&(|5jV(Mo1khY2Pe?r0kjADk?Y Result { - let rows = sqlx::query( - format!( - "SELECT * FROM {} limit {} offset {};", - table_name, - page_size, - page_index as i32 * page_size - ) - .as_str(), - ) - .fetch_all(pool) - .await?; - - let page_count_result = - sqlx::query(format!("SELECT COUNT(*) from {}", table_name).as_str()) - .fetch_one(pool) - .await?; + let query_str = format!( + "SELECT * FROM {} limit {} offset {};", + table_name, + page_size, + page_index as i32 * page_size + ); + + let rows = sqlx::query(&query_str).fetch_all(pool).await?; + + let query_str = format!("SELECT COUNT(*) from {}", table_name); + + let page_count_result = sqlx::query(&query_str).fetch_one(pool).await?; let page_count = page_count_result.try_get::(0).unwrap() as i32 / page_size; let paginated_rows = PaginatedRows::new(decode::decode_raw_rows(rows)?, page_count); @@ -75,6 +71,7 @@ pub trait RowHandler { params: String, ) -> Result { let query_str = format!("DELETE FROM {table_name} WHERE {pk_col_name} in ({params});"); + let result = sqlx::query(&query_str).execute(pool).await?; let mut message = String::from("Successfully deleted "); @@ -92,10 +89,9 @@ pub trait RowHandler { columns: String, values: String, ) -> Result { - let res = - sqlx::query(format!("INSERT INTO {table_name} ({columns}) VALUES({values})").as_str()) - .execute(pool) - .await?; + let query_str = format!("INSERT INTO {table_name} ({columns}) VALUES({values})"); + + let res = sqlx::query(&query_str).execute(pool).await?; Ok(format!("Successfully created {} row", res.rows_affected())) } async fn update_row( @@ -106,15 +102,12 @@ pub trait RowHandler { pk_col_name: String, pk_col_value: JsonValue, ) -> Result { - let _ = sqlx::query( - format!( - "UPDATE {table_name} SET {set_condition} WHERE {pk_col_name}={}", - pk_col_value - ) - .as_str(), - ) - .execute(pool) - .await?; + let query_str = format!( + "UPDATE {table_name} SET {set_condition} WHERE {pk_col_name}={}", + pk_col_value + ); + + let _ = sqlx::query(&query_str).execute(pool).await?; Ok(String::from("Successfully updated row")) } diff --git a/crates/handlers/src/mysql/mod.rs b/crates/handlers/src/mysql/mod.rs index e65b19d4..ff89f72e 100644 --- a/crates/handlers/src/mysql/mod.rs +++ b/crates/handlers/src/mysql/mod.rs @@ -16,7 +16,9 @@ impl Handler for MySQLHandler {} impl TableHandler for MySQLHandler { async fn get_tables(&self, pool: &AnyPool) -> Result> { let _ = pool.acquire().await; // This line is only added due to weird behavior when running the CLI - let res = sqlx::query("show tables;").fetch_all(pool).await?; + let query_str = "show tables;"; + + let res = sqlx::query(query_str).fetch_all(pool).await?; Ok(res) } async fn get_columns_props( @@ -24,8 +26,7 @@ impl TableHandler for MySQLHandler { pool: &AnyPool, table_name: String, ) -> Result> { - let result = sqlx::query_as::<_,ColumnProps>( - "SELECT cols.column_name AS column_name, + let query_str = "SELECT cols.column_name AS column_name, cols.data_type AS data_type, cols.is_nullable = \"YES\" AS is_nullable, cols.column_default AS default_value, @@ -35,11 +36,12 @@ impl TableHandler for MySQLHandler { LEFT JOIN information_schema.key_column_usage AS kcu ON kcu.column_name = cols.column_name LEFT JOIN information_schema.table_constraints AS tc ON tc.constraint_name = kcu.constraint_name WHERE cols.table_name = ? - GROUP BY cols.column_name, cols.data_type, cols.is_nullable, cols.column_default;" - ) - .bind(&table_name) - .fetch_all(pool) - .await?; + GROUP BY cols.column_name, cols.data_type, cols.is_nullable, cols.column_default;"; + + let result = sqlx::query_as::<_, ColumnProps>(query_str) + .bind(&table_name) + .fetch_all(pool) + .await?; Ok(result) } @@ -54,8 +56,7 @@ impl RowHandler for MySQLHandler { column_name: String, cell_value: JsonValue, ) -> Result> { - let fk_relations = sqlx::query_as::<_, FkRelation>( - " + let query_str = " SELECT referenced_table_name AS \"table\", referenced_column_name AS \"to\" FROM @@ -63,27 +64,25 @@ impl RowHandler for MySQLHandler { WHERE table_name = ? AND column_name = ? AND referenced_table_name IS NOT NULL; - ", - ) - .bind(&table_name) - .bind(&column_name) - .fetch_all(pool) - .await?; + "; + + let fk_relations = sqlx::query_as::<_, FkRelation>(query_str) + .bind(&table_name) + .bind(&column_name) + .fetch_all(pool) + .await?; let mut result = Vec::new(); for relation in fk_relations.iter() { - let rows = sqlx::query( - format!( - "SELECT * from {table_name} where {to} = {column_value};", - table_name = relation.table, - to = relation.to, - column_value = cell_value, - ) - .as_str(), - ) - .fetch_all(pool) - .await?; + let query_str = format!( + "SELECT * from {table_name} where {to} = {column_value};", + table_name = relation.table, + to = relation.to, + column_value = cell_value, + ); + + let rows = sqlx::query(&query_str).fetch_all(pool).await?; let decoded_row_data = tx_lib::decode::decode_raw_rows(rows)?; diff --git a/crates/handlers/src/postgres/mod.rs b/crates/handlers/src/postgres/mod.rs index 75eabf13..56415ec9 100644 --- a/crates/handlers/src/postgres/mod.rs +++ b/crates/handlers/src/postgres/mod.rs @@ -15,14 +15,12 @@ impl Handler for PostgresHandler {} impl TableHandler for PostgresHandler { async fn get_tables(&self, pool: &AnyPool) -> Result> { let _ = pool.acquire().await; // This line is only added due to weird behavior when running the CLI - let res = sqlx::query( - "SELECT \"table_name\" + let query_str = "SELECT \"table_name\" FROM information_schema.tables WHERE table_type = 'BASE TABLE' - AND table_schema = 'public';", - ) - .fetch_all(pool) - .await?; + AND table_schema = 'public';"; + + let res = sqlx::query(query_str).fetch_all(pool).await?; Ok(res) } @@ -32,8 +30,7 @@ impl TableHandler for PostgresHandler { pool: &AnyPool, table_name: String, ) -> Result> { - let result = sqlx::query_as::<_,ColumnProps>( - " + let query_str = " SELECT col.column_name, col.data_type, CASE @@ -68,11 +65,12 @@ impl TableHandler for PostgresHandler { END has_fk_relations FROM information_schema.columns AS COL WHERE col.table_name = $1 ORDER BY col.ordinal_position; - " - ) - .bind(&table_name) - .fetch_all(pool) - .await?; + "; + + let result = sqlx::query_as::<_, ColumnProps>(query_str) + .bind(&table_name) + .fetch_all(pool) + .await?; Ok(result) } @@ -87,8 +85,7 @@ impl RowHandler for PostgresHandler { column_name: String, cell_value: JsonValue, ) -> Result> { - let fk_relations = sqlx::query_as::<_, FkRelation>( - " + let query_str = " SELECT ccu.table_name AS table, ccu.column_name AS to @@ -102,27 +99,25 @@ impl RowHandler for PostgresHandler { AND kcu.column_name = $1 AND tc.table_schema='public' AND tc.table_name= $2; - ", - ) - .bind(&column_name) - .bind(&table_name) - .fetch_all(pool) - .await?; + "; + + let fk_relations = sqlx::query_as::<_, FkRelation>(query_str) + .bind(&column_name) + .bind(&table_name) + .fetch_all(pool) + .await?; let mut result = Vec::new(); for relation in fk_relations.iter() { - let rows = sqlx::query( - format!( - "SELECT * from {table_name} where {to} = {column_value};", - table_name = relation.table, - to = relation.to, - column_value = cell_value, - ) - .as_str(), - ) - .fetch_all(pool) - .await?; + let query_str = format!( + "SELECT * from {table_name} where {to} = {column_value};", + table_name = relation.table, + to = relation.to, + column_value = cell_value, + ); + + let rows = sqlx::query(&query_str).fetch_all(pool).await?; let decoded_row_data = tx_lib::decode::decode_raw_rows(rows)?; diff --git a/crates/handlers/src/sqlite/mod.rs b/crates/handlers/src/sqlite/mod.rs index 7fcc460a..c6ef66f1 100644 --- a/crates/handlers/src/sqlite/mod.rs +++ b/crates/handlers/src/sqlite/mod.rs @@ -15,14 +15,12 @@ impl Handler for SQLiteHandler {} #[async_trait] impl TableHandler for SQLiteHandler { async fn get_tables(&self, pool: &AnyPool) -> Result> { - let res = sqlx::query( - "SELECT name + let query_str = "SELECT name FROM sqlite_schema WHERE type ='table' - AND name NOT LIKE 'sqlite_%';", - ) - .fetch_all(pool) - .await?; + AND name NOT LIKE 'sqlite_%';"; + + let res = sqlx::query(query_str).fetch_all(pool).await?; Ok(res) } @@ -32,8 +30,7 @@ impl TableHandler for SQLiteHandler { pool: &AnyPool, table_name: String, ) -> Result> { - let result = sqlx::query_as::<_,ColumnProps>( - " + let query_str = " SELECT ti.name AS column_name, ti.type AS data_type, CASE WHEN ti.\"notnull\" = 1 @@ -47,11 +44,12 @@ impl TableHandler for SQLiteHandler { ELSE 0 END AS has_fk_relations FROM PRAGMA_TABLE_INFO($1) as ti; - " - ) - .bind(&table_name) - .fetch_all(pool) - .await?; + "; + + let result = sqlx::query_as::<_, ColumnProps>(query_str) + .bind(&table_name) + .fetch_all(pool) + .await?; Ok(result) } @@ -66,28 +64,26 @@ impl RowHandler for SQLiteHandler { column_name: String, cell_value: JsonValue, ) -> Result> { - let fk_relations = sqlx::query_as::<_, FkRelation>( - "SELECT \"table\",\"to\" FROM pragma_foreign_key_list($1) WHERE \"from\" = $2;", - ) - .bind(&table_name) - .bind(&column_name) - .fetch_all(pool) - .await?; + let query_str = + "SELECT \"table\",\"to\" FROM pragma_foreign_key_list($1) WHERE \"from\" = $2;"; + + let fk_relations = sqlx::query_as::<_, FkRelation>(query_str) + .bind(&table_name) + .bind(&column_name) + .fetch_all(pool) + .await?; let mut result = Vec::new(); for relation in fk_relations.iter() { - let rows = sqlx::query( - format!( - "SELECT * from {table_name} where {to} = {column_value};", - table_name = relation.table, - to = relation.to, - column_value = cell_value, - ) - .as_str(), - ) - .fetch_all(pool) - .await?; + let query_str = format!( + "SELECT * from {table_name} where {to} = {column_value};", + table_name = relation.table, + to = relation.to, + column_value = cell_value, + ); + + let rows = sqlx::query(&query_str).fetch_all(pool).await?; let decoded_row_data = tx_lib::decode::decode_raw_rows(rows)?; diff --git a/crates/keybindings/Cargo.toml b/crates/keybindings/Cargo.toml index 9fbb3588..e222873e 100644 --- a/crates/keybindings/Cargo.toml +++ b/crates/keybindings/Cargo.toml @@ -13,4 +13,5 @@ serde = { workspace = true } specta = { workspace = true } tauri-specta = { workspace = true } tauri = { workspace = true } +log = { workspace = true } tx_lib = { path = "../lib" } diff --git a/crates/keybindings/src/fs.rs b/crates/keybindings/src/fs.rs index 411f2967..36b9f92e 100644 --- a/crates/keybindings/src/fs.rs +++ b/crates/keybindings/src/fs.rs @@ -12,10 +12,13 @@ pub const KEYBINDINGS_FILE_NAME: &str = "keybindings.json"; /// with the default keybindings. pub fn ensure_keybindings_file_exist(path: &PathBuf) -> Result<(), TxError> { if path.exists() { + log::debug!("{} exists, skipping creation.", KEYBINDINGS_FILE_NAME); return Ok(()); } create_json_file_recursively(path)?; write_into_json(path, get_default_keybindings())?; + log::info!("Wrote default keybindings to {}", KEYBINDINGS_FILE_NAME); + Ok(()) } @@ -26,7 +29,6 @@ pub fn get_keybindings_file_path( app: &tauri::AppHandle, ) -> Result { let mut config_dir = app.path().app_config_dir()?; - // .map_err(|_| "Couldn't read config dir path".to_string())?; config_dir.push(KEYBINDINGS_FILE_NAME); Ok(config_dir) } diff --git a/crates/lib/Cargo.toml b/crates/lib/Cargo.toml index 4fc83da3..63d80c94 100644 --- a/crates/lib/Cargo.toml +++ b/crates/lib/Cargo.toml @@ -18,3 +18,4 @@ specta = { workspace = true } tauri-specta = { workspace = true } chrono = "0.4.38" thiserror = "1.0.63" +log = { workspace = true } diff --git a/crates/lib/src/events.rs b/crates/lib/src/events.rs index 32e853b0..449ff25c 100644 --- a/crates/lib/src/events.rs +++ b/crates/lib/src/events.rs @@ -2,8 +2,8 @@ use serde::{Deserialize, Serialize}; use specta::Type; use tauri_specta::Event; -#[derive(Clone, Serialize, Deserialize, Type, Event)] +#[derive(Clone, Serialize, Deserialize, Type, Event, Debug)] pub struct ConnectionsChanged; -#[derive(Clone, Serialize, Deserialize, Type, Event)] +#[derive(Clone, Serialize, Deserialize, Type, Event, Debug)] pub struct TableContentsChanged; diff --git a/crates/lib/src/fs.rs b/crates/lib/src/fs.rs index 17e16cda..7f600df5 100644 --- a/crates/lib/src/fs.rs +++ b/crates/lib/src/fs.rs @@ -16,6 +16,7 @@ where serde_json::to_writer_pretty(&mut writer, &contents)?; writer.flush().unwrap(); + Ok(()) } @@ -26,7 +27,11 @@ pub fn read_from_json(path: &PathBuf) -> Result where D: DeserializeOwned, { - let mut file = create_json_file_recursively(path)?; + let mut file = if !path.exists() { + create_json_file_recursively(path)? + } else { + OpenOptions::new().read(true).write(true).open(path)? + }; let _ = file.seek(SeekFrom::Start(0)); let reader = BufReader::new(file); @@ -39,16 +44,17 @@ where /// write to it and empty object ( `{}` ), /// otherwise opens the file and returns it. pub fn create_json_file_recursively(path: &PathBuf) -> Result { - if path.exists() { - let file = OpenOptions::new().read(true).write(true).open(path)?; - return Ok(file); - } let parent = path.parent().unwrap(); if !parent.exists() { std::fs::create_dir_all(parent)?; + log::info!("Created {} recursively.", parent.to_str().unwrap()); } + let mut file = File::create_new(path)?; + log::info!("Created {}.", path.to_str().unwrap()); write!(file, "{{}}")?; + log::info!("Wrote initial content to {}.", path.to_str().unwrap()); + Ok(file) } diff --git a/crates/settings/Cargo.toml b/crates/settings/Cargo.toml index ad59b000..f5f23b32 100644 --- a/crates/settings/Cargo.toml +++ b/crates/settings/Cargo.toml @@ -15,3 +15,4 @@ serde_json = { workspace = true } specta = { workspace = true } tauri = { workspace = true } tx_lib = { path = "../lib" } +log = { workspace = true } diff --git a/crates/settings/src/fs.rs b/crates/settings/src/fs.rs index 9654f7fb..105e4b7b 100644 --- a/crates/settings/src/fs.rs +++ b/crates/settings/src/fs.rs @@ -14,10 +14,14 @@ pub const SETTINGS_FILE_NAME: &str = "settings.json"; /// with the default settings. pub fn ensure_settings_file_exist(path: &PathBuf) -> Result<(), TxError> { if path.exists() { + log::debug!("{} exists, skipping creation.", SETTINGS_FILE_NAME); return Ok(()); } create_json_file_recursively(path)?; + write_into_json(path, Settings::default())?; + log::info!("Wrote default settings to {}", SETTINGS_FILE_NAME); + Ok(()) } diff --git a/crates/settings/src/schema.rs b/crates/settings/src/schema.rs index 74aaa15a..e13c3552 100644 --- a/crates/settings/src/schema.rs +++ b/crates/settings/src/schema.rs @@ -13,7 +13,7 @@ pub struct Settings { #[serde(rename = "$schema")] schema: Option, /// Number of rows to be fetched per page. - page_size: u32, + pub page_size: u32, /// Wether to automatically check for updates or not. pub check_for_updates: bool, /// Configuration for the SQL editor.