Skip to content

Commit

Permalink
refactor(tools): moved everything into the tools dir
Browse files Browse the repository at this point in the history
  • Loading branch information
tnfssc committed Jul 31, 2024
1 parent c046137 commit 693caff
Show file tree
Hide file tree
Showing 21 changed files with 678 additions and 424 deletions.
125 changes: 125 additions & 0 deletions src-tauri/Cargo.lock

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

3 changes: 2 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ edition = "2021"
tauri-build = { version = "1", features = [] }

[dependencies]
tauri = { version = "1", features = [ "fs-read-file", "shell-execute", "fs-write-file", "fs-exists", "shell-open", "path-all"] }
tauri = { version = "1", features = [ "dialog-open", "fs-read-file", "shell-execute", "fs-write-file", "fs-exists", "shell-open", "path-all"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tauri-plugin-persisted-scope = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }

[features]
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_persisted_scope::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
8 changes: 8 additions & 0 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
"path": {
"all": true
},
"dialog": {
"all": false,
"ask": false,
"confirm": false,
"message": false,
"open": true,
"save": false
},
"fs": {
"all": false,
"readFile": true,
Expand Down
1 change: 1 addition & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './cli';
export * from './tauri';
40 changes: 40 additions & 0 deletions src/api/tauri.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* eslint-disable @tanstack/query/exhaustive-deps */
import { type UseMutationOptions, queryOptions } from '@tanstack/react-query';
import { type OpenDialogOptions, open } from '@tauri-apps/api/dialog';
import { normalize } from '@tauri-apps/api/path';

import { queryClient } from '~/lib/query-client';

import { cli } from './cli';

export const tauri = {
dialog: {
open(defaultOptions?: OpenDialogOptions) {
return {
mutationKey: ['open', defaultOptions].filter((v) => !!v),
mutationFn: async ({ options: _options }: { options?: OpenDialogOptions }) => {
const options = { ...defaultOptions, ..._options };
let dir: string | null = null;
const selected = await open(options);
if (Array.isArray(selected)) dir = selected[0];
else dir = selected;
if (!dir) throw new Error('No directory selected');
return dir;
},
} satisfies UseMutationOptions<string, Error, { options?: OpenDialogOptions }>;
},
},
path: {
normalize(path: string) {
return queryOptions({
queryKey: ['path', 'normalize', path].filter((v) => !!v),
queryFn: async () => {
let p = await normalize(path);
const homeDirectory = await queryClient.fetchQuery(cli.homeDir());
if (p.includes(homeDirectory)) p = p.replace(homeDirectory, '~/');
return p;
},
});
},
},
};
45 changes: 0 additions & 45 deletions src/components/drawer.tsx

This file was deleted.

16 changes: 16 additions & 0 deletions src/components/floating-action-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Box, type BoxProps } from 'styled-system/jsx';

import { IconButton, type IconButtonProps } from '~/ui/icon-button';

export interface FloatingActionButtonProps extends IconButtonProps {
containerProps?: BoxProps;
}

export const FloatingActionButton: React.FC<FloatingActionButtonProps> = ({ containerProps, ...props }) => {
return (
<Box pos="absolute" top="2" left="2" {...containerProps}>
{/* @ts-expect-error - TODO: fix */}
<IconButton {...props} />
</Box>
);
};
Loading

0 comments on commit 693caff

Please sign in to comment.