generated from emilk/eframe_template
-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (C) 2023 Lily Lyons | ||
// | ||
// This file is part of Luminol. | ||
// | ||
// Luminol is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Luminol is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Luminol. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
export function is_worker() { | ||
return typeof DedicatedWorkerGlobalScope === 'function' | ||
&& self instanceof DedicatedWorkerGlobalScope; | ||
} | ||
|
||
export function worker() { | ||
return is_worker() ? self : null; | ||
} | ||
|
||
// A binding for this attribute was added in July 2023 but hasn't made its way into a release of | ||
// web-sys as of September 2023 | ||
export function performance(worker) { | ||
return worker.performance; | ||
} | ||
|
||
export function filesystem_supported() { | ||
return typeof window?.showOpenFilePicker === 'function' | ||
&& typeof window?.showDirectoryPicker === 'function' | ||
&& typeof FileSystemFileHandle === 'function' | ||
&& typeof FileSystemWritableFileStream === 'function' | ||
&& typeof FileSystemFileHandle?.prototype?.remove === 'function' | ||
&& typeof FileSystemDirectoryHandle?.prototype?.remove === 'function'; | ||
} | ||
|
||
export async function _show_directory_picker() { | ||
return await window.showDirectoryPicker({ mode: 'readwrite' }); | ||
} | ||
|
||
export async function _remove_file(file) { | ||
await file.remove(); | ||
} | ||
|
||
export async function _remove_dir(dir) { | ||
await dir.remove(); | ||
} | ||
|
||
export function dir_values(dir) { | ||
return dir.values(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (C) 2023 Lily Lyons | ||
// | ||
// This file is part of Luminol. | ||
// | ||
// Luminol is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Luminol is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Luminol. If not, see <http://www.gnu.org/licenses/>. | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen(module = "/assets/bindings.js")] | ||
extern "C" { | ||
pub fn worker() -> Option<web_sys::DedicatedWorkerGlobalScope>; | ||
pub fn performance(worker: &web_sys::DedicatedWorkerGlobalScope) -> web_sys::Performance; | ||
pub fn filesystem_supported() -> bool; | ||
#[wasm_bindgen(catch)] | ||
async fn _show_directory_picker() -> Result<JsValue, JsValue>; | ||
#[wasm_bindgen(catch)] | ||
async fn _remove_file(file: &web_sys::FileSystemFileHandle) -> Result<JsValue, JsValue>; | ||
#[wasm_bindgen(catch)] | ||
async fn _remove_dir(dir: &web_sys::FileSystemDirectoryHandle) -> Result<JsValue, JsValue>; | ||
pub fn dir_values(dir: &web_sys::FileSystemDirectoryHandle) -> js_sys::AsyncIterator; | ||
} | ||
|
||
pub async fn show_directory_picker() -> Result<web_sys::FileSystemDirectoryHandle, js_sys::Error> { | ||
_show_directory_picker() | ||
.await | ||
.map(|o| o.unchecked_into()) | ||
.map_err(|e| e.unchecked_into()) | ||
} | ||
|
||
pub async fn remove_file(file: &web_sys::FileSystemFileHandle) -> Result<JsValue, js_sys::Error> { | ||
_remove_file(file) | ||
.await | ||
.map(|o| o.unchecked_into()) | ||
.map_err(|e| e.unchecked_into()) | ||
} | ||
|
||
pub async fn remove_dir( | ||
dir: &web_sys::FileSystemDirectoryHandle, | ||
) -> Result<JsValue, js_sys::Error> { | ||
_remove_dir(dir) | ||
.await | ||
.map(|o| o.unchecked_into()) | ||
.map_err(|e| e.unchecked_into()) | ||
} |