mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 11:07:04 +00:00
feat(io): add read_file/write_file commands and dialog capability
This commit is contained in:
1 parent
eb63a6d49d
commit
13f2a70af2
3 files changed
+20
-2
No files matched your search
@@ -5,6 +5,7 @@
|
|||||||
"windows": ["main"],
|
"windows": ["main"],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"core:default",
|
"core:default",
|
||||||
"opener:default"
|
"opener:default",
|
||||||
|
"dialog:default"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,16 @@
|
|||||||
mod pdf;
|
mod pdf;
|
||||||
|
mod project;
|
||||||
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.plugin(tauri_plugin_opener::init())
|
.plugin(tauri_plugin_opener::init())
|
||||||
.invoke_handler(tauri::generate_handler![pdf::compile_pdf])
|
.plugin(tauri_plugin_dialog::init())
|
||||||
|
.invoke_handler(tauri::generate_handler![
|
||||||
|
pdf::compile_pdf,
|
||||||
|
project::read_file,
|
||||||
|
project::write_file
|
||||||
|
])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running margin");
|
.expect("error while running margin");
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
use std::fs;
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn read_file(path: String) -> Result<String, String> {
|
||||||
|
fs::read_to_string(&path).map_err(|e| e.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn write_file(path: String, contents: String) -> Result<(), String> {
|
||||||
|
fs::write(&path, contents).map_err(|e| e.to_string())
|
||||||
|
}
|
||||||
Reference in new issue
Block a user