Skip to content

Commit

Permalink
feat: export save file dialog feature via FFI
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMiyauci committed Jul 31, 2024
1 parent 3dbc97f commit 7f7d5f2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/deno/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ export const symbols = {
result: "pointer",
nonblocking: false,
},
__Dialog_save_file: {
parameters: [
"pointer",
],
result: "pointer",
nonblocking: false,
},
__Dialog_set_directory: {
parameters: [
"pointer",
Expand Down
14 changes: 14 additions & 0 deletions src/deno/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ function __Dialog_pick_directory(
);
}

function __Dialog_save_file(
arg0: Deno.PointerObject | null,
): Deno.PointerObject | null {
return symbols.__Dialog_save_file(
arg0,
);
}

function __Dialog_set_directory(
arg0: Deno.PointerObject | null,
arg1: Uint8Array,
Expand Down Expand Up @@ -127,6 +135,12 @@ export class Dialog {
);
}

save_file(): Deno.PointerObject | null {
return __Dialog_save_file(
this.ptr,
);
}

set_directory(arg0: Uint8Array): Dialog {
return __Dialog_set_directory(
this.ptr,
Expand Down
18 changes: 18 additions & 0 deletions src/file_dialog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ impl Dialog {
c_string.into_raw()
}

pub fn save_file(&self) -> *mut c_char {
let path_buf = self.dialog.clone().save_file();

let result = match path_buf {
Some(path) => json!({
"success": true,
"data": path
}),
None => json!({
"success": false
}),
};

let c_string = CString::new(result.to_string()).unwrap();

c_string.into_raw()
}

pub fn set_directory(&self, p: &[u8]) -> Dialog {
let path_str = str::from_utf8(p).expect("Invalid UTF-8 sequence");
let path = Path::new(path_str);
Expand Down

0 comments on commit 7f7d5f2

Please sign in to comment.