Skip to content

Commit

Permalink
Merge pull request #442 from hydralauncher/feature/steam-client-icon-…
Browse files Browse the repository at this point in the history
…cache

feat: adding steam client icon cache
  • Loading branch information
thegrannychaseroperation authored May 18, 2024
2 parents f31ae47 + be13ecc commit a89e676
Show file tree
Hide file tree
Showing 28 changed files with 195 additions and 169 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ jobs:
if: matrix.os == 'ubuntu-latest'
run: yarn build:linux
env:
MAIN_VITE_STEAMGRIDDB_API_KEY: ${{ secrets.STEAMGRIDDB_API_KEY }}
MAIN_VITE_ONLINEFIX_USERNAME: ${{ secrets.ONLINEFIX_USERNAME }}
MAIN_VITE_ONLINEFIX_PASSWORD: ${{ secrets.ONLINEFIX_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -46,7 +45,6 @@ jobs:
if: matrix.os == 'windows-latest'
run: yarn build:win
env:
MAIN_VITE_STEAMGRIDDB_API_KEY: ${{ secrets.STEAMGRIDDB_API_KEY }}
MAIN_VITE_ONLINEFIX_USERNAME: ${{ secrets.ONLINEFIX_USERNAME }}
MAIN_VITE_ONLINEFIX_PASSWORD: ${{ secrets.ONLINEFIX_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -56,7 +54,7 @@ jobs:
with:
name: Build-${{ matrix.os }}
path: |
dist/*.exe
dist/win-unpacked/**
dist/*.zip
dist/*.dmg
dist/*.deb
Expand Down
16 changes: 0 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ jobs:
if: matrix.os == 'ubuntu-latest'
run: yarn build:linux
env:
MAIN_VITE_STEAMGRIDDB_API_KEY: ${{ secrets.STEAMGRIDDB_API_KEY }}
MAIN_VITE_ONLINEFIX_USERNAME: ${{ secrets.ONLINEFIX_USERNAME }}
MAIN_VITE_ONLINEFIX_PASSWORD: ${{ secrets.ONLINEFIX_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -48,25 +47,10 @@ jobs:
if: matrix.os == 'windows-latest'
run: yarn build:win
env:
MAIN_VITE_STEAMGRIDDB_API_KEY: ${{ secrets.STEAMGRIDDB_API_KEY }}
MAIN_VITE_ONLINEFIX_USERNAME: ${{ secrets.ONLINEFIX_USERNAME }}
MAIN_VITE_ONLINEFIX_PASSWORD: ${{ secrets.ONLINEFIX_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create artifact
uses: actions/upload-artifact@v4
with:
name: Build-${{ matrix.os }}
path: |
dist/*.exe
dist/*.zip
dist/*.dmg
dist/*.deb
dist/*.rpm
dist/*.tar.gz
dist/*.yml
dist/*.blockmap
- name: Release
uses: softprops/action-gh-release@v1
with:
Expand Down
3 changes: 1 addition & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
yarn lint
yarn typecheck
yarn format
3 changes: 2 additions & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
yarn format
yarn lint
yarn typecheck
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
out
dist
seeds
pnpm-lock.yaml
LICENSE.md
tsconfig.json
Expand Down
1 change: 1 addition & 0 deletions electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extraResources:
- hydra-download-manager
- hydra.db
- fastlist.exe
- seeds
files:
- "!**/.vscode/*"
- "!src/*"
Expand Down
Binary file modified hydra.db
Binary file not shown.
1 change: 1 addition & 0 deletions seeds/steam-games.json

Large diffs are not rendered by default.

20 changes: 3 additions & 17 deletions src/main/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,6 @@ export const repackers = [
"onlinefix",
] as const;

export const months = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
];

export const defaultDownloadsPath = app.getPath("downloads");

export const databasePath = path.join(
Expand All @@ -41,5 +26,6 @@ export const databasePath = path.join(
"hydra.db"
);

export const INSTALLATION_ID_LENGTH = 6;
export const ACTIVATION_KEY_MULTIPLIER = 7;
export const seedsPath = app.isPackaged
? path.join(process.resourcesPath, "seeds")
: path.join(__dirname, "..", "..", "seeds");
20 changes: 8 additions & 12 deletions src/main/data-source.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import { DataSource } from "typeorm";
import {
Game,
GameShopCache,
Repack,
UserPreferences,
SteamGame,
} from "@main/entity";
import type { SqliteConnectionOptions } from "typeorm/driver/sqlite/SqliteConnectionOptions";
import { Game, GameShopCache, Repack, UserPreferences } from "@main/entity";
import type { BetterSqlite3ConnectionOptions } from "typeorm/driver/better-sqlite3/BetterSqlite3ConnectionOptions";

import { databasePath } from "./constants";
import migrations from "./migrations";

export const createDataSource = (options: Partial<SqliteConnectionOptions>) =>
export const createDataSource = (
options: Partial<BetterSqlite3ConnectionOptions>
) =>
new DataSource({
type: "better-sqlite3",
database: databasePath,
entities: [Game, Repack, UserPreferences, GameShopCache, SteamGame],
entities: [Game, Repack, UserPreferences, GameShopCache],
synchronize: true,
database: databasePath,
...options,
});

export const dataSource = createDataSource({
migrations: migrations,
migrations,
});
4 changes: 2 additions & 2 deletions src/main/entity/game.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export class Game {
@Column("text")
title: string;

@Column("text")
iconUrl: string;
@Column("text", { nullable: true })
iconUrl: string | null;

@Column("text", { nullable: true })
folderName: string | null;
Expand Down
1 change: 0 additions & 1 deletion src/main/entity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export * from "./game.entity";
export * from "./repack.entity";
export * from "./user-preferences.entity";
export * from "./game-shop-cache.entity";
export * from "./steam-game.entity";
10 changes: 0 additions & 10 deletions src/main/entity/steam-game.entity.ts

This file was deleted.

12 changes: 7 additions & 5 deletions src/main/events/catalogue/get-game-shop-details.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { gameShopCacheRepository, steamGameRepository } from "@main/repository";
import { gameShopCacheRepository } from "@main/repository";
import { getSteamAppDetails } from "@main/services";

import type { ShopDetails, GameShop, SteamAppDetails } from "@types";

import { registerEvent } from "../register-event";
import { stateManager } from "@main/state-manager";

const getLocalizedSteamAppDetails = (
objectID: string,
Expand All @@ -13,10 +14,11 @@ const getLocalizedSteamAppDetails = (
return getSteamAppDetails(objectID, language);
}

return Promise.all([
steamGameRepository.findOne({ where: { id: Number(objectID) } }),
getSteamAppDetails(objectID, language),
]).then(([steamGame, localizedAppDetails]) => {
return getSteamAppDetails(objectID, language).then((localizedAppDetails) => {
const steamGame = stateManager
.getValue("steamGames")
.find((game) => game.id === Number(objectID));

if (steamGame && localizedAppDetails) {
return {
...localizedAppDetails,
Expand Down
36 changes: 24 additions & 12 deletions src/main/events/library/add-game-to-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { gameRepository } from "@main/repository";
import { registerEvent } from "../register-event";

import type { GameShop } from "@types";
import { getFileBase64 } from "@main/helpers";
import { getSteamGameIconUrl } from "@main/services";
import { getFileBase64, getSteamAppAsset } from "@main/helpers";
import { stateManager } from "@main/state-manager";

const addGameToLibrary = async (
_event: Electron.IpcMainInvokeEvent,
Expand All @@ -27,17 +27,29 @@ const addGameToLibrary = async (
)
.then(async ({ affected }) => {
if (!affected) {
const iconUrl = await getFileBase64(
await getSteamGameIconUrl(objectID)
);
const steamGame = stateManager
.getValue("steamGames")
.find((game) => game.id === Number(objectID));

await gameRepository.insert({
title,
iconUrl,
objectID,
shop: gameShop,
executablePath,
});
const iconUrl = steamGame?.clientIcon
? getSteamAppAsset("icon", objectID, steamGame.clientIcon)
: null;

await gameRepository
.insert({
title,
iconUrl,
objectID,
shop: gameShop,
executablePath,
})
.then(() => {
if (iconUrl) {
getFileBase64(iconUrl).then((base64) =>
gameRepository.update({ objectID }, { iconUrl: base64 })
);
}
});
}
});
};
Expand Down
44 changes: 30 additions & 14 deletions src/main/events/torrenting/start-game-download.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getSteamGameIconUrl } from "@main/services";
import {
gameRepository,
repackRepository,
Expand All @@ -8,10 +7,11 @@ import {
import { registerEvent } from "../register-event";

import type { GameShop } from "@types";
import { getFileBase64 } from "@main/helpers";
import { getFileBase64, getSteamAppAsset } from "@main/helpers";
import { In } from "typeorm";
import { DownloadManager } from "@main/services";
import { Downloader, GameStatus } from "@shared";
import { stateManager } from "@main/state-manager";

const startGameDownload = async (
_event: Electron.IpcMainInvokeEvent,
Expand Down Expand Up @@ -76,18 +76,34 @@ const startGameDownload = async (

return game;
} else {
const iconUrl = await getFileBase64(await getSteamGameIconUrl(objectID));

const createdGame = await gameRepository.save({
title,
iconUrl,
objectID,
downloader,
shop: gameShop,
status: GameStatus.Downloading,
downloadPath,
repack: { id: repackId },
});
const steamGame = stateManager
.getValue("steamGames")
.find((game) => game.id === Number(objectID));

const iconUrl = steamGame?.clientIcon
? getSteamAppAsset("icon", objectID, steamGame.clientIcon)
: null;

const createdGame = await gameRepository
.save({
title,
iconUrl,
objectID,
downloader,
shop: gameShop,
status: GameStatus.Downloading,
downloadPath,
repack: { id: repackId },
})
.then((result) => {
if (iconUrl) {
getFileBase64(iconUrl).then((base64) =>
gameRepository.update({ objectID }, { iconUrl: base64 })
);
}

return result;
});

DownloadManager.downloadGame(createdGame.id);

Expand Down
15 changes: 1 addition & 14 deletions src/main/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
gogFormatter,
onlinefixFormatter,
} from "./formatters";
import { months, repackers } from "../constants";
import { repackers } from "../constants";

export const pipe =
<T>(...fns: ((arg: T) => any)[]) =>
Expand Down Expand Up @@ -44,19 +44,6 @@ export const repackerFormatter: Record<
onlinefix: onlinefixFormatter,
};

export const formatUploadDate = (str: string) => {
const date = new Date();

const [month, day, year] = str.split(" ");

date.setMonth(months.indexOf(month.replace(".", "")));
date.setDate(Number(day.substring(0, 2)));
date.setFullYear(Number("20" + year.replace("'", "")));
date.setHours(0, 0, 0, 0);

return date;
};

export const getSteamAppAsset = (
category: "library" | "hero" | "logo" | "icon",
objectID: string,
Expand Down
Loading

0 comments on commit a89e676

Please sign in to comment.