Skip to content

Commit

Permalink
Make platform Gamepass api typed
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownskl committed Sep 25, 2024
1 parent f2e0a7d commit caa0876
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 120 deletions.
117 changes: 56 additions & 61 deletions app/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,79 +4,74 @@ import serve from 'electron-serve'
import { createWindow } from './helpers'
import Platform from '@greenlight/platform'
import Logger from '@greenlight/logger'
// const Platform = require('@greenlight/platform')
const Logger2 = require('@greenlight/logger')
import pkg from '../package.json'

console.log('Fucking logger kanker shit:', Logger, Logger2.default)
export default class Application {

// export default class Application {
public isProduction: boolean = process.env.NODE_ENV === 'production'

// public isProduction: boolean = process.env.NODE_ENV === 'production'
private _platform?:Platform
public logger:Logger = new Logger('GreenlightApp')

// private _platform:Platform
// public logger:Logger = new Logger('GreenlightApp')
constructor() {
this.logger.log('constructor() Application booting... Greenlight App version', pkg.version)

// constructor() {
// this.logger.log('constructor() Application booting... Greenlight App version', pkg.version)
if(this.isProduction === true){
serve({ directory: 'app' })
} else {
app.setPath('userData', `${app.getPath('userData')} (development)`)
}
}

// if(this.isProduction === true){
// serve({ directory: 'app' })
// } else {
// app.setPath('userData', `${app.getPath('userData')} (development)`)
// }
// }
async isReady() {
await app.whenReady()
}

// async isReady() {
// await app.whenReady()
// }
loadPlatform(){
return new Promise((resolve, reject) => {
this._platform = new Platform()

// loadPlatform(){
// return new Promise((resolve, reject) => {
// // const Platform = require('@greenlight/platform');
// this._platform = new Platform()
this._platform.loadWorker('./app/worker.js').then((authenticated:boolean) => {
this.logger.log('loadPlatform() Platform loaded and authenticated')
resolve(authenticated)
}).catch((error:any) => {
this.logger.error('loadPlatform() Platform failed to load. Critical error: '+error)
reject(error)
})
})
}

// this._platform.loadWorker('./app/worker.js').then((authenticated:boolean) => {
// this.logger.log('loadPlatform() Platform loaded and authenticated')
// resolve(authenticated)
// }).catch((error:any) => {
// this.logger.error('loadPlatform() Platform failed to load. Critical error: '+error)
// reject(error)
// })
// })
// }

// async spawnMainWindow() {
// const mainWindow = createWindow('main', {
// width: 1280,
// height: (this.isProduction) ? 800 : 1200,
// title: 'Greenlight',
// backgroundColor: 'rgb(26, 27, 30)',
// webPreferences: {
// preload: path.join(__dirname, 'preload.js'),
// },
// })
async spawnMainWindow() {
const mainWindow = createWindow('main', {
width: 1280,
height: (this.isProduction) ? 800 : 1200,
title: 'Greenlight',
backgroundColor: 'rgb(26, 27, 30)',
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
},
})

// if (this.isProduction) {
// await mainWindow.loadURL('app://./boot')
// } else {
// const port = process.argv[2]
// await mainWindow.loadURL(`http://localhost:${port}/boot`)
// mainWindow.webContents.openDevTools({
// mode: 'bottom'
// })
// }
// this.logger.log('spawnMainWindow() Main application windows drawn')
if (this.isProduction) {
await mainWindow.loadURL('app://./boot')
} else {
const port = process.argv[2]
await mainWindow.loadURL(`http://localhost:${port}/boot`)
mainWindow.webContents.openDevTools({
mode: 'bottom'
})
}
this.logger.log('spawnMainWindow() Main application windows drawn')


// return mainWindow
// }
// }
return mainWindow
}
}

// const main = new Application()
// ;(async () => {
// await main.isReady()
const main = new Application()
;(async () => {
await main.isReady()

// await main.spawnMainWindow()
// await main.loadPlatform()
// })()
await main.spawnMainWindow()
await main.loadPlatform()
})()
22 changes: 11 additions & 11 deletions packages/platform/src/controllers/gamepass.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import GreenlightPlatform from '..'
import { GetTitlesResponse } from '@greenlight/xcloudapi/src/response'
import Product from '@greenlight/storeapi/src/product'

