Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ tauri-plugin-deeplink2 = { path = "plugins/deeplink2" }
tauri-plugin-detect = { path = "plugins/detect" }
tauri-plugin-extensions = { path = "plugins/extensions" }
tauri-plugin-fs-sync = { path = "plugins/fs-sync" }
tauri-plugin-fs2 = { path = "plugins/fs2" }
tauri-plugin-hooks = { path = "plugins/hooks" }
tauri-plugin-icon = { path = "plugins/icon" }
tauri-plugin-importer = { path = "plugins/importer" }
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@hypr/plugin-detect": "workspace:*",
"@hypr/plugin-extensions": "workspace:*",
"@hypr/plugin-fs-sync": "workspace:*",
"@hypr/plugin-fs2": "workspace:*",
"@hypr/plugin-hooks": "workspace:*",
"@hypr/plugin-icon": "workspace:*",
"@hypr/plugin-importer": "workspace:*",
Expand Down Expand Up @@ -90,7 +91,6 @@
"@tauri-apps/plugin-autostart": "^2.5.1",
"@tauri-apps/plugin-deep-link": "^2.4.5",
"@tauri-apps/plugin-dialog": "^2.4.2",
"@tauri-apps/plugin-fs": "^2.4.4",
"@tauri-apps/plugin-http": "^2.5.4",
"@tauri-apps/plugin-opener": "^2.5.2",
"@tauri-apps/plugin-os": "^2.3.2",
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ tauri-plugin-deeplink2 = { workspace = true }
tauri-plugin-detect = { workspace = true }
tauri-plugin-dialog = { workspace = true }
tauri-plugin-extensions = { workspace = true }
tauri-plugin-fs = { workspace = true }
tauri-plugin-fs-sync = { workspace = true }
tauri-plugin-fs2 = { workspace = true }
tauri-plugin-hooks = { workspace = true }
tauri-plugin-http = { workspace = true }
tauri-plugin-icon = { workspace = true }
Expand Down
163 changes: 1 addition & 162 deletions apps/desktop/src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,168 +49,6 @@
}
]
},
{
"identifier": "fs:allow-mkdir",
"allow": [
{
"path": "$DATA/hyprnote"
},
{
"path": "$DATA/hyprnote/**/*"
},
{
"path": "$APPDATA"
},
{
"path": "$APPDATA/**/*"
}
]
},
{
"identifier": "fs:allow-read-dir",
"allow": [
{
"path": "$DATA/hyprnote"
},
{
"path": "$DATA/hyprnote/**/*"
},
{
"path": "$APPDATA"
},
{
"path": "$APPDATA/**/*"
}
]
},
{
"identifier": "fs:allow-exists",
"allow": [
{
"path": "/Applications/*"
},
{
"path": "$DATA/hyprnote"
},
{
"path": "$DATA/hyprnote/**/*"
},
{
"path": "$APPDATA"
},
{
"path": "$APPDATA/**/*"
}
]
},
{
"identifier": "fs:allow-read-file",
"allow": [
{
"path": "$DATA/hyprnote"
},
{
"path": "$DATA/hyprnote/**/*"
},
{
"path": "$APPDATA"
},
{
"path": "$APPDATA/**/*"
}
]
},
{
"identifier": "fs:allow-read-text-file",
"allow": [
{
"path": "$DATA/hyprnote"
},
{
"path": "$DATA/hyprnote/**/*"
},
{
"path": "$APPDATA"
},
{
"path": "$APPDATA/**/*"
}
]
},
{
"identifier": "fs:allow-write-text-file",
"allow": [
{
"path": "$DATA/hyprnote"
},
{
"path": "$DATA/hyprnote/**/*"
},
{
"path": "$APPDATA"
},
{
"path": "$APPDATA/**/*"
},
{
"path": "$DOWNLOAD/**/*"
}
]
},
{
"identifier": "fs:allow-write-file",
"allow": [
{
"path": "$DATA/hyprnote"
},
{
"path": "$DATA/hyprnote/**/*"
},
{
"path": "$APPDATA"
},
{
"path": "$APPDATA/**/*"
},
{
"path": "$DOWNLOAD/**/*"
}
]
},
{
"identifier": "fs:allow-remove",
"allow": [
{
"path": "$DATA/hyprnote"
},
{
"path": "$DATA/hyprnote/**/*"
},
{
"path": "$APPDATA"
},
{
"path": "$APPDATA/**/*"
}
]
},
{
"identifier": "fs:allow-rename",
"allow": [
{
"path": "$DATA/hyprnote"
},
{
"path": "$DATA/hyprnote/**/*"
},
{
"path": "$APPDATA"
},
{
"path": "$APPDATA/**/*"
}
]
},
"apple-calendar:default",
"apple-contact:default",
"audio-priority:default",
Expand Down Expand Up @@ -258,6 +96,7 @@
},
"misc:default",
"fs-sync:default",
"fs2:default",
"os:default",
"detect:default",
"permissions:default",
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ pub async fn main() {
.plugin(tauri_plugin_deep_link::init())
.plugin(tauri_plugin_deeplink2::init())
.plugin(tauri_plugin_fs_sync::init())
.plugin(tauri_plugin_fs2::init())
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_path2::init())
.plugin(tauri_plugin_pdf::init())
.plugin(tauri_plugin_process::init())
Expand Down
25 changes: 18 additions & 7 deletions apps/desktop/src/store/tinybase/persister/chat/load.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { sep } from "@tauri-apps/api/path";
import { readTextFile } from "@tauri-apps/plugin-fs";

