Skip to content

Commit

Permalink
Merge pull request #79 from SRVFI-Raws/main
Browse files Browse the repository at this point in the history
你陪了我多少年,花开花落,一路上起起跌跌
  • Loading branch information
DamnCrab authored Jul 19, 2023
2 parents fd28d8e + ccfb3d9 commit de73b31
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 31 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Final2x",
"productName": "Final2x",
"version": "1.1.1",
"version": "1.1.2",
"description": "A cross-platform image super-resolution tool.",
"main": "./out/main/index.js",
"author": "Tohrusky",
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/src/utils/IOPath.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { storeToRefs } from 'pinia'
import { useIOPathStore } from '../store/ioPathStore'
import PathFormat from '../utils/pathFormat'

class ioPATH {
static add(id: string, path: string): void {
Expand Down Expand Up @@ -61,7 +62,8 @@ class ioPATH {

static setoutputpath(path: string): void {
const { outputpath, outputpathLock } = storeToRefs(useIOPathStore())
if (path != '' && outputpathLock.value == false) {
// if outputpathLock is false or outputpath is empty, set outputpath
if (path != '' && (outputpathLock.value == false || !PathFormat.checkPath(outputpath.value))) {
outputpath.value = path
} else {
console.log('outputpath Lock!')
Expand Down
14 changes: 13 additions & 1 deletion src/renderer/src/utils/getFinal2xconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { storeToRefs } from 'pinia'
import { useSRSettingsStore } from '../store/SRSettingsStore'
import { useGlobalSettingsStore } from '../store/globalSettingsStore'
import ioPath from '../utils/IOPath'
import PathFormat from '../utils/pathFormat'

// {
// "gpuid": 0, // GPU id, >= -1 (-1 for CPU, may not work for some models.)
Expand Down Expand Up @@ -31,14 +32,25 @@ import ioPath from '../utils/IOPath'
// tta: boolean
// }

function getOutPutPATH(): string {
if (!PathFormat.checkPath(ioPath.getoutputpath())) {
const inputPATHList = ioPath.getList()
const pathFormat = new PathFormat()
pathFormat.setRootPath(inputPATHList[0])
ioPath.setoutputpath(pathFormat.getRootPath())
}
return ioPath.getoutputpath()
}

export const getFinal2xconfig = (): string => {
const { selectedModel, selectedScale, selectedNoise, useTTA, CustomScaleValue } = storeToRefs(
useSRSettingsStore()
)
const { SRgpuid } = storeToRefs(useGlobalSettingsStore())

const gpuID = SRgpuid.value === 114514 ? 0 : SRgpuid.value
const inputPATHList = ioPath.getList()
const outputPATH = ioPath.getoutputpath()
const outputPATH = getOutPutPATH()
const targetScale = CustomScaleValue.value === null ? 0 : CustomScaleValue.value
return JSON.stringify({
gpuid: gpuID,
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/utils/pathFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PathFormat {
return this.rootpath + segments.join(this.rootpath.startsWith('/') ? '/' : '\\')
}

checkPath(path: string): boolean {
static checkPath(path: string): boolean {
return path.startsWith('/') || path.includes('\\')
}
}
Expand Down
66 changes: 49 additions & 17 deletions src/renderer/src/views/Final2xSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,15 @@ class ClickButtomToConsoleLog {
<template>
<n-card :bordered="false" class="settings-card">
<n-space class="vertical" vertical justify="center">
<n-space justify="space-between">
<n-space>
<n-popover trigger="hover" :width="400">
<template #trigger>
<n-button dashed type="success" @click="ClickButtomToConsoleLog.SRgpuid()">
<n-button
dashed
type="success"
style="width: 80px"
@click="ClickButtomToConsoleLog.SRgpuid()"
>
Device
</n-button>
</template>
Expand All @@ -259,10 +264,15 @@ class ClickButtomToConsoleLog {

<n-select v-model:value="SRgpuid" :options="deviceList" style="width: 465px" />
</n-space>
<n-space justify="space-between">
<n-space>
<n-popover trigger="hover" :width="400">
<template #trigger>
<n-button dashed type="success" @click="ClickButtomToConsoleLog.selectedModel()">
<n-button
dashed
type="success"
style="width: 80px"
@click="ClickButtomToConsoleLog.selectedModel()"
>
Model
</n-button>
</template>
Expand All @@ -272,11 +282,16 @@ class ClickButtomToConsoleLog {
v-model:value="selectedModel"
:fallback-option="ModelOptionsFallBack"
:options="getEnabledModelOptions"
style="width: 250px"
style="width: 206px"
/>
<n-popover trigger="hover">
<template #trigger>
<n-button dashed type="success" @click="ClickButtomToConsoleLog.selectedScale()">
<n-button
dashed
type="success"
style="width: 120px"
@click="ClickButtomToConsoleLog.selectedScale()"
>
Model Scale
</n-button>
</template>
Expand All @@ -286,13 +301,18 @@ class ClickButtomToConsoleLog {
v-model:value="selectedScale"
:fallback-option="ScaleOptionsFallBack"
:options="getScaleOptions"
style="width: 88px"
style="width: 115px"
/>
</n-space>
<n-space justify="space-between">
<n-popover trigger="hover" :width="400">
<n-space>
<n-popover trigger="hover">
<template #trigger>
<n-button dashed type="success" @click="ClickButtomToConsoleLog.selectedNoise()">
<n-button
dashed
type="success"
style="width: 80px"
@click="ClickButtomToConsoleLog.selectedNoise()"
>
Denoise
</n-button>
</template>
Expand All @@ -306,9 +326,14 @@ class ClickButtomToConsoleLog {
style="width: 80px"
/>

<n-popover trigger="hover" :width="400">
<n-popover trigger="hover">
<template #trigger>
<n-button dashed type="success" @click="ClickButtomToConsoleLog.useTTA()">
<n-button
dashed
type="success"
style="width: 54px"
@click="ClickButtomToConsoleLog.useTTA()"
>
TTA
</n-button>
</template>
Expand All @@ -317,9 +342,14 @@ class ClickButtomToConsoleLog {

<n-switch v-model:value="useTTA" size="large" style="height: 35px"></n-switch>

<n-popover trigger="hover" :width="400">
<n-popover trigger="hover" :width="200">
<template #trigger>
<n-button dashed type="success" @click="ClickButtomToConsoleLog.CustomScale()">
<n-button
dashed
type="success"
style="width: 120px"
@click="ClickButtomToConsoleLog.CustomScale()"
>
Custom Scale
</n-button>
</template>
Expand All @@ -332,19 +362,21 @@ class ClickButtomToConsoleLog {
:min="0"
:step="0.2"
placeholder="Default"
style="width: 110px"
style="width: 115px"
/>
</n-space>

<n-space>
<n-popover trigger="hover">
<template #trigger>
<n-button round type="success" @click="getPath"> Output Folder</n-button>
<n-button round type="success" style="width: 171px" @click="getPath">
Output Folder
</n-button>
</template>
<span> {{ MyPopoverMessages.OutputFolder() }} </span>
</n-popover>

<n-input v-model:value="outputpath" :placeholder="outputpath" round style="width: 411px" />
<n-input v-model:value="outputpath" :placeholder="outputpath" round style="width: 374px" />
</n-space>
</n-space>
</n-card>
Expand Down
9 changes: 8 additions & 1 deletion test/utils/IOPath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

import ioPath from '../../src/renderer/src/utils/IOPath'
import { beforeEach, describe, expect, it } from 'vitest'
import { createPinia, setActivePinia } from 'pinia'
import { createPinia, setActivePinia, storeToRefs } from 'pinia'
import { useIOPathStore } from '../../src/renderer/src/store/ioPathStore'

describe('IOPath', () => {
beforeEach(() => {
setActivePinia(createPinia())
})

it('test_ioPath', () => {
const { outputpath } = storeToRefs(useIOPathStore())

// test inputpath
ioPath.add('114514', 'test')
expect(ioPath.getByID('114514')).toBe('test')
Expand All @@ -35,6 +38,10 @@ describe('IOPath', () => {
expect(ioPath.getoutputpath()).toBe('/test2')
ioPath.setoutputpath('')
expect(ioPath.getoutputpath()).toBe('/test2')
outputpath.value = '' // 模拟用户手动清除outputpath
ioPath.setoutputpath('/testWhenEmpty')
expect(ioPath.getoutputpath()).toBe('/testWhenEmpty')
ioPath.setoutputpathManual('/test2')

// clear ALL
ioPath.add('114514', 'test')
Expand Down
5 changes: 3 additions & 2 deletions test/utils/getFinal2xconfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ describe('getFinal2xconfig', () => {
})

it('test_getFinal2xconfig', () => {
ioPath.add('114514', '/Users/Downloads/114514')
expect(getFinal2xconfig()).toEqual(
'{"gpuid":0,"inputpath":[],"model":"RealESRGAN","modelscale":2,"modelnoise":-1,"outputpath":"","targetscale":0,"tta":false}'
'{"gpuid":0,"inputpath":["/Users/Downloads/114514"],"model":"RealESRGAN","modelscale":2,"modelnoise":-1,"outputpath":"/Users/Downloads","targetscale":0,"tta":false}'
)
ioPath.setoutputpath('/test')
expect(getFinal2xconfig()).toEqual(
'{"gpuid":0,"inputpath":[],"model":"RealESRGAN","modelscale":2,"modelnoise":-1,"outputpath":"/test","targetscale":0,"tta":false}'
'{"gpuid":0,"inputpath":["/Users/Downloads/114514"],"model":"RealESRGAN","modelscale":2,"modelnoise":-1,"outputpath":"/test","targetscale":0,"tta":false}'
)
ioPath.add('114514', '/test1')
expect(getFinal2xconfig()).toEqual(
Expand Down
9 changes: 4 additions & 5 deletions test/utils/pathFormat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ describe('PathFormat', () => {
})

it('checkpath', () => {
const pathFormat = new PathFormat()
const check: Array<boolean> = [
pathFormat.checkPath('/Users/test/Downloads/unix'),
pathFormat.checkPath('C:\\Users\\test\\Downloads\\win'),
pathFormat.checkPath('C:Users/test/Downloads/unix/test.txt'),
pathFormat.checkPath('Users/test/Downloads/unix/test.txt')
PathFormat.checkPath('/Users/test/Downloads/unix'),
PathFormat.checkPath('C:\\Users\\test\\Downloads\\win'),
PathFormat.checkPath('C:Users/test/Downloads/unix/test.txt'),
PathFormat.checkPath('Users/test/Downloads/unix/test.txt')
]
expect(check).toStrictEqual([true, true, false, false])
})
Expand Down

0 comments on commit de73b31

Please sign in to comment.