Skip to content

Commit 6718758

Browse files
feat: Implemented logins and bundle importers (only Humble Bundles for now)
1 parent 6d66a86 commit 6718758

17 files changed

Lines changed: 525 additions & 38 deletions

File tree

package-lock.json

Lines changed: 10 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@
123123
"electron-log": "^5.4.3",
124124
"electron-store": "^8.2.0",
125125
"electron-updater": "^6.7.3",
126-
"file-icons-js": "github:websemantics/file-icons-js",
127126
"idb": "^8.0.3",
128127
"lodash-es": "^4.17.21",
129128
"lokijs": "^1.5.12",
@@ -140,6 +139,7 @@
140139
"react": "^18.3.1",
141140
"react-audio-player": "^0.17.0",
142141
"react-dom": "^18.2.0",
142+
"react-icons": "^5.5.0",
143143
"react-markdown": "^10.1.0",
144144
"react-router-dom": "^7.12.0",
145145
"react-split": "^2.0.14",
@@ -303,14 +303,18 @@
303303
"target": [
304304
"nsis"
305305
],
306-
"publish": ["github"]
306+
"publish": [
307+
"github"
308+
]
307309
},
308310
"linux": {
309311
"target": [
310312
"AppImage"
311313
],
312314
"category": "Development",
313-
"publish": ["github"]
315+
"publish": [
316+
"github"
317+
]
314318
},
315319
"directories": {
316320
"app": "release/app",

src/main/api/accounts.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import ElectronStore from 'electron-store';
2+
import { MainIpcGetter, StoreSchema } from 'shared/constants';
3+
import InstallHumbleImporter from './bundles/humble-importer';
4+
5+
export default function InitializeAccounts(
6+
store: ElectronStore<StoreSchema>,
7+
database: Loki,
8+
api: MainIpcGetter,
9+
) {
10+
const importers = {
11+
humble: InstallHumbleImporter(store, database),
12+
};
13+
14+
api.checkLogin = async (provider) => importers[provider].isLoggedIn();
15+
api.logout = async (provider) => {};
16+
api.login = async (provider) => importers[provider].login();
17+
18+
return importers;
19+
}

src/main/api/bundles-api.ts

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
1+
/* eslint-disable no-await-in-loop */
12
import { spawn } from 'child_process';
23
import { createWriteStream } from 'fs';
34
import { writeFile, readFile, mkdir, rename, stat, rm } from 'fs/promises';
45
import path, { normalize } from 'path';
5-
import { dialog, BrowserWindow, shell, Notification } from 'electron';
6-
import log from 'electron-log/main';
6+
import { setTimeout } from 'timers/promises';
7+
import { uuid } from '@tanstack/react-form';
8+
import { load } from 'cheerio';
9+
import { dialog, BrowserWindow, shell, Notification, session, net } from 'electron';
10+
import log from 'electron-log';
711
import Store from 'electron-store';
812
import JSZip from 'jszip';
913
import Loki from 'lokijs';
1014
import StreamZip from 'node-stream-zip';
11-
import { BundleMetaFile, StoreSchema, MainIpcGetter, previewTypes } from '../../shared/constants';
15+
import {
16+
BundleMetaFile,
17+
StoreSchema,
18+
MainIpcGetter,
19+
previewTypes,
20+
HUMBLE_PARTITION,
21+
ImportType,
22+
LoginProvider,
23+
} from '../../shared/constants';
1224
import { addTask } from '../managers/task-manager';
13-
import { FilePath, getProjectDir, getRandom, ignoredFilesMatch } from '../util';
25+
import { FilePath, foreachAsync, getProjectDir, getRandom, ignoredFilesMatch } from '../util';
1426
import {
1527
findBundlePath,
1628
forAllAssetsInProject,
@@ -219,21 +231,24 @@ export async function getVirtualBundles(
219231
bundle: b,
220232
isVirtual: true,
221233
date: new Date(b.date),
234+
sourceType: b.sourceType,
222235
}) satisfies BundleInfo as BundleInfo,
223236
);
224237
}
225238

226239
export async function getBundles(
227240
store: Store<StoreSchema>,
228-
virtualBundles: Collection<VirtualBundle>,
241+
virtualBundles?: Collection<VirtualBundle>,
229242
): Promise<BundleInfo[]> {
230243
const bundles: BundleInfo[] = [];
231244
const projectDir = getProjectDir(store);
232245
if (projectDir) {
233246
await findChildrenBundles(new FilePath(projectDir, ''), bundles);
234247
}
235248

236-
bundles.push(...(await getVirtualBundles(virtualBundles)));
249+
if (virtualBundles) {
250+
bundles.push(...(await getVirtualBundles(virtualBundles)));
251+
}
237252

238253
return bundles.sort((a, b) => b.date?.getTime() - a.date?.getTime());
239254
}
@@ -369,9 +384,18 @@ async function exportBundle(
369384
}
370385
}
371386

387+
async function getHumbleCookieHeader(): Promise<string> {
388+
const cookies = await session.defaultSession.cookies.get({
389+
domain: '.humblebundle.com',
390+
});
391+
392+
return cookies.map((c) => `${c.name}=${c.value}`).join('; ');
393+
}
394+
372395
/* ----------------------------- Initialize API ----------------------------- */
373396

374397
export default function InitializeBundlesApi(
398+
importers: Record<LoginProvider, BundleImporter>,
375399
api: MainIpcGetter,
376400
store: Store<StoreSchema>,
377401
db: Loki,
@@ -447,6 +471,7 @@ export default function InitializeBundlesApi(
447471
bundle: virtualBundle as Bundle,
448472
previewUrl: virtualBundle.previewUrl,
449473
name: virtualBundle.name,
474+
sourceType: virtualBundle.sourceType,
450475
} as BundleInfo;
451476
}
452477
return tryGetBundleEntryFromFolderPath(FilePath.fromStore(store, id));
@@ -502,6 +527,15 @@ export default function InitializeBundlesApi(
502527
}
503528

504529
api.updateBundle = updateBundle;
530+
api.importBundles = async (type) => {
531+
const importer = importers[type];
532+
if (importer) {
533+
return addTask('Importing Bundles', async (abort, progress) =>
534+
importer.import(abort, progress),
535+
);
536+
}
537+
throw new Error(`No Importer of type ${type}`);
538+
};
505539
api.getBundles = () => getBundles(store, virtualBundles);
506540
api.getHomeBundles = getHomeBundles;
507541
api.createVirtualBundle = createVirtualBundle;

0 commit comments

Comments
 (0)