import { commands as fs2Commands } from "@hypr/plugin-fs2";
import { commands as fsSyncCommands } from "@hypr/plugin-fs-sync";

import {
Expand Down Expand Up @@ -96,15 +96,26 @@ export async function loadSingleChatGroup(
): Promise<LoadResult<LoadedChatData>> {
const filePath = [dataDir, "chats", groupId, CHAT_MESSAGES_FILE].join(sep());

const result = await fs2Commands.readTextFile(filePath);
if (result.status === "error") {
if (isFileNotFoundError(result.error)) {
return ok(createEmptyLoadedChatData());
}
console.error(
`[${LABEL}] Failed to load chat group ${groupId}:`,
result.error,
);
return err(result.error);
}

try {
const content = await readTextFile(filePath);
const json = JSON.parse(content) as ChatJson;
const json = JSON.parse(result.data) as ChatJson;
return ok(chatJsonToData(json));
} catch (error) {
if (isFileNotFoundError(error)) {
return ok(createEmptyLoadedChatData());
}
console.error(`[${LABEL}] Failed to load chat group ${groupId}:`, error);
console.error(
`[${LABEL}] Failed to parse chat JSON for ${groupId}:`,
error,
);
return err(String(error));
}
}
11 changes: 5 additions & 6 deletions apps/desktop/src/store/tinybase/persister/factories/collector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { remove } from "@tauri-apps/plugin-fs";
import { createCustomPersister } from "tinybase/persisters/with-schemas";
import type {
PersistedChanges,
Expand All @@ -11,6 +10,7 @@ import type {
OptionalSchemas,
} from "tinybase/with-schemas";

import { commands as fs2Commands } from "@hypr/plugin-fs2";
import {
commands as fsSyncCommands,
type ParsedDocument,
Expand Down Expand Up @@ -235,12 +235,11 @@ async function deleteFiles(paths: string[], label: string): Promise<void> {
if (paths.length === 0) return;

for (const path of paths) {
try {
await remove(path);
} catch (error) {
const errorStr = String(error);
const result = await fs2Commands.remove(path);
if (result.status === "error") {
const errorStr = result.error;
if (!errorStr.includes("No such file") && !errorStr.includes("ENOENT")) {
console.error(`[${label}] Failed to delete file ${path}:`, error);
console.error(`[${label}] Failed to delete file ${path}:`, errorStr);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const path2Mocks = vi.hoisted(() => ({
base: vi.fn().mockResolvedValue("/mock/data/dir/hyprnote"),
}));

const fsMocks = vi.hoisted(() => ({
mkdir: vi.fn().mockResolvedValue(undefined),
const fs2Mocks = vi.hoisted(() => ({
readTextFile: vi.fn(),
remove: vi.fn(),
}));

const fsSyncMocks = vi.hoisted(() => ({
Expand All @@ -23,7 +23,7 @@ const notifyMocks = vi.hoisted(() => ({
}));

vi.mock("@hypr/plugin-path2", () => ({ commands: path2Mocks }));
vi.mock("@tauri-apps/plugin-fs", () => fsMocks);
vi.mock("@hypr/plugin-fs2", () => ({ commands: fs2Mocks }));
vi.mock("@hypr/plugin-fs-sync", () => ({ commands: fsSyncMocks }));
vi.mock("@hypr/plugin-notify", () => ({ events: notifyMocks }));

Expand Down Expand Up @@ -67,7 +67,10 @@ describe("createJsonFilePersister", () => {
recurrence_series_id: "",
},
};
fsMocks.readTextFile.mockResolvedValue(JSON.stringify(mockData));
fs2Mocks.readTextFile.mockResolvedValue({
status: "ok",
data: JSON.stringify(mockData),
});

const persister = createJsonFilePersister(store, {
tableName: "events",
Expand All @@ -76,16 +79,17 @@ describe("createJsonFilePersister", () => {
});
await persister.load();

expect(fsMocks.readTextFile).toHaveBeenCalledWith(
expect(fs2Mocks.readTextFile).toHaveBeenCalledWith(
`${MOCK_DATA_DIR}/test.json`,
);
expect(store.getTable("events")).toEqual(mockData);
});

test("handles file not found gracefully", async () => {
fsMocks.readTextFile.mockRejectedValue(
new Error("No such file or directory"),
);
fs2Mocks.readTextFile.mockResolvedValue({
status: "error",
error: "No such file or directory",
});

const persister = createJsonFilePersister(store, {
tableName: "events",
Expand Down
Loading
Loading