-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show result path & refactor result component (#38)
- Loading branch information
1 parent
e7ee512
commit 8d1352d
Showing
5 changed files
with
173 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<script lang="ts"> | ||
import { getFileName, getTruncatedFilePath } from '../../../utils/path'; | ||
import { getIcon } from '../../../utils/icon'; | ||
export let filePath; | ||
export let resultType: number; | ||
</script> | ||
|
||
<button on:click class="searchResult" id={filePath}> | ||
<div class="resultContent"> | ||
{#await getIcon(getFileName(filePath).replace(/.app$/, ''))} | ||
<span class="icon" /> | ||
{:then { icon, fallbackIcon }} | ||
<img | ||
class="icon" | ||
src={icon} | ||
alt="" | ||
on:error={event => { | ||
// @ts-ignore | ||
event.target.src = fallbackIcon; | ||
}} | ||
/> | ||
{/await} | ||
<p class="fileName"> | ||
{getFileName(filePath).replace(/.app$/, '')} | ||
</p> | ||
</div> | ||
{#if resultType == 2} | ||
<div class="resultPathDiv"> | ||
<p class="resultPathText"> | ||
{getTruncatedFilePath(filePath)} | ||
</p> | ||
</div> | ||
{/if} | ||
</button> | ||
|
||
<style> | ||
.resultPathDiv { | ||
position: relative; | ||
right: 0%; | ||
} | ||
.resultPathText { | ||
font-family: Helvetica; | ||
font-style: normal; | ||
font-weight: 500; | ||
font-size: 12px; | ||
line-height: 20px; | ||
margin: 0; | ||
color: var(--secondary-text-color); | ||
width: 250px; | ||
text-align: right; | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} | ||
.searchResult { | ||
margin-top: 7px; | ||
margin-left: 12px; | ||
box-sizing: border-box; | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
padding: 0px 12px; | ||
width: 726px; | ||
height: 43px; | ||
background: transparent; | ||
border: none; | ||
border-radius: 8px; | ||
flex: none; | ||
order: 1; | ||
flex-grow: 0; | ||
} | ||
.resultContent { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
flex: none; | ||
order: 0; | ||
flex-grow: 0; | ||
margin-right: auto; | ||
} | ||
.icon { | ||
display: inline-flex; | ||
width: 24px; | ||
height: 24px; | ||
margin-right: 8px; | ||
} | ||
.fileName { | ||
font-family: Helvetica; | ||
font-style: normal; | ||
font-weight: 500; | ||
font-size: 14px; | ||
line-height: 20px; | ||
margin: 0; | ||
color: var(--primary-text-color); | ||
text-align: left; | ||
width: 250px; | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { resolveResource, appDataDir, join } from '@tauri-apps/api/path'; | ||
import { FALLBACK_ICON_SYMBOL, icons } from '../cache'; | ||
import { convertFileSrc } from '@tauri-apps/api/tauri'; | ||
|
||
export const getIcon = async (app_name: string) => { | ||
let icon = icons.get(app_name); | ||
let fallbackIcon = icons.get(FALLBACK_ICON_SYMBOL); | ||
|
||
if (icon && fallbackIcon) { | ||
return { icon, fallbackIcon }; | ||
} | ||
|
||
if (!fallbackIcon) { | ||
fallbackIcon = convertFileSrc(await resolveResource('assets/default.svg')); | ||
icons.set(FALLBACK_ICON_SYMBOL, fallbackIcon); | ||
} | ||
|
||
let iconPath: string; | ||
if ( | ||
[ | ||
'Migration Assistant', | ||
'System Information', | ||
'Calendar', | ||
'System Settings', | ||
'Photo Booth', | ||
'AirPort Utility', | ||
].includes(app_name) | ||
) { | ||
iconPath = await resolveResource(`assets/appIcons/${app_name}.app.png`); | ||
} else { | ||
const appDataDirPath = await appDataDir(); | ||
iconPath = await join(appDataDirPath, `appIcons/${app_name}.app.png`); | ||
} | ||
|
||
icon = convertFileSrc(iconPath); | ||
icons.set(app_name, icon); | ||
return { icon, fallbackIcon }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const getFileName = (path: string) => { | ||
return path.split('/').pop(); | ||
}; | ||
|
||
const getTruncatedFilePath = (path: string) => { | ||
const pathArray = path.split('/'); | ||
const fileName = pathArray.pop(); | ||
const fileDir = pathArray.pop(); | ||
const fileParentDir = pathArray.pop(); | ||
return `${fileParentDir}/${fileDir}/${fileName}`; | ||
}; | ||
|
||
export { getFileName, getTruncatedFilePath }; |