Skip to content

Commit

Permalink
Reveal file
Browse files Browse the repository at this point in the history
Signed-off-by: xychen <[email protected]>
  • Loading branch information
xychen committed Jun 17, 2024
1 parent 669beb1 commit b037a3a
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 21 deletions.
23 changes: 23 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@tauri-apps/api": "^2.0.0-beta.11",
"@tauri-apps/plugin-dialog": "^2.0.0-beta.3",
"@tauri-apps/plugin-fs": "^2.0.0-beta.3",
"@tauri-apps/plugin-os": "^2.0.0-beta.5",
"@tauri-apps/plugin-process": "^2.0.0-beta.3",
"@tauri-apps/plugin-shell": "^2.0.0-beta.3",
"@tauri-apps/plugin-updater": "^2.0.0-beta.3",
Expand Down
49 changes: 49 additions & 0 deletions src-tauri/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 src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ tauri-build = { version = "2.0.0-beta", features = [] }
tauri = { version = "2.0.0-beta", features = [] }
tauri-plugin-dialog = "2.0.0-beta.7"
tauri-plugin-fs = "2.0.0-beta.7"
tauri-plugin-os = "2.0.0-beta"
tauri-plugin-process = "2.0.0-beta.4"
tauri-plugin-shell = "2.0.0-beta.4"
tauri-plugin-updater = "2.0.0-beta.5"
Expand Down
19 changes: 19 additions & 0 deletions src-tauri/capabilities/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,29 @@
"cmd": "",
"args": true,
"sidecar": true
},
{
"name": "reveal-file-windows",
"cmd": "Explorer",
"args": true,
"sidecar": false
},
{
"name": "reveal-file-macos",
"cmd": "open",
"args": true,
"sidecar": false
},
{
"name": "reveal-file-linux",
"cmd": "dbus-send",
"args": true,
"sidecar": false
}
]
},
"shell:allow-kill",
"os:allow-os-type",
"process:allow-restart",
"updater:default",
"window:allow-destroy",
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 @@ -16,6 +16,7 @@ fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_process::init())
.plugin(tauri_plugin_shell::init())
.setup(|app| {
Expand Down
18 changes: 12 additions & 6 deletions src/components/datatable/FieldBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
</selectable-text>
</n-element>
<template v-for="button in (props.buttons || [])">
<n-button :class="$style.button" size="small" quaternary circle @click="button.onClick">
<template #icon>
<n-icon>
<component :is="button.icon" />
</n-icon>
<n-tooltip>
<template #trigger>
<n-button :class="$style.button" size="small" quaternary circle @click="button.onClick">
<template #icon>
<n-icon>
<component :is="button.icon" />
</n-icon>
</template>
</n-button>
</template>
</n-button>
{{ button.title }}
</n-tooltip>
</template>
</n-flex>
</template>
Expand All @@ -24,6 +29,7 @@ import {
NElement,
NFlex,
NIcon,
NTooltip,
} from 'naive-ui';
import SelectableText from '@/components/common/SelectableText.vue';
Expand Down
50 changes: 40 additions & 10 deletions src/components/sections/PartitionView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,56 @@
<selectable-text :class="$style.name" selectable>{{ image.file.name }}</selectable-text>
<n-space>
<file-size :class="$style.size" :size="image.file.size" />
<span>-</span>
<template v-if="props.errors[0]">
<span>-</span>
<n-text type="error">{{ props.errors[0] }}</n-text>
</template>
<template v-if="props.progress.status == FlashStatus.STOPPED">
<span>-</span>
<n-text type="error">已停止</n-text>
</template>
<template v-else-if="props.progress.status == FlashStatus.ERROR">
<span>-</span>
<n-text type="error">异常</n-text>
</template>
<template v-else-if="props.progress.status == FlashStatus.FLASHING">
<span>-</span>
<n-text>{{ (props.progress.progress * 100).toFixed(1) }}%</n-text>
</template>
<template v-else-if="props.progress.status == FlashStatus.VERIFYING">
<span>-</span>
<n-text>校验中…</n-text>
</template>
<template v-else-if="props.progress.status == FlashStatus.SUCCESS">
<span>-</span>
<n-text type="success">已完成</n-text>
</template>
<template v-else>
<n-text>未开始</n-text>
</template>
</n-space>
<n-space>
<n-tooltip>
<template #trigger>
<n-button size="small" quaternary circle
@click="() => image?.format == 'hex' && revealFile(image.file.path)">
<template #icon>
<n-icon>
<search-16-regular />
</n-icon>
</template>
</n-button>
</template>
定位文件
</n-tooltip>
<n-tooltip>
<template #trigger>
<n-button size="small" quaternary circle :disabled="props.busy" @click="() => image = null">
<template #icon>
<n-icon>
<delete-16-regular />
</n-icon>
</template>
</n-button>
</template>
重新选择
</n-tooltip>
</n-space>
<n-button secondary :disabled="props.busy" :style="{ marginTop: '16px' }" @click="() => image = null">
重新选择
</n-button>
</n-flex>
</n-element>
<partition-table v-else-if="image.format == 'bin'" :partitions="image.partitions" :style="{ height: '100%' }">
Expand All @@ -67,7 +89,13 @@
<field-base>{{ index + 1 }}</field-base>
</template>
<template #column-name="{ data }">
<field-base selectable>{{ data.file.name }}</field-base>
<field-base selectable :buttons="[
{
icon: Search16Regular,
title: '定位文件',
onClick: () => revealFile(data.file.containerPath ?? data.file.path),
},
]">{{ data.file.name }}</field-base>
</template>
<template #column-addr="{ index }">
<field-addr v-model:value="state![index].addr" :placeholder="toHex(image.partitions[index].addr)"
Expand Down Expand Up @@ -149,6 +177,7 @@ import {
Add12Regular,
Delete16Regular,
ErrorCircle16Regular,
Search16Regular,
} from '@vicons/fluent';
import { isEmpty } from 'radash';
import { open } from '@tauri-apps/plugin-dialog';
Expand All @@ -167,6 +196,7 @@ import PartitionTable from '@/components/common/PartitionTable.vue';
import FieldBase from '@/components/datatable/FieldBase.vue';
import FieldAddr from '@/components/datatable/FieldAddr.vue';
import FieldProgress from '@/components/datatable/FieldProgress.vue';
import { revealFile } from '@/utils/revealFile';
export interface IPartitionState {
addr: string;
Expand Down
15 changes: 11 additions & 4 deletions src/utils/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export interface IFileRef {
*/
path: string;

/**
* Path of the container file (for example, a .lpk file) that this file is
* extracted from (if any).
*/
containerPath?: string;

/**
* Display name of the file.
*/
Expand Down Expand Up @@ -78,22 +84,23 @@ export class LocalFile extends BaseFile {
}

export class TmpFile extends BaseFile {
static async from(pseudoPath: string, content: Uint8Array): Promise<TmpFile> {
static async from(pseudoPath: string, content: Uint8Array, containerPath?: string): Promise<TmpFile> {
const tmpDir = await ensureTmpDir();

const path = await join(tmpDir, generateTmpFileName());
const name = await basename(pseudoPath);

await writeFile(path, content);

return new TmpFile(path, name, content.length);
return new TmpFile(path, name, content.length, containerPath);
}

static clone(base: TmpFile): TmpFile {
return new TmpFile(base.path, base.name, base.size);
return new TmpFile(base.path, base.name, base.size, base.containerPath);
}

private constructor(path: string, name: string, size: number) {
private constructor(path: string, name: string, size: number,
readonly containerPath?: string) {
super(path, name, size);
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/readLpk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export async function readLpk(path: string): Promise<IPartition[]> {
const partitions = await invoke('read_lpk', { path });
return partitions.map((part) => ({
addr: part.addr,
file: TmpFile.clone(part.file),
file: TmpFile.clone({ ...part.file, containerPath: path }),
}));
}
27 changes: 27 additions & 0 deletions src/utils/revealFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Command } from '@tauri-apps/plugin-shell';
import { type } from '@tauri-apps/plugin-os';

export async function revealFile(path: string): Promise<void> {
const os = await type();
switch (os) {
case 'windows':
await Command.create('reveal-file-windows', [`/select,"${path}"`]).execute();
break;
case 'macos':
await Command.create('reveal-file-macos', ['-R', path]).execute();
break;
case 'linux':
await Command.create('reveal-file-linux', [
'--print-reply',
'--dest=org.freedesktop.FileManager1',
'/org/freedesktop/FileManager1',
'org.freedesktop.FileManager1.ShowItems',
`array:string:"file://${path}"`,
'string:""',
]).execute();
break;
default:
// Not supported
break;
}
}

0 comments on commit b037a3a

Please sign in to comment.