Skip to content

Commit

Permalink
Merge pull request #3 from bazalp/develop
Browse files Browse the repository at this point in the history
Multiple fix
  • Loading branch information
vincehi authored Jun 27, 2023
2 parents c551f41 + a449323 commit 7754713
Show file tree
Hide file tree
Showing 21 changed files with 1,313 additions and 708 deletions.
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1,228 changes: 757 additions & 471 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@types/wavesurfer.js": "^6.0.6",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"autoprefixer": "^10.4.13",
"daisyui": "^3.1.5",
"dotenv": "^16.0.3",
"eslint": "^8.33.0",
"eslint-config-prettier": "^8.6.0",
Expand All @@ -32,12 +33,12 @@
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-solid": "~0.9.4",
"postcss": "^8.4.21",
"prettier": "2.8.8",
"prisma": "^4.9.0",
"semantic-release": "^21.0.3",
"semantic-release-export-data": "file:./tools/semantic-release-export-data.js",
"tailwindcss": "^3.2.7",
"tailwindcss": "^3.3.2",
"typescript": "^4.9.5",
"vite": "^4.0.4",
"vite": "^4.0.5",
"vite-plugin-solid": "^2.5.0"
},
"dependencies": {
Expand All @@ -50,10 +51,11 @@
"howler": "^2.2.3",
"lodash-es": "^4.17.21",
"solid-heroicons": "^3.1.1",
"solid-js": "^1.6.0",
"solid-js": "^1.7.0",
"solidjs-use": "^2.2.0",
"split.js": "^1.6.5",
"wait-on": "^7.0.1",
"wavesurfer.js": "^6.6.3"
"wavesurfer.js": "^6.6.4"
},
"volta": {
"node": "18.12.1"
Expand Down
10 changes: 0 additions & 10 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// const semanticReleaseExportData = require("./tools/semantic-release-export-data")

const config = {
branches: ['main'],
plugins: [
Expand All @@ -8,15 +6,7 @@ const config = {
'@semantic-release/github',
["@semantic-release/npm", {"npmPublish": false}],
"./tools/semantic-release-export-data.js",
// ["@semantic-release/git", {
// "assets": ["dist/*.js", "dist/*.js.map"],
// "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
// }],
//
]
};

// console.log(process.env)


module.exports = config;
78 changes: 78 additions & 0 deletions src-tauri/src/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use crate::utils::app::AppState;
use prisma_client_rust::and;
use prisma_client_rust::operator::or;
use prisma_client_rust::prisma_errors::query_engine::UniqueKeyViolation;
use std::process::Command;
use tauri::Manager;
use walkdir::WalkDir;

#[tauri::command]
Expand Down Expand Up @@ -97,8 +99,60 @@ pub async fn get_directory_files(
};
}

#[tauri::command]
pub async fn open_in_finder(path: String) {
#[cfg(target_os = "windows")]
{
Command::new("explorer")
.args(["/select,", &path]) // The comma after select is not a typo
.spawn()
.unwrap();
}

#[cfg(target_os = "linux")]
{
if path.contains(",") {
// see https://gitlab.freedesktop.org/dbus/dbus/-/issues/76
let new_path = match metadata(&path).unwrap().is_dir() {
true => path,
false => {
let mut path2 = PathBuf::from(path);
path2.pop();
path2.into_os_string().into_string().unwrap()
}
};
Command::new("xdg-open").arg(&new_path).spawn().unwrap();
} else {
Command::new("dbus-send")
.args([
"--session",
"--dest=org.freedesktop.FileManager1",
"--type=method_call",
"/org/freedesktop/FileManager1",
"org.freedesktop.FileManager1.ShowItems",
format!("array:string:\"file://{path}\"").as_str(),
"string:\"\"",
])
.spawn()
.unwrap();
}
}

#[cfg(target_os = "macos")]
{
Command::new("open").args(["-R", &path]).spawn().unwrap();
}
}

#[derive(Clone, serde::Serialize)]
struct Payload {
processing: bool,
directory_path: String,
}

#[tauri::command]
pub async fn scan_directory(
app_handle: tauri::AppHandle,
path_dir: String,
state: tauri::State<'_, AppState>,
) -> Result<Vec<file::Data>, String> {
Expand All @@ -111,7 +165,19 @@ pub async fn scan_directory(
v if !v.is_empty() => v,
_ => return Err(format!("No file found in directory: {}", path_dir)),
};

let mut result = Vec::with_capacity(walk_dir.len());

app_handle
.emit_all(
"event-walk-directory",
Payload {
processing: true,
directory_path: path_dir_string.clone(),
},
)
.unwrap();

for path_file in walk_dir {
if let Some(ext) = path_file.path().extension() {
if ext == "wav" || ext == "mp3" {
Expand Down Expand Up @@ -148,8 +214,20 @@ pub async fn scan_directory(
}
}
}

app_handle
.emit_all(
"event-walk-directory",
Payload {
processing: false,
directory_path: path_dir_string.clone(),
},
)
.unwrap();

if result.is_empty() {
return Err(format!("No audio files found in directory: {}", path_dir));
}

Ok(result)
}
3 changes: 2 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ async fn main() {
cmds::create_directory,
cmds::delete_directory,
cmds::scan_directory,
cmds::get_directory_files
cmds::get_directory_files,
cmds::open_in_finder,
])
.menu(tauri::Menu::os_default(&context.package_info().name))
.run(context)
Expand Down
13 changes: 7 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import Navbar from "./screens/Main/layouts/Navbar";
import Sidebar from "./screens/Main/layouts/Sidebar";
import ViewFiles from "./screens/Main/layouts/ViewFiles";
import WavePlayer from "@/components/WavePlayer";
import { WalkDirProvider } from "@/providers/WalkDir";

const App: Component = () => {
return (
<SearchProvider>
<Navbar />
<Sidebar />
<div class="relative">
<WalkDirProvider>
<SearchProvider>
<Navbar />
<Sidebar />
<ViewFiles />
<WavePlayer />
</div>
</SearchProvider>
</SearchProvider>
</WalkDirProvider>
);
};

Expand Down
121 changes: 90 additions & 31 deletions src/components/ActionsDirectory/index.tsx
Original file line number Diff line number Diff line change
@@ -1,54 +1,113 @@
import { deleteDirectories, scanDirectory } from "@/services/directories";
import { type Directory } from "@prisma/client";
import { confirm } from "@tauri-apps/api/dialog";
import { confirm, message } from "@tauri-apps/api/dialog";
import { Icon } from "solid-heroicons";
import { documentMagnifyingGlass, trash } from "solid-heroicons/outline";
import { type Component } from "solid-js";
import { type Component, Show } from "solid-js";
import {
createDirectory,
CustomError,
deleteDirectory,
scanDirectory,
} from "@/services/directories";
import { useWalkDir } from "@/providers/WalkDir";

const ActionsDirectory: Component<{
directory: Directory;
}> = (props) => {
const [walkDirStore] = useWalkDir();

const handleRemove = (
event: MouseEvent & { currentTarget: HTMLButtonElement; target: Element }
): void => {
event.preventDefault();
event.stopPropagation();
void (async () => {
if (walkDirStore.processing) {
await message(
"You cannot perform this action until the scan process has been completed.",
{
title: "Incomplete scan",
type: "error",
}
);
} else {
const response = await confirm(
`Are you sure you want to delete ${props.directory.name} ?\n\n(This action does not delete the original)`,
{
title: "Delete directory",
type: "error",
}
);
if (response) {
await deleteDirectory(props.directory.path);
}
}
})();
};

const handleScan = (
event: MouseEvent & { currentTarget: HTMLButtonElement; target: Element }
): void => {
event.preventDefault();
event.stopPropagation();
void (async () => {
if (walkDirStore.processing) {
await message(
"You cannot perform this action until the scan process has been completed.",
{
title: "Incomplete scan",
type: "error",
}
);
} else {
const response = await confirm(
`Scan the directory ${props.directory.name} to get all samples`,
{
title: "Scan the directory",
type: "warning",
}
);
if (response) {
try {
await deleteDirectory(props.directory.path);
await createDirectory(props.directory.path);
await scanDirectory(props.directory.path);
} catch (error) {
if (error instanceof CustomError) {
await message(error.message, error.options);
return;
}
console.error(error);
}
}
}
})();
};

return (
<>
<Show
when={
walkDirStore.pathDirectory === props.directory.path &&
walkDirStore.processing
}
>
<span class="loading loading-ring loading-xs mr-1"></span>
</Show>
<button
class="text-gray-500 hover:text-gray-900"
onClick={(event) => {
event.preventDefault();
event.stopPropagation();
void (async () => {
const response = await confirm(
`Are you sure you want to delete ${props.directory.name} ?\n\n(This action does not delete the original)`,
{
title: "Delete directory",
type: "error",
}
);
if (response) {
await deleteDirectories([props.directory.path]);
}
})();
handleRemove(event);
}}
title={`Remove ${props.directory.name}`}
>
<Icon path={trash} class="w-4" />
</button>

<button
class="text-gray-500 hover:text-gray-900"
onClick={(event) => {
event.preventDefault();
event.stopPropagation();
void (async () => {
const response = await confirm(
`Scan the directory ${props.directory.name} to get all samples`,
{
title: "Scan the directory",
type: "warning",
}
);
if (response) {
await scanDirectory(props.directory.path);
}
})();
handleScan(event);
}}
title={`Scanning ${props.directory.name}`}
>
Expand Down
Loading

0 comments on commit 7754713

Please sign in to comment.