Skip to content
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
13 changes: 4 additions & 9 deletions src/main/runCommand.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Final2xCoreConfig } from '@shared/type/core'
import type { IpcMainEvent } from 'electron'
import type { ChildProcessWithoutNullStreams } from 'node:child_process'
import { spawn } from 'node:child_process'
Expand All @@ -8,22 +9,16 @@ import { getCorePath } from './getCorePath'

let child: ChildProcessWithoutNullStreams | null = null

export async function runCommand(
event: IpcMainEvent,
config_json: string,
openOutputFolder: boolean,
): Promise<void> {
// ---- 还是直接传base64吧
// config_json = JSON.stringify(config_json) // 转义转义
// ----
export async function runCommand(event: IpcMainEvent, coreConfig: Final2xCoreConfig): Promise<void> {
let config_json = JSON.stringify(coreConfig.config)
// eslint-disable-next-line node/prefer-global/buffer
config_json = Buffer.from(config_json, 'utf8').toString('base64')

const resourceUrl = getCorePath()

let command = `"${resourceUrl}" -b ${config_json}`

if (!openOutputFolder) {
if (!coreConfig.options.open_output_folder) {
command += ' -n'
}

Expand Down
12 changes: 5 additions & 7 deletions src/renderer/src/components/MyProgress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { storeToRefs } from 'pinia'
import { nextTick, onMounted, ref, watchEffect } from 'vue'
import { useI18n } from 'vue-i18n'
import { useGlobalSettingsStore } from '../store/globalSettingsStore'
import { getFinal2xConfig } from '../utils/getFinal2xConfig'
import { getFinal2xCoreConfig } from '../utils/getFinal2xCoreConfig'
import IOPath from '../utils/IOPath'

const { t } = useI18n()
Expand All @@ -17,7 +17,6 @@ const {
StartCommandLock,
SrSuccess,
ProgressPercentage,
openOutputFolder,
} = storeToRefs(useGlobalSettingsStore())

const showLOG = ref(false)
Expand Down Expand Up @@ -150,12 +149,11 @@ function StartSR(): void {

MyProgressNotifications.StartSR()

const command = getFinal2xConfig()
// get Final2x-core config
const final2xCoreConfig = getFinal2xCoreConfig()
CommandLOG.value += `\n${JSON.stringify(final2xCoreConfig)}\n`

CommandLOG.value += `\n${command}\n`
CommandLOG.value += `OPEN OUTPUT FOLDER: ${openOutputFolder.value}\n`

window.electron.ipcRenderer.send(IpcChannelSend.EXECUTE_COMMAND, command, openOutputFolder.value)
window.electron.ipcRenderer.send(IpcChannelSend.EXECUTE_COMMAND, final2xCoreConfig)
}

function TerminateSR(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Final2xCoreConfig } from '@shared/type/core'
import { useGlobalSettingsStore } from '@renderer/store/globalSettingsStore'
import { storeToRefs } from 'pinia'
import { useSRSettingsStore } from '../store/SRSettingsStore'
import PathFormat from '../utils/pathFormat'
Expand All @@ -19,8 +21,9 @@ function getOutPutPATH(): string {
/**
* @description: 返回最终的json字符串配置文件
*/
export function getFinal2xConfig(): string {
export function getFinal2xCoreConfig(): Final2xCoreConfig {
const { selectedSRModel, ghProxy, targetScale, selectedTorchDevice, useTile, saveFormat } = storeToRefs(useSRSettingsStore())
const { openOutputFolder } = storeToRefs(useGlobalSettingsStore())

const inputPATHList = IOPath.getList()
const outputPATH = getOutPutPATH()
Expand All @@ -33,14 +36,19 @@ export function getFinal2xConfig(): string {
_gh_proxy = ghProxy.value
}

return JSON.stringify({
pretrained_model_name: selectedSRModel.value,
device: selectedTorchDevice.value,
gh_proxy: _gh_proxy,
target_scale: targetScale.value,
output_path: outputPATH,
input_path: inputPATHList,
use_tile: useTile.value,
save_format: saveFormat.value,
})
return {
config: {
pretrained_model_name: selectedSRModel.value,
device: selectedTorchDevice.value,
gh_proxy: _gh_proxy,
target_scale: targetScale.value,
output_path: outputPATH,
input_path: inputPATHList,
use_tile: useTile.value,
save_format: saveFormat.value,
},
options: {
open_output_folder: openOutputFolder.value,
},
}
}
15 changes: 15 additions & 0 deletions src/shared/type/core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export interface Final2xCoreConfig {
config: {
pretrained_model_name: string
device: string
gh_proxy: string | null
target_scale: number | null
output_path: string
input_path: string[]
use_tile: boolean
save_format: string
}
options: {
open_output_folder: boolean
}
}
30 changes: 0 additions & 30 deletions test/web/getFinal2xConfig.test.ts

This file was deleted.

Loading