Skip to content

Commit 0869041

Browse files
committed
fix: buggy drives and window operations
1 parent 00aecee commit 0869041

File tree

6 files changed

+57
-25
lines changed

6 files changed

+57
-25
lines changed

src-tauri/capabilities/main.json

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@
66
"permissions": [
77
"path:default",
88
"event:default",
9+
"window:default",
910
"app:default",
11+
"image:default",
1012
"resources:default",
1113
"menu:default",
1214
"tray:default",
13-
"window:allow-set-title",
14-
"os:allow-arch",
15-
"os:allow-hostname",
16-
"os:allow-os-type",
17-
"os:allow-platform",
18-
"fs:allow-watch",
19-
"window:allow-start-dragging",
20-
"window:allow-minimize",
2115
"window:allow-maximize",
22-
"window:allow-close"
16+
"window:allow-minimize",
17+
"window:allow-is-minimizable",
18+
"window:allow-is-maximizable",
19+
"window:allow-is-minimized",
20+
"window:allow-is-maximized",
21+
"window:allow-set-decorations",
22+
"window:allow-toggle-maximize",
23+
"window:allow-start-dragging",
24+
"window:allow-set-content-protected"
2325
]
2426
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"main-capability":{"identifier":"main-capability","description":"Capability for the main window","local":true,"windows":["main"],"permissions":["path:default","event:default","app:default","resources:default","menu:default","tray:default","window:allow-set-title","os:allow-arch","os:allow-hostname","os:allow-os-type","os:allow-platform","fs:allow-watch","window:allow-start-dragging","window:allow-minimize","window:allow-maximize","window:allow-close"]}}
1+
{"main-capability":{"identifier":"main-capability","description":"Capability for the main window","local":true,"windows":["main"],"permissions":["path:default","event:default","window:default","app:default","image:default","resources:default","menu:default","tray:default","window:allow-maximize","window:allow-minimize","window:allow-is-minimizable","window:allow-is-maximizable","window:allow-is-minimized","window:allow-is-maximized","window:allow-set-decorations","window:allow-toggle-maximize","window:allow-start-dragging","window:allow-set-content-protected"]}}

src-tauri/src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ lazy_static! {
115115
};
116116
}
117117

