Skip to content

Commit

Permalink
add interactive steam auth
Browse files Browse the repository at this point in the history
add open external terminal
  • Loading branch information
Armaldio committed Jan 9, 2025
1 parent 61cf648 commit f79738e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 35 deletions.
46 changes: 15 additions & 31 deletions src/shared/libs/plugin-steam/upload-to-steam.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createAction, createActionRunner, runWithLiveLogs } from '@pipelab/plugin-core'
import { checkSteamAuth } from './utils'
import { checkSteamAuth, openExternalTerminal } from './utils'

// https://github.com/ztgasdf/steampkg?tab=readme-ov-file#account-management

Expand Down Expand Up @@ -196,49 +196,33 @@ export const uploadToSteamRunner = createActionRunner<typeof uploadToSteam>(
console.log('isAuthenticated', isAuthenticated)

if (isAuthenticated.success === false) {
await execa({
detached: true,
stdio: 'inherit'
})`echo Enter your password && read password`
// console.log('isAuthenticated.error', isAuthenticated.error)
// if (error === 'LOGGED_OUT') {
// options.context.log('You are not logged in to Steam')
// options.context.log('To log in, run command below:')
// options.context.log(`"${options.steamcmdPath}" +login ${options.username} +quit`)
// throw new Error(
// 'You are not logged in to Steam\nTo log in, run command below:\n' +
// `"${options.steamcmdPath}" +login ${options.username} +quit`
// )
// } else {
// throw new Error('Unknown error: ' + isAuthenticated.error)
// }
console.log('OPEN STEAM AUTH')
await openExternalTerminal(steamcmdPath, ['+login', username, '+quit'])
const isAuthenticatedNow = await checkSteamAuth({
context: {
log
},
scriptPath,
steamcmdPath,
username
})
if (isAuthenticatedNow.success === false) {
throw new Error('Not authenticated')
}
}

log('Writing script')
await writeFile(scriptPath, script, 'utf8')

log('Executing steamcmd')

let error: string = ''

// SHould be authed here
try {
await runWithLiveLogs(
steamcmdPath,
['+login', username, '+run_app_build', scriptPath, '+quit'],
{},
log,
{
onStdout: (data, subprocess) => {
log('data stdout', data)

// TODO: handle password input dynamically
if (data.includes('Cached credentials not found')) {
error = 'LOGGED_OUT'

subprocess.kill()
}
}
}
)
} catch (e) {
if (e instanceof Error) {
Expand Down
29 changes: 25 additions & 4 deletions src/shared/libs/plugin-steam/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export const checkSteamAuth = async (options: Options) => {
options.context.log,
{
onStdout: (data, subprocess) => {
options.context.log('data stdout', data)

// TODO: handle password input dynamically
if (data.includes('Cached credentials not found')) {
error = 'LOGGED_OUT'
Expand All @@ -38,8 +36,6 @@ export const checkSteamAuth = async (options: Options) => {
}
}

console.warn('error', error)

if (error) {
return {
success: false,
Expand All @@ -51,3 +47,28 @@ export const checkSteamAuth = async (options: Options) => {
success: true
}
}

export const openExternalTerminal = async (command: string, args: string[] = [], options = {}) => {
const { execa } = await import('execa')
const os = await import('os')

const platform = os.platform()

try {
if (platform === 'darwin') {
// macOS
await execa('open', ['-a', 'Terminal', command, ...args], options)
} else if (platform === 'linux') {
// Linux
const terminal = process.env.TERMINAL ?? process.env.TERM ?? 'xterm'
await execa(terminal, ['-e', command, ...args], options)
} else if (platform === 'win32') {
// Windows
await execa('cmd', ['/c', command, ...args], options)
} else {
throw new Error('Unsupported platform:' + platform)
}
} catch (error) {
throw new Error('Error opening terminal:' + error.message)
}
}

0 comments on commit f79738e

Please sign in to comment.