Skip to content

Commit d0c2f5c

Browse files
committed
支持单独打开资源
1 parent 660031d commit d0c2f5c

File tree

3 files changed

+52
-9
lines changed

3 files changed

+52
-9
lines changed

src-tauri/src/api/launcher_api.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,13 @@ pub async fn launch(
314314
Ok(())
315315
}
316316

317+
/// 打开路径
318+
#[tauri::command]
319+
pub async fn open_path(app: AppHandle, path: &str) -> Result<(), OneClickLaunchError> {
320+
open_using_default_program(&app, path)?;
321+
Ok(())
322+
}
323+
317324
pub fn launch_resources(app: &AppHandle, resources: &[LauncherResource]) {
318325
for resource in resources.iter() {
319326
if let Err(e) = open_using_default_program(app, resource.path.as_str()) {

src-tauri/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ pub async fn run() -> Result<()> {
143143
launcher_api::delete_resource,
144144
launcher_api::query_launchers,
145145
launcher_api::launch,
146+
launcher_api::open_path,
146147
setting_api::save_setting,
147148
setting_api::read_setting,
148149
setting_api::read_all_setting,

src/launcher.vue

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,24 @@
5454
</span>
5555
<input v-if="editingResourceState.get(item.id)" v-model="newResourceName" class="name-input"
5656
@blur="saveResourceName(item)" @keyup.enter="saveResourceName(item)" />
57-
<span>{{ item.path }}</span>
57+
<span>
58+
{{ item.path }}
59+
</span>
5860
</span>
59-
<button class="delete-button" @click="deleteRow(item.id)" title="删除">
60-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" width="16"
61-
height="16">
62-
<path
63-
d="M9 3v1H4v2h16V4h-5V3H9zM5 7v12c0 1.1.9 2 2 2h10c1.1 0 2-.9 2-2V7H5zm4 2h2v8H9V9zm4 0h2v8h-2V9z" />
64-
</svg>
65-
</button>
61+
<Press class="press" theme="outline" size="19" @click="openPath(item)" />
62+
<el-popconfirm title="确定要删除吗?" confirm-button-text="确认" cancel-button-text="取消"
63+
@confirm="deleteRow(item.id)">
64+
<template #reference>
65+
<button class="delete-button" title="删除">
66+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" width="16"
67+
height="16">
68+
<path
69+
d="M9 3v1H4v2h16V4h-5V3H9zM5 7v12c0 1.1.9 2 2 2h10c1.1 0 2-.9 2-2V7H5zm4 2h2v8H9V9zm4 0h2v8h-2V9z" />
70+
</svg>
71+
</button>
72+
</template>
73+
</el-popconfirm>
74+
6675
</div>
6776
</div>
6877
<button class="launch-button" :disabled="isLaunching" @click="launch">
@@ -88,6 +97,7 @@ import { invoke } from "@tauri-apps/api/core";
8897
import { useToast } from "vue-toastification";
8998
import { platform } from '@tauri-apps/plugin-os'
9099
import { ref, reactive, onMounted, nextTick, onBeforeMount } from 'vue';
100+
import { Press } from '@icon-park/vue-next';
91101
92102
export default {
93103
props: {
@@ -96,6 +106,9 @@ export default {
96106
required: true, // 确保传入数据
97107
},
98108
},
109+
components: {
110+
Press
111+
},
99112
setup(props, { emit }) {
100113
const toast = useToast()
101114
// 控制下拉菜单的显示
@@ -206,6 +219,10 @@ export default {
206219
isLaunching.value = false; // 恢复按钮状态
207220
}
208221
};
222+
const openPath = async (item) => {
223+
await invoke("open_path", { path: item.path });
224+
toast.success(item.name + " 已打开!");
225+
};
209226
const showAddUrlDialog = () => {
210227
showDialog.value = true; // 打开添加网址的对话框
211228
dropdownVisible.value = false; // 关闭下拉菜单
@@ -269,7 +286,8 @@ export default {
269286
closeDialog,
270287
moveLauncher,
271288
debounce,
272-
debouncedLaunch
289+
debouncedLaunch,
290+
openPath
273291
};
274292
}
275293
};
@@ -521,4 +539,21 @@ hr {
521539
.mo-launcher {
522540
font-size: 18px;
523541
}
542+
543+
.press {
544+
transition: transform 0.3s ease, fill 0.3s ease;
545+
color: #a19797;
546+
}
547+
548+
.press:hover {
549+
transform: scale(1.05);
550+
color: #218838;
551+
}
552+
553+
.press:active {
554+
/* 点击时更深的绿色 */
555+
color: #1e7e34;
556+
/* 点击时缩小效果 */
557+
transform: scale(0.95);
558+
}
524559
</style>

0 commit comments

Comments
 (0)