export interface SiglResponse {
properties: {
Expand All @@ -19,26 +21,26 @@ export default class Gamepass {
this._platform = platform
}

async getTitles() {
async getTitles():Promise<GetTitlesResponse> {
return await this._platform.sendMessage({
controller: 'xCloudApi',
action: 'getTitles'
})
}

async getList(type:string) {
const titles = await (this._platform.sendMessage({
async getList(type:string):Promise<Product[]> {
const sigl = await (this._platform.sendMessage({
controller: 'xCloudApi',
action: 'getList',
params: [
type
]
}) as Promise<SiglResponse>)

return await this.getProductIds(titles.productIds)
return await this.getProductIds(sigl.productIds)
}

async getSigl(siglId:string) {
async getSigl(siglId:string):Promise<SiglResponse> {
return await this._platform.sendMessage({
controller: 'xCloudApi',
action: 'getSigl',
Expand All @@ -48,7 +50,7 @@ export default class Gamepass {
})
}

async getProductIds(productIds:string[]) {
async getProductIds(productIds:string[]):Promise<Product[]> {
const products = await this._platform.sendMessage({
controller: 'storeApi',
action: 'getProductIds',
Expand All @@ -66,21 +68,19 @@ export default class Gamepass {
]
})

const retProducts = await this._platform.sendMessage({
return await this._platform.sendMessage({
controller: 'storeApi',
action: 'getProductIds',
params: [
productIds
]
})

return await this.parseItems(retProducts)
} else {
return await this.parseItems(products)
return products
}
}

async parseItems(items:any[]){
async parseItems(items:any[]):Promise<Product[]> {
const parsedItems = []
for(const item in items){
const parsedItem = await this._platform.sendMessage({
Expand Down
4 changes: 2 additions & 2 deletions packages/platform/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class GreenlightPlatform {
this.logger.log('constructor() Creating new GreenlightPlatform instance')
}

loadWorker(file = __filename) {
loadWorker(file = __filename):Promise<boolean> {
return new Promise((resolve, reject) => {
if(! worker.isMainThread)
throw new Error('Cannot load worker in worker thread, need to be loaded in the main thread.')
Expand All @@ -39,7 +39,7 @@ export default class GreenlightPlatform {
})
})
this._worker.on('error', (error:any) => {
console.log('Worker error:', error)
this.logger.error('Worker error:', error)
reject(error)
})
this._worker.on('exit', (exit:any) => {
Expand Down
88 changes: 43 additions & 45 deletions packages/storeapi/src/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class Product {
public name:string;

public description:string;
public description_short:string;
public descriptionShort:string;

public developer:string;
public publisher:string;
Expand All @@ -80,83 +80,81 @@ export default class Product {
this.id = item.StoreId
this.name = item.ProductTitle

const storeData = item

this.description = storeData.ProductDescription
this.description_short = storeData.ProductDescriptionShort
this.developer = storeData.DeveloperName
this.publisher = storeData.PublisherName
this.description = item.ProductDescription
this.descriptionShort = item.ProductDescriptionShort
this.developer = item.DeveloperName
this.publisher = item.PublisherName

this.images = {
tile: 'https:'+storeData.Image_Tile.URL,
poster: 'https:'+storeData.Image_Poster.URL,
hero: (storeData.Image_Hero !== null) ? 'https:'+storeData.Image_Hero.URL : undefined,
titledHero: (storeData.Image_TitledHero !== null) ? 'https:'+storeData.Image_TitledHero.URL : undefined
tile: 'https:'+item.Image_Tile?.URL,
poster: 'https:'+item.Image_Poster?.URL,
hero: (item.Image_Hero !== null) ? 'https:'+item.Image_Hero?.URL : undefined,
titledHero: (item.Image_TitledHero !== null) ? 'https:'+item.Image_TitledHero?.URL : undefined
}

for(const screenshot in storeData.Screenshots){
for(const screenshot in item.Screenshots){
this.screenshots.push({
url: 'https:'+storeData.Screenshots[screenshot].URL,
caption: storeData.Screenshots[screenshot].Caption
url: 'https:'+item.Screenshots[screenshot].URL,
caption: item.Screenshots[screenshot].Caption
})
}

for(const trailer in storeData.Trailers){
for(const trailer in item.Trailers){
this.trailers.push({
image: storeData.Trailers[trailer].PreviewImageURL,
url: storeData.Trailers[trailer].URL,
caption: storeData.Trailers[trailer].Caption
image: item.Trailers[trailer].PreviewImageURL,
url: item.Trailers[trailer].URL,
caption: item.Trailers[trailer].Caption
})
}

for(const category in storeData.Categories){
for(const category in item.Categories){
this.categories.push({
name: storeData.Categories[category],
localizedName: storeData.LocalizedCategories[category]
name: item.Categories[category],
localizedName: item.LocalizedCategories[category]
})
}

for(const capability in storeData.Attributes){
for(const capability in item.Attributes){
this.capabilities.push({
name: storeData.Attributes[capability].Name,
localizedName: storeData.Attributes[capability].LocalizedName
name: item.Attributes[capability].Name,
localizedName: item.Attributes[capability].LocalizedName
})
}

for(const language in storeData.LanguageSupport){
for(const language in item.LanguageSupport){
this.languageSupport[language] = {
audio: storeData.LanguageSupport[language].GamePlayAudioLanguageSupport == 1 ? true : false,
interface: storeData.LanguageSupport[language].InterfaceLanguageSupport == 1 ? true : false,
subtitles: storeData.LanguageSupport[language].SubtitlesLanguageSupport == 1 ? true : false
audio: item.LanguageSupport[language].GamePlayAudioLanguageSupport == 1 ? true : false,
interface: item.LanguageSupport[language].InterfaceLanguageSupport == 1 ? true : false,
subtitles: item.LanguageSupport[language].SubtitlesLanguageSupport == 1 ? true : false
}
}

this.defaultPrice = (storeData.AnonymousPrice.MSRP !== null) ? {
currency: storeData.AnonymousPrice.MSRP.CurrencyCode,
value: storeData.AnonymousPrice.MSRP.Value,
formatted: storeData.AnonymousPrice.MSRP.FormattedValue
this.defaultPrice = (item.AnonymousPrice.MSRP !== null) ? {
currency: item.AnonymousPrice.MSRP?.CurrencyCode,
value: item.AnonymousPrice.MSRP?.Value,
formatted: item.AnonymousPrice.MSRP?.FormattedValue
} : {
currency: 'USD',
value: 0.00,
formatted: '$0.00'
}

this.price = (storeData.AnonymousPrice.SalePrice !== null) ? {
currency: storeData.AnonymousPrice.SalePrice.CurrencyCode,
value: storeData.AnonymousPrice.SalePrice.Value,
formatted: storeData.AnonymousPrice.SalePrice.FormattedValue
this.price = (item.AnonymousPrice.SalePrice !== null) ? {
currency: item.AnonymousPrice.SalePrice.CurrencyCode,
value: item.AnonymousPrice.SalePrice.Value,
formatted: item.AnonymousPrice.SalePrice.FormattedValue
} : this.defaultPrice

this.rating = {
name: storeData.ContentRating.LongName,
description: storeData.ContentRating.Description,
age: storeData.ContentRating.Age,
logo: storeData.ContentRating.LogoUrl,
system: storeData.ContentRating.RatingSystem,
systemUrl: storeData.ContentRating.RatingSystemUrl,
localizedDescriptors: storeData.ContentRating.LocalizedDescriptors,
localizedDisclaimers: storeData.ContentRating.LocalizedDisclaimers,
localizedInteractiveElements: storeData.ContentRating.LocalizedInteractiveElements
name: item.ContentRating.LongName,
description: item.ContentRating.Description,
age: item.ContentRating.Age,
logo: item.ContentRating.LogoUrl,
system: item.ContentRating.RatingSystem,
systemUrl: item.ContentRating.RatingSystemUrl,
localizedDescriptors: item.ContentRating.LocalizedDescriptors,
localizedDisclaimers: item.ContentRating.LocalizedDisclaimers,
localizedInteractiveElements: item.ContentRating.LocalizedInteractiveElements
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/xcloudapi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface xCloudApiConfig {
language?:string
}

interface SiglResponse {
export interface SiglResponse {
properties: {
siglId: string,
title: string,
Expand Down

0 comments on commit caa0876

Please sign in to comment.