Skip to content

Commit

Permalink
fix & improve steam auth on window
Browse files Browse the repository at this point in the history
  • Loading branch information
Armaldio committed Jan 14, 2025
1 parent 0b2d3f8 commit a86cebe
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .mise.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tools]
node = "latest"
node = "22"

[env]
_.file = '.env.local'
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@electron-toolkit/utils": "3.0.0",
"@floating-ui/vue": "1.1.5",
"@jitl/quickjs-wasmfile-release-sync": "0.31.0",
"@lydell/node-pty": "1.0.3",
"@pipelab/core": "1.3.3",
"@primevue/themes": "4.1.1",
"@sentry/electron": "5.4.0",
Expand Down
54 changes: 54 additions & 0 deletions pnpm-lock.yaml

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

37 changes: 37 additions & 0 deletions src/shared/libs/plugin-core/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Options, Subprocess } from 'execa'
import { IPty, type IPtyForkOptions, type IWindowsPtyForkOptions } from '@lydell/node-pty'

export const runWithLiveLogs = async (
command: string,
Expand Down Expand Up @@ -67,3 +68,39 @@ export const runWithLiveLogs = async (
})
})
}

export const runWithLiveLogsPTY = async (
command: string,
args: string[],
ptyOptions: IPtyForkOptions | IWindowsPtyForkOptions,
log: typeof console.log,
hooks?: {
onStdout?: (data: string, subprocess: IPty) => void
onStderr?: (data: string, subprocess: IPty) => void
onExit?: (code: number) => void
}
): Promise<void> => {
const { spawn } = await import('@lydell/node-pty')
return new Promise((resolve, reject) => {
log('runWithLiveLogsPTY', command, args, ptyOptions)
log('command: ', command, args.join(' '))

const subprocess = spawn(command, args, ptyOptions)

subprocess.onData((data) => {
log(data.toString())
hooks?.onStdout?.(data.toString(), subprocess)
})

subprocess.onExit(({ exitCode, signal }) => {
log('exit', exitCode)
hooks?.onExit?.(exitCode)

if (exitCode === 0) {
return resolve()
} else {
return reject(new Error(`Command exited with non-zero exitCode: ${exitCode}`))
}
})
})
}
8 changes: 3 additions & 5 deletions src/shared/libs/plugin-steam/upload-to-steam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ export const uploadToSteamRunner = createActionRunner<typeof uploadToSteam>(
const { join, dirname } = await import('path')
const { platform } = await import('os')
const { chmod, mkdir, writeFile } = await import('fs/promises')
// for esm
const { execa } = await import('execa')

log('uploading to steam')
const { folder, appId, sdk, depotId, username, description } = inputs
Expand Down Expand Up @@ -193,10 +191,10 @@ export const uploadToSteamRunner = createActionRunner<typeof uploadToSteam>(
username
})

console.log('isAuthenticated', isAuthenticated)
log('isAuthenticated', isAuthenticated)

if (isAuthenticated.success === false) {
console.log('OPEN STEAM AUTH')
log('OPEN STEAM AUTH terminal')
await openExternalTerminal(steamcmdPath, ['+login', username, '+quit'])
const isAuthenticatedNow = await checkSteamAuth({
context: {
Expand All @@ -222,7 +220,7 @@ export const uploadToSteamRunner = createActionRunner<typeof uploadToSteam>(
steamcmdPath,
['+login', username, '+run_app_build', scriptPath, '+quit'],
{},
log,
log
)
} catch (e) {
if (e instanceof Error) {
Expand Down
4 changes: 2 additions & 2 deletions src/shared/libs/plugin-steam/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { runWithLiveLogs } from '../plugin-core'
import { runWithLiveLogsPTY } from '../plugin-core'

export type Options = {
steamcmdPath: string
Expand All @@ -13,7 +13,7 @@ export const checkSteamAuth = async (options: Options) => {
let error: 'LOGGED_OUT' | 'UNKNOWN' | undefined = undefined

try {
await runWithLiveLogs(
await runWithLiveLogsPTY(
options.steamcmdPath,
['+login', options.username, '+quit'],
{},
Expand Down

0 comments on commit a86cebe

Please sign in to comment.