Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installs Jailer Config for Native Apps #201

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions services/jail-conf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { fetchWrapper } from './fetch-wrapper';
import fs from 'fs';
import { asyncPipeline } from './adapter';
import path from 'path';

function fileUrl(sdkVersion: string, fileType: string) {
return `https://developer.lge.com/common/file/DownloadFile.dev?sdkVersion=${sdkVersion}&fileType=${fileType}`;
}

async function downloadFileTo(url: string, targetPath: string) {
const res = await fetchWrapper(url);
if (!res.ok) {
throw new Error(`Failed to download jail.conf.sig: ${res.statusText}`);
}
const targetFile = fs.createWriteStream(targetPath);
await asyncPipeline(res.body, targetFile);
}

export async function downloadJailConf(appDir: string, sdkVersion: string) {
await downloadFileTo(fileUrl(sdkVersion, 'conf'), path.join(appDir, 'jail_app.conf'));
await downloadFileTo(fileUrl(sdkVersion, 'sig'), path.join(appDir, 'jail_app.conf.sig'));
}
31 changes: 25 additions & 6 deletions services/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import { asyncStat, asyncExecFile, asyncPipeline, asyncUnlink, asyncWriteFile, asyncReadFile, asyncChmod, asyncMkdir } from './adapter';
import { fetchWrapper } from './fetch-wrapper';
import { downloadJailConf } from './jail-conf';

import rootAppInfo from '../appinfo.json';
import serviceInfo from './services.json';
Expand Down Expand Up @@ -406,8 +407,14 @@
return serviceRemote as Service;
}

async function getAppInfo(appId: string): Promise<Record<string, any>> {
const appList = await asyncCall<{ apps: { id: string }[] }>(
interface AppInfo {
id: string;
title: string;
type: string;
folderPath: string;
}
async function getAppInfo(appId: string): Promise<AppInfo> {
const appList = await asyncCall<{ apps: AppInfo[] }>(

Check failure on line 417 in services/service.ts

View workflow job for this annotation

GitHub Actions / build / build

Replace `⏎······getInstallerService(),⏎······'luna://com.webos.applicationManager/dev/listApps',⏎······{},⏎····` with `getInstallerService(),·'luna://com.webos.applicationManager/dev/listApps',·{}`
getInstallerService(),
'luna://com.webos.applicationManager/dev/listApps',
{},
Expand All @@ -417,14 +424,14 @@
return appInfo;
}

/**
* Installs the requested ipk from a URL.
*/
interface InstallPayload {
ipkUrl: string;
ipkHash: string;
id?: string;
}
/**
* Installs the requested ipk from a URL.
*/
service.register(
'install',
tryRespond(async (message: Message) => {
Expand Down Expand Up @@ -491,7 +498,19 @@

try {
const appInfo = await getAppInfo(installedPackageId);
await createToast(`Application installed: ${appInfo['title']}`, service);
if (appInfo.type === 'native') {
await createToast(`Updating jailer config for ${appInfo.title}…`, service);
const sdkVersion = await asyncCall<{
sdkVersion: string;
}>(service, 'luna://com.webos.service.tv.systemproperty/getSystemInfo', {
keys: ['sdkVersion'],
}).then((resp) => resp.sdkVersion).catch(() => null);

Check failure on line 507 in services/service.ts

View workflow job for this annotation

GitHub Actions / build / build

Replace `.then((resp)·=>·resp.sdkVersion)` with `⏎············.then((resp)·=>·resp.sdkVersion)⏎············`
if (sdkVersion) {
await downloadJailConf(appInfo.folderPath, sdkVersion)

Check failure on line 509 in services/service.ts

View workflow job for this annotation

GitHub Actions / build / build

Delete `⏎··············`
.catch((err) => console.warn('jailer conf download failed:', err));

Check failure on line 510 in services/service.ts

View workflow job for this annotation

GitHub Actions / build / build

Returning a void expression from an arrow function shorthand is forbidden. Please add braces to the arrow function
}
}
await createToast(`Application installed: ${appInfo.title}`, service);
} catch (err: unknown) {
console.warn('appinfo fetch failed:', err);
await createToast(`Application installed: ${installedPackageId}`, service);
Expand Down
Loading