Skip to content

A games launcher for GOG, Amazon and Epic Games for Linux, Windows and macOS.

3.4 KB
Raw Blame
/**
 * Types for the itch.io store integration.
 *
 * Field-naming convention:
 *   - butlerd JSON-RPC payloads use camelCase (apiKey, displayName,
 *     installFolder, caveId, ...). Types describing wire shapes — anything
 *     a butlerd call directly produces or consumes — therefore use
 *     camelCase.
 *   - Heroic's own `GameInfo` / `InstalledInfo` shapes use snake_case
 *     (app_name, install_path, install_size). `ItchioInstallInfo.manifest`
 *     mirrors those snake_case keys so the rest of Heroic's UI consumes
 *     the union without runtime branching.
 *
 * Reference: https://docs.itch.ovh/butlerd/master/
 */

import type { LaunchOption } from 'common/types'

// itch.io upload platforms exposed by butlerd. Lower-case in the wire format.
type ItchioInstallPlatform = 'windows' | 'linux' | 'osx'

// Where a library entry came from. Owned keys are games with a materialized
// download key, bundles are owned but not claimed yet, collections are the
// user's own lists (which may contain games they don't own).
export type ItchioGameSource = 'owned' | 'bundle' | 'collection'

// Whether Heroic can install the game: owned (key or bundle), free (no payment
// needed) or unowned (paid and not owned).
export type ItchioGameStatus = 'owned' | 'free' | 'unowned'

export interface ItchioUserData {
  id: number
  username: string
  displayName?: string
  url: string
  coverUrl?: string
  pressUser?: boolean
  developer?: boolean
  gamer?: boolean
}

export const ITCHIO_OAUTH_REDIRECT_URI = 'itch://oauth-callback'

export interface ItchioOAuthLoginData {
  url: string
}

export interface ItchioOAuthCodeData {
  code: string
  state: string
}

export interface ItchioLoginData {
  apiKeysUrl: string
}

export interface ItchioRegisterData {
  apiKey: string
}

interface ItchioGameUser {
  id: number
  username: string
  displayName?: string
  url: string
}

export interface ItchioGame {
  id: number
  title: string
  url: string
  shortText?: string
  coverUrl?: string
  stillCoverUrl?: string
  classification?:
    | 'game'
    | 'tool'
    | 'assets'
    | 'game_mod'
    | 'physical_game'
    | 'soundtrack'
    | 'other'
    | 'comic'
    | 'book'
  user: ItchioGameUser
  // butlerd reports platform support as a map keyed by 'windows' | 'linux'
  // | 'osx'. Values can be booleans or arch strings ("all", "x64"); we
  // treat any truthy value as supported.
  platforms?: Partial<Record<ItchioInstallPlatform, unknown>>
  // Price in cents; `canBeBought` is true when payments are accepted.
  minPrice?: number
  canBeBought?: boolean
  // itch.io has no DLC concept; declared as a required empty array so
  // the generic `InstallInfo['game'].owned_dlc` access in DownloadDialog
  // narrows cleanly across all union variants.
  owned_dlc: { app_name: string; title: string }[]
}

export interface ItchioUpload {
  id: number
  filename: string
  displayName?: string
  size: number
  channelName?: string
  platforms: Partial<Record<ItchioInstallPlatform, boolean>>
}

export interface ItchioInstallInfo {
  game: ItchioGame
  upload: ItchioUpload
  install_size: number
  download_size: number
  launch_options?: LaunchOption[]
  /**
   * Manifest shape kept structurally compatible with the rest of the
   * `InstallInfo` union so generic UI like DownloadDialog can read
   * `disk_size` / `download_size` without runtime branching.
   */
  manifest: {
    disk_size: number
    download_size: number
  }
}