Skip to content

Commit

Permalink
Try upgrading to napi@3
Browse files Browse the repository at this point in the history
  • Loading branch information
probablykasper committed Sep 30, 2024
1 parent 9025f62 commit 48c70a4
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 71 deletions.
112 changes: 53 additions & 59 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ crate-type = ["cdylib"]
napi-build = "2.0"

[dependencies]
napi = { version = "2.13", features = [
napi = { version = "3.0.0-alpha.12", features = [
"serde-json",
"napi6",
"tokio_rt",
Expand Down
6 changes: 3 additions & 3 deletions src-native/data_js.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::data::Data;
use anyhow::{Context, Result};
use napi::{Env, JsUndefined};
use napi::Env;

pub fn get_data(env: &Env) -> Result<&mut Data> {
let data = env.get_instance_data::<Data>()?.context("No data")?;
Expand Down Expand Up @@ -44,8 +44,8 @@ pub fn get_paths(env: Env) -> Result<PathsJs> {

#[napi(js_name = "save")]
#[allow(dead_code)]
pub fn save(env: Env) -> napi::Result<JsUndefined> {
pub fn save(env: Env) -> Result<()> {
let data: &mut Data = get_data(&env)?;
data.save()?;
env.get_undefined()
Ok(())
}
6 changes: 3 additions & 3 deletions src-native/itunes_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,19 +588,19 @@ pub struct ItunesImport {
#[napi]
impl ItunesImport {
#[napi(factory)]
pub fn new(env: Env) -> napi::Result<Self> {
pub fn new(env: Env) -> Result<Self> {
let data = get_data(&env)?;
Ok(Self {
new_library: Some(data.library.clone()).into(),
itunes_track_paths: HashMap::new().into(),
})
}
#[napi]
pub async fn start(&self, path: String, tracks_dir: String) -> napi::Result<ImportStatus> {
pub async fn start(&self, path: String, tracks_dir: String) -> Result<ImportStatus> {
Ok(import_itunes(self, path, tracks_dir).await?)
}
#[napi]
pub fn finish(&mut self, env: Env) -> napi::Result<()> {
pub fn finish(&mut self, env: Env) -> Result<()> {
let data = get_data(&env)?;
let itunes_track_paths = &mut *self.itunes_track_paths.lock().unwrap();
for (itunes_path, ferrum_file) in itunes_track_paths {
Expand Down
Loading

0 comments on commit 48c70a4

Please sign in to comment.