Skip to content

Commit

Permalink
Use oncecell
Browse files Browse the repository at this point in the history
  • Loading branch information
Blakeinstein committed Jun 6, 2021
1 parent f64afe4 commit dbdaa9b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ rust-embed = "5.9.0"
serde_json = "1.0.56"
serde = { version = "1.0.114", features = ["derive"] }
glob = "0.3.0"
once_cell = "1.7.2"

[profile.release]
panic = "abort"
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ fn exec(

fn main() {
let context = tauri::generate_context!();
unsafe {
scripts::PACKAGE_INFO = Some(context.package_info().clone());
};
scripts::PACKAGE_INFO
.set(context.package_info().clone())
.unwrap();
tauri::Builder::default()
.manage(Scripts(Default::default()))
.invoke_handler(tauri::generate_handler![doc_ready, exec])
Expand Down
5 changes: 3 additions & 2 deletions src/scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use serde::{Deserialize, Serialize};

use std::collections::HashMap;

pub static mut PACKAGE_INFO: Option<tauri::PackageInfo> = None;
use once_cell::sync::OnceCell;
pub static PACKAGE_INFO: OnceCell<tauri::PackageInfo> = OnceCell::new();

#[derive(Serialize, Deserialize)]
struct Metadata {
Expand Down Expand Up @@ -66,7 +67,7 @@ pub fn build_scripts(
window: Window,
script_list: &mut HashMap<String, Script>,
) -> tauri::Result<()> {
if let Some(resource_dir) = unsafe { resource_dir(&(PACKAGE_INFO.clone()).unwrap()) } {
if let Some(resource_dir) = resource_dir(&PACKAGE_INFO.get().unwrap()) {
dbg!(&resource_dir);
let script_path = &resource_dir.join("scripts").join("**").join("*.js");
install_scripts(&window, script_list, script_path.to_str().unwrap())?;
Expand Down

0 comments on commit dbdaa9b

Please sign in to comment.