118+
#[tauri::command]
119+
#[inline]
120+
fn get_platform() -> String {
121+
std::env::consts::OS.to_string()
122+
}
123+
118124
#[cfg(target_os = "windows")]
119125
#[tauri::command]
120126
#[inline]
@@ -249,7 +255,8 @@ async fn main() {
249255
check_vscode_installed,
250256
get_available_fonts,
251257
enable_shadow_effect,
252-
change_transparent_effect
258+
change_transparent_effect,
259+
get_platform
253260
])
254261
// .plugin(tauri_plugin_window_state::Builder::default().build())
255262
.setup(|app| {

src/Components/Sidebar/index.tsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import React, { useEffect } from "react";
22
import { useDispatch, useSelector } from "react-redux";
33

44
import { setActiveTab, updateTab } from "../../Store/ActionCreators/TabActionCreators";
5+
import { fetchDrivesRequest } from "../../Store/ActionCreators/DriveActionCreators";
56
import { IAppState } from "../../Store/Reducers";
67
import { IFavoritesReducerState } from "../../Typings/Store/favorites";
8+
import { IDrive } from "../../Typings/Store/drive";
79

810
import XplorerLogo from "../../Icon/extension/xplorer.svg";
911
import FavoriteLogo from "../../Icon/folder/sidebar-favorite.svg";
@@ -14,16 +16,34 @@ const Sidebar = () => {
1416
const dispatch = useDispatch();
1517
const favorites = useSelector<IAppState, IFavoritesReducerState>((state) => state.favorites);
1618
const { drives } = useSelector<IAppState, IAppState["drive"]>((state) => state.drive);
19+
const platform = useSelector<IAppState, IAppState["platform"]["os"]>((state) => state.platform.os);
1720

1821
const activeTab = useSelector<IAppState, IAppState["tabs"]["activeTab"]>((state) => state.tabs.activeTab);
1922

23+
// Fetch drives when component mounts
24+
useEffect(() => {
25+
dispatch(fetchDrivesRequest());
26+
}, [dispatch]);
27+
2028
const favoritesSort = (a: [string, string], b: [string, string]): number => (a[0] > b[0] ? 1 : -1);
2129

2230
const navigateToPath = (path: string) => {
2331
dispatch(updateTab(activeTab.name, { ...activeTab, path, name: path }));
2432
dispatch(setActiveTab({ ...activeTab, path, name: path }));
2533
};
2634

35+
// Compute drive display name based on platform and drive properties
36+
const getDriveDisplayName = (drive: IDrive) => {
37+
if (platform === "windows") {
38+
const hasName = drive.name && /[^?]/.test(drive.name);
39+
const baseName = hasName ? drive.name : drive.disk_type;
40+
const mountPoint = drive.mount_point.replace(/\\$/g, "");
41+
return `${baseName} (${mountPoint})`;
42+
} else {
43+
return drive.mount_point.split("/").at(-1) || drive.mount_point;
44+
}
45+
};
46+
2747
return (
2848
<ThemedDiv componentName="sidebar" className="sidebar">
2949
<ThemedSpan componentName="xplorerBrand" className="xplorer-brand">
@@ -59,20 +79,20 @@ const Sidebar = () => {
5979
<div id="sidebar-drives" data-section="drives">
6080
<ThemedDiv componentName="sidebarNavToogle" className="sidebar-nav-toggle sidebar-hover-effect">
6181
<img src={HardDiskLogo} alt="Drives" />
62-
<span className="sidebar-text" />
82+
<span className="sidebar-text">{platform === "linux" ? "Pendrives" : "Drives"}</span>
6383
<span className="sidebar-nav-toggle-arrow" />
6484
</ThemedDiv>
6585
<div className="sidebar-nav-list">
66-
{drives.map(({ name, mount_point }) => (
86+
{drives.map((drive) => (
6787
<span
68-
data-path={mount_point}
88+
data-path={drive.mount_point}
6989
className="sidebar-hover-effect sidebar-nav-item drive-item"
70-
onClick={() => navigateToPath(mount_point.replace(/\\/g, "/"))}
71-
key={mount_point + name}
90+
onClick={() => navigateToPath(drive.mount_point.replace(/\\/g, "/"))}
91+
key={drive.mount_point}
7292
>
7393
<div className="sidebar-icon"></div>
7494
<ThemedSpan componentName="sidebarText" className="sidebar-text">
75-
{name}
95+
{getDriveDisplayName(drive)}
7696
</ThemedSpan>
7797
</span>
7898
))}

src/Services/PlatformService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { platform } from "@tauri-apps/plugin-os";
1+
import { invoke } from "@tauri-apps/api/core";
22

33
export const getOS = async (): Promise<string> => {
4-
const currentPlatform = await platform();
4+
const currentPlatform = await invoke<string>("get_platform");
55
return currentPlatform;
66
};

src/Store/Sagas/DrivesSaga.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1-
import { all, call, takeLatest } from "redux-saga/effects";
1+
import { all, call, takeLatest, select, take } from "redux-saga/effects";
22

33
import { fetchDrivesFailure, fetchDrivesSuccess } from "../ActionCreators/DriveActionCreators";
44
import { getOSRequest } from "../ActionCreators/PlatformActionCreators";
55

6-
import { selectStatus, typedPut as put, typedSelect as select } from "./helpers";
6+
import { selectStatus, typedPut as put } from "./helpers";
77
import * as DrivesService from "../../Services/DrivesService";
88
import { IDrive } from "../../Typings/Store/drive";
99

1010
function* fetchDrivesWorker(/* action: FetchDrivesRequest */) {
1111
try {
1212
let os: string = yield select((state) => state.platform.os);
13+
1314
if (!os) {
15+
// Request OS information
1416
yield put(getOSRequest());
15-
}
1617

17-
// WAIT FOR OS RESOLVE
18-
while (!os) {
19-
yield new Promise((resolve) => setTimeout(resolve, 100));
18+
// Wait for OS to be successfully loaded
19+
yield take(selectStatus("GET_OS", "SUCCESS"));
20+
21+
// Get the OS again after it's been loaded
2022
os = yield select((state) => state.platform.os);
2123
}
2224

25+
console.log("OS detected:", os);
2326
const drives: IDrive[] = yield call(DrivesService.fetchDrives, os);
2427
yield put(fetchDrivesSuccess(drives));
2528
} catch (error) {

0 commit comments

Comments
 (0)