Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(frontend): implement open log dir button #34

Merged
merged 1 commit into from
Jan 16, 2024
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
1 change: 1 addition & 0 deletions frontend/src/components/buttons/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @index('./*', f => `export * from '${f.path}'`)
export * from './convert_btn';
export * from './log_file_btn';
export * from './log_dir_btn';
export * from './path_selector';
export * from './remove_oar_btn';
export * from './unhide_dar_btn';
28 changes: 28 additions & 0 deletions frontend/src/components/buttons/log_dir_btn.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import FolderOpenIcon from '@mui/icons-material/FolderOpen';
import { Button, Tooltip } from '@mui/material';
import { toast } from 'react-hot-toast';

import { useTranslation } from '@/hooks';
import { openLogDir } from '@/tauri_cmd';

export const LogDirButton = () => {
const { t } = useTranslation();

return (
<Tooltip title={t('open-log-dir-tooltip')}>
<Button
sx={{
marginTop: '9px',
width: '100%',
height: '60%',
}}
onClick={async () => openLogDir().catch((e) => toast.error(`${e}`))}
startIcon={<FolderOpenIcon />}
type="button"
variant="outlined"
>
{t('open-log-dir-btn')}
</Button>
</Tooltip>
);
};
30 changes: 16 additions & 14 deletions frontend/src/components/buttons/log_file_btn.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FileOpen } from '@mui/icons-material';
import { Button } from '@mui/material';
import { Button, Tooltip } from '@mui/material';
import { toast } from 'react-hot-toast';

import { useTranslation } from '@/hooks';
Expand All @@ -9,18 +9,20 @@ export const LogFileButton = () => {
const { t } = useTranslation();

return (
<Button
sx={{
marginTop: '9px',
width: '100%',
height: '60%',
}}
onClick={async () => openLogFile().catch((e) => toast.error(`${e}`))}
startIcon={<FileOpen />}
type="button"
variant="outlined"
>
{t('open-log-btn')}
</Button>
<Tooltip title={t('open-log-tooltip')}>
<Button
sx={{
marginTop: '9px',
width: '100%',
height: '60%',
}}
onClick={async () => openLogFile().catch((e) => toast.error(`${e}`))}
startIcon={<FileOpen />}
type="button"
variant="outlined"
>
{t('open-log-btn')}
</Button>
</Tooltip>
);
};
19 changes: 16 additions & 3 deletions frontend/src/components/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ import { listen } from '@tauri-apps/api/event';
import { Controller, useForm, type SubmitHandler } from 'react-hook-form';
import { toast } from 'react-hot-toast';

import { ConvertButton, UnhideDarBtn, SelectPathButton, RemoveOarBtn, LogFileButton } from '@/components/buttons';
import {
ConvertButton,
UnhideDarBtn,
SelectPathButton,
RemoveOarBtn,
LogFileButton,
LogDirButton,
} from '@/components/buttons';
import { SelectLogLevel } from '@/components/lists';
import { LinearWithValueLabel } from '@/components/notifications';
import { useTranslation } from '@/hooks';
Expand Down Expand Up @@ -310,16 +317,22 @@ export function ConvertForm() {
)}
/>
</Grid>
<Grid xs={3}>

<Grid xs={2}>
<Controller
name="logLevel"
control={control}
render={({ field: { value } }) => <SelectLogLevel value={value} {...register('logLevel')} />}
/>
</Grid>
<Grid xs={3}>

<Grid xs={2}>
<LogFileButton />
</Grid>

<Grid xs={2}>
<LogDirButton />
</Grid>
</Grid>

<Grid container sx={{ alignItems: 'center' }}>
Expand Down
71 changes: 57 additions & 14 deletions frontend/src/tauri_cmd/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { selectLogLevel } from '@/utils/selector';

export { open as openShell } from '@tauri-apps/api/shell';

type ConverterArgs = {
type ConverterOptions = {
src: string;
dist?: string;
modName?: string;
Expand All @@ -20,10 +20,16 @@ type ConverterArgs = {
};

/**
* Convert DAR to OAR
* # Throw Error
* Converts DAR to OAR.
*
* This function converts a DAR (DynamicAnimationReplacer) to an OAR (OpenAnimationReplacer).
* It takes the specified properties as arguments and invokes the appropriate conversion command.
*
* @param {ConverterOptions} props - Converter Options.
* @returns {Promise<void>} A promise that resolves when converted.
* @throws
*/
export async function convertDar2oar(props: ConverterArgs): Promise<string> {
export async function convertDar2oar(props: ConverterOptions): Promise<void> {
const args = {
options: {
darDir: props.src === '' ? undefined : props.src,
Expand All @@ -42,13 +48,22 @@ export async function convertDar2oar(props: ConverterArgs): Promise<string> {

const showProgress = props.showProgress ?? false;
if (showProgress) {
return invoke<string>('convert_dar2oar_with_progress', args);
return invoke('convert_dar2oar_with_progress', args);
} else {
return invoke<string>('convert_dar2oar', args);
return invoke('convert_dar2oar', args);
}
}

export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error';

/**
* Changes the log level.
*
* This function invokes the 'change_log_level' command with the specified log level.
*
* @param {LogLevel} [logLevel] - The log level to set. If not provided, the default log level will be used.
* @returns {Promise<void>} A promise that resolves when the log level is changed.
*/
export async function changeLogLevel(logLevel?: LogLevel): Promise<void> {
return invoke('change_log_level', { logLevel });
}
Expand All @@ -58,29 +73,38 @@ export async function changeLogLevel(logLevel?: LogLevel): Promise<void> {
*
* # Throw Error
*/
export async function unhideDarDir(darDir: string, errMsg = 'DAR dir must be specified.') {
/**
* Add '.mohidden' to DAR's files.
* @param {string} darDir - A string representing the directory path of the DAR directory that needs to be
* unhidden.
*
* @throws
*/
export async function unhideDarDir(darDir: string) {
if (darDir === '') {
throw new Error(errMsg);
throw new Error('darDir is empty string.');
}
await invoke('unhide_dar_dir', { darDir });
}

/**
* @param darPath
*
* # Throw Error
* The function `removeOarDir` is an asynchronous function that removes a specified directory and throws an error if the
* path is empty.
* @param {string} path - The `path` parameter is a string that specifies the directory path of the DAR or OAR directory
* that needs to be removed.
* @throws
*/
export async function removeOarDir(path: string, errMsg = 'DAR or OAR dir must be specified.') {
export async function removeOarDir(path: string) {
if (path === '') {
throw new Error(errMsg);
throw new Error('Specified path is empty string.');
}
await invoke('remove_oar_dir', { path });
}

/**
* Open a file or Dir
*
* # Throw Error
* @throws
*/
export async function openPath(path: string, setPath: (path: string) => void, isDir: boolean) {
const res = await open({
Expand All @@ -96,8 +120,27 @@ export async function openPath(path: string, setPath: (path: string) => void, is
}
}

/**
* Opens the log file.
*
* This function retrieves the log directory using the appLogDir function,
* constructs the path to the log file, and opens the shell with the log file path.
*
* @throws - if not found path
*/
export async function openLogFile() {
const logDir = await appLogDir();
const logFile = `${logDir}g_dar2oar.log`;
await openShell(logFile);
}

/**
* Opens the log directory.
*
* This function opens the shell and awaits the result of the appLogDir function.
*
* @throws - if not found path
*/
export async function openLogDir() {
await openShell(await appLogDir());
}
5 changes: 4 additions & 1 deletion locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"log-level-list-tooltip4": "Error: Logs nothing but errors.",
"mapping-wiki-url-leaf": "wiki#what-is-the-mapping-file",
"open-log-btn": "Open log",
"open-log-dir-btn": "Log(dir)",
"open-log-tooltip": "Open current log file.(Rotate to a new log file each time the application is launched.)",
"open-log-dir-tooltip": "Open the log storage location.",
"progress-btn": "ProgressBar",
"progress-btn-tooltip": "Display detail progress",
"progress-btn-tooltip2": "",
Expand All @@ -49,7 +52,7 @@
"remove-oar-success": "Removed OAR directory.",
"remove-oar-tooltip": "Find and delete OAR dir from \"DAR(src) Directory*\" or \"OAR(dist) Directory\".",
"run-parallel-btn-tooltip": "Use multi-threading.",
"run-parallel-btn-tooltip2": "NOTE: More than twice the processing speed can be expected, but the logs are difficult to read.",
"run-parallel-btn-tooltip2": "Note: More than twice the processing speed can be expected, but the concurrent processing results in thread termination timings being out of order, so log writes will be out of order as well, greatly reducing readability of the logs.",
"run-parallel-label": "Run Parallel",
"select-btn": "Select",
"unhide-dar-btn": "Unhide DAR",
Expand Down
7 changes: 5 additions & 2 deletions locales/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@
"log-level-list-tooltip3": " Info: 変換時間を記録します",
"log-level-list-tooltip4": "Error: 重大なエラー以外記録しません",
"mapping-wiki-url-leaf": "wiki#what-is-the-mapping-file",
"open-log-btn": "ログを開く",
"open-log-btn": "ログを閲覧",
"open-log-dir-btn": "ログ(dir)",
"open-log-tooltip": "現在のログファイルを開きます。(アプリを起動するたびに新しいログファイルにローテーションします)",
"open-log-dir-tooltip": "ログの格納場所を開きます。",
"progress-btn": "進捗バー",
"progress-btn-tooltip": "詳細な進捗状況を表示します",
"progress-btn-tooltip2": "",
Expand All @@ -49,7 +52,7 @@
"remove-oar-success": "OARディレクトリを削除しました",
"remove-oar-tooltip": "OAR(dist)(なければDAR(src))からOARディレクトリを捜索して削除します",
"run-parallel-btn-tooltip": "マルチスレッドを使用します",
"run-parallel-btn-tooltip2": "注意: 2倍以上の処理速度が期待できますが、ログが読みづらいです",
"run-parallel-btn-tooltip2": "注意: 2倍以上の処理速度が期待できますが、平行処理によりスレッドの終了タイミングが順不同になるため、ログの書き込みも同様に順不同になりログの可読性が大幅に低下します。",
"run-parallel-label": "並列実行",
"select-btn": "選択",
"unhide-dar-btn": "DAR再表示",
Expand Down