Skip to content

Commit 647c828

Browse files
authored
fix: open in finder in player
* start * feat: windows ready * fix: dark theme * type * feat: open in finder in player * remove console.log * fix: tabs renaming on windows * remove console.log
1 parent b711d96 commit 647c828

File tree

16 files changed

+128
-65
lines changed

16 files changed

+128
-65
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<html lang="en" data-theme="cupcake">
2+
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
55
<link rel="icon" type="image/svg+xml" href="favicon.svg" />

package-lock.json

Lines changed: 30 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"@tauri-apps/api": "^1.5.6 ",
5555
"github": "^14.0.0",
5656
"lodash-es": "^4.17.21",
57+
"nanopath": "^2.0.1",
5758
"pretty-ms": "^9.0.0",
5859
"solid-heroicons": "^3.2.4",
5960
"solid-js": "^1.8.17",

src-tauri/src/cmds.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::path::Path;
12
use std::process::Command;
23
use std::sync::atomic::{AtomicBool, Ordering};
34
use std::sync::Arc;
@@ -22,20 +23,29 @@ pub async fn create_directory(
2223
path_dir: String,
2324
state: tauri::State<'_, AppState>,
2425
) -> Result<directory::Data, String> {
25-
let parts = path_dir.split("/").collect::<Vec<&str>>();
26-
let last_part = parts[parts.len() - 1];
26+
let path = Path::new(&path_dir);
27+
let directory_name = path
28+
.file_name()
29+
.and_then(|name| name.to_str())
30+
.ok_or_else(|| "Nom de répertoire invalide".to_string())?;
31+
2732
return match state
2833
.prisma_client
2934
.directory()
30-
.create(path_dir.to_string(), last_part.to_string(), true, vec![])
35+
.create(
36+
path.to_string_lossy().into_owned(),
37+
directory_name.to_string(),
38+
true,
39+
vec![],
40+
)
3141
.exec()
3242
.await
3343
{
3444
Ok(directory) => Ok(directory),
3545
Err(error) if error.is_prisma_error::<UniqueKeyViolation>() => {
36-
Err(last_part.to_string() + " already exists")
46+
Err(format!("{} existe déjà", directory_name))
3747
}
38-
Err(_error) => Err("An error occurred".to_string()),
48+
Err(_error) => Err("Une erreur s'est produite".to_string()),
3949
};
4050
}
4151

src/components/FilesTable/FilesTable.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
getCoreRowModel,
88
} from "@tanstack/solid-table";
99
import { createVirtualizer } from "@tanstack/solid-virtual";
10-
import { random } from "lodash-es";
1110
import {
1211
For,
1312
createEffect,
@@ -129,8 +128,12 @@ const FilesTable: Component = () => {
129128

130129
const handleRandomPosition = async () => {
131130
const totalCount = metadataFiles()?.total_count ?? 0;
132-
const countRandom = random(0, totalCount - 1);
133-
setRandomPosition(countRandom);
131+
if (totalCount > 0) {
132+
const randomBuffer = new Uint32Array(1);
133+
window.crypto.getRandomValues(randomBuffer);
134+
const countRandom = randomBuffer[0] % totalCount;
135+
setRandomPosition(countRandom);
136+
}
134137
};
135138

136139
createEffect(() => {

src/components/FilesTable/columns.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { type File } from "@prisma/client";
22
import { type ColumnDef } from "@tanstack/solid-table";
33

4-
import { tauri } from "@tauri-apps/api";
4+
import { openInFinder as openInFinderApi } from "@/services/filesServices";
55
import prettyMilliseconds from "pretty-ms";
66
import { Icon } from "solid-heroicons";
77
import { magnifyingGlass } from "solid-heroicons/solid";
88

99
async function openInFinder(path: string, event: Event): Promise<void> {
1010
event.preventDefault();
1111
event.stopPropagation();
12-
await tauri.invoke("open_in_finder", { path });
12+
await openInFinderApi(path);
1313
}
1414

1515
export const filesTableColumns: Array<ColumnDef<File>> = [

src/components/Tabs/Tabs.tsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,36 @@ const Tabs: FlowComponent<Props, Component<any>> = (props) => {
2222
const [getRenamingMode, setRenamingMode] = createSignal(false);
2323

2424
return (
25-
<a
26-
ondblclick={(event) => {
27-
event.stopPropagation();
28-
setRenamingMode(true);
29-
setFocused(true);
30-
target()?.select();
31-
}}
32-
onClick={() => props.setActive(index())}
33-
class="tab flex-shrink-0"
34-
classList={{
35-
"tab-active": item.active,
36-
}}
37-
>
25+
<div class="tab flex-shrink-0 flex items-center" classList={{ "tab-active": item.active }}>
3826
<label class="input-sizer" data-value={item.name}>
3927
<input
4028
ref={setTarget}
4129
type="text"
4230
value={item.name}
43-
disabled={!getRenamingMode()}
31+
readOnly={!getRenamingMode()}
32+
class="appearance-none bg-transparent border-none focus:outline-none cursor-pointer"
33+
classList={{
34+
"cursor-text": getRenamingMode(),
35+
}}
36+
onClick={(event) => {
37+
if (!getRenamingMode()) {
38+
props.setActive(index());
39+
}
40+
}}
41+
onDblClick={(event) => {
42+
event.preventDefault();
43+
setRenamingMode(true);
44+
setFocused(true);
45+
target()?.select();
46+
}}
4447
onBlur={() => setRenamingMode(false)}
4548
onInput={(event) => {
4649
tabsStore.rename(index(), event.target.value);
4750
}}
4851
onKeyDown={(event) => {
4952
if (event.key === "Enter") {
5053
event.preventDefault();
54+
setRenamingMode(false);
5155
setFocused(false);
5256
}
5357
}}
@@ -64,7 +68,7 @@ const Tabs: FlowComponent<Props, Component<any>> = (props) => {
6468
>
6569
<Icon path={xMark} class="flex-shrink-0 w-4" />
6670
</button>
67-
</a>
71+
</div>
6872
);
6973
}}
7074
</For>

src/components/WavePlayer/WavePlayer.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { useSearch } from "@/providers/SearchProvider/SearchProvider";
2+
import { openInFinder } from "@/services/filesServices";
23
import { convertFileSrc } from "@tauri-apps/api/tauri";
34
import { Icon } from "solid-heroicons";
4-
import { pause, play } from "solid-heroicons/solid";
5+
import { magnifyingGlass, pause, play } from "solid-heroicons/solid";
56
import {
67
Match,
78
Switch,
@@ -58,8 +59,8 @@ const WavePlayer: Component = () => {
5859

5960
return (
6061
<div class="player p-4">
61-
<div>
62-
<div class="flex items-center mb-4">
62+
<div class="flex items-center mb-4 gap-4">
63+
<div class="flex items-center">
6364
<input
6465
id="default-checkbox"
6566
type="checkbox"
@@ -74,6 +75,17 @@ const WavePlayer: Component = () => {
7475
Auto play
7576
</label>
7677
</div>
78+
<button
79+
class="ml-auto"
80+
disabled={!store.pathSelected}
81+
onClick={() => openInFinder(store.pathSelected)}
82+
title="Open in finder"
83+
>
84+
<Icon
85+
path={magnifyingGlass}
86+
class="flex-shrink-0 w-4 h-4 text-gray-500 transition duration-75 group-hover:text-gray-900 dark:text-gray-400 dark:group-hover:text-white"
87+
/>
88+
</button>
7789
</div>
7890
<div ref={container} />
7991

src/lib/nanopath.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { isWindows } from '@tauri-apps/api/helpers/os-check';
2+
3+
import type { PathPlatform } from 'nanopath/dist/types';
4+
5+
import posix from '../../node_modules/nanopath/dist/posix';
6+
import win32 from '../../node_modules/nanopath/dist/win32';
7+
8+
type SimplePathPlatform = Omit<PathPlatform, 'posix' | 'win32'>;
9+
10+
const Platform = (isWindows() ? win32 : posix);
11+
const Path: SimplePathPlatform = Platform;
12+
13+
export default Path;

src/providers/SearchProvider/SearchProvider.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { type SetStoreFunction } from "solid-js/store";
44

55
interface SearchActions {
66
setCollapse: SetStoreFunction<Collapsed>;
7+
setAllCollapse: SetStoreFunction<Collapsed>;
78
setSearch: SetStoreFunction<string>;
89
setPathSelected: SetStoreFunction<string>;
910
}

0 commit comments

Comments
 (0)