mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
53 lines
1.1 KiB
TypeScript
53 lines
1.1 KiB
TypeScript
import {
|
|
DownloadManager,
|
|
Ludusavi,
|
|
PythonInstance,
|
|
startMainLoop,
|
|
} from "./services";
|
|
import {
|
|
downloadQueueRepository,
|
|
userPreferencesRepository,
|
|
} from "./repository";
|
|
import { UserPreferences } from "./entity";
|
|
import { RealDebridClient } from "./services/real-debrid";
|
|
import { HydraApi } from "./services/hydra-api";
|
|
import { uploadGamesBatch } from "./services/library-sync";
|
|
|
|
const loadState = async (userPreferences: UserPreferences | null) => {
|
|
import("./events");
|
|
|
|
if (userPreferences?.realDebridApiToken) {
|
|
RealDebridClient.authorize(userPreferences?.realDebridApiToken);
|
|
}
|
|
|
|
Ludusavi.addManifestToLudusaviConfig();
|
|
|
|
HydraApi.setupApi().then(() => {
|
|
uploadGamesBatch();
|
|
});
|
|
|
|
const [nextQueueItem] = await downloadQueueRepository.find({
|
|
order: {
|
|
id: "DESC",
|
|
},
|
|
relations: {
|
|
game: true,
|
|
},
|
|
});
|
|
|
|
if (nextQueueItem?.game.status === "active") {
|
|
DownloadManager.startDownload(nextQueueItem.game);
|
|
} else {
|
|
PythonInstance.spawn();
|
|
}
|
|
|
|
startMainLoop();
|
|
};
|
|
|
|
userPreferencesRepository
|
|
.findOne({
|
|
where: { id: 1 },
|
|
})
|
|
.then((userPreferences) => {
|
|
loadState(userPreferences);
|
|
});
|