Skip to content

Commit

Permalink
fix: fix invalid json, module not found and more
Browse files Browse the repository at this point in the history
  • Loading branch information
reisxd committed Aug 14, 2024
1 parent 66c330b commit 103ae59
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 88 deletions.
3 changes: 1 addition & 2 deletions tizenbrew-app/TizenBrew/config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns:tizen="http://tizen.org/ns/widgets" xmlns="http://www.w3.org/ns/widgets" id="https://tizentube.vercel.app" version="1.3.2" viewmodes="maximized">
<widget xmlns:tizen="http://tizen.org/ns/widgets" xmlns="http://www.w3.org/ns/widgets" id="https://tizentube.vercel.app" version="1.3.3" viewmodes="maximized">
<access origin="*" subdomains="true"></access>
<tizen:app-control>
<tizen:src name="index.html" reload="disable"/>
Expand All @@ -19,7 +19,6 @@
<tizen:metadata key="http://samsung.com/tv/metadata/prelaunch.support" value="true"/>
<tizen:metadata key="http://samsung.com/tv/metadata/microphone.support" value="1"/>
<tizen:metadata key="http://samsung.com/tv/metadata/microphone.area" value="open"/>
<tizen:metadata key="http://samsung.com/tv/metadata/use.preview" value="endpoint_URL=https://tizentube.vercel.app/smartHubPreview.json"/>
<name>TizenBrewStandalone</name>
<tizen:privilege name="http://tizen.org/privilege/internet"/>
<tizen:privilege name="http://developer.samsung.com/privilege/network.public"/>
Expand Down
5 changes: 1 addition & 4 deletions tizenbrew-app/TizenBrew/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,7 @@
break;
}

if (packageType === 'service' || packageType === 'service-mods') {
window.send({ type: "startService", package: { name: packageName, type: moduleType } });
}
window.send({ type: "launch", package: { name: packageName, type: moduleType }, isTizen3, tvIp: webapis.network.getIp() });
window.send({ type: "launch", package: `${moduleType}/${packageName}`, tvIp: webapis.network.getIp() });
var keys = selectedItem.getAttribute("data-keys");
if (appPath.startsWith("http")) {
if (keys.length > 0) {
Expand Down
68 changes: 34 additions & 34 deletions tizenbrew-app/TizenBrew/js/wsClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let client;
const isTizen3 = navigator.userAgent.includes('Tizen 3.0');
let canLaunchModules = false;
let canAutoLaunch = true;
let loadedModules = false;

function connect() {
const ip = localStorage.getItem('ip');
Expand Down Expand Up @@ -49,7 +50,7 @@ function onMessage(msg) {
hideError();
localStorage.setItem('failedStartupAttempts', '0');
canLaunchModules = message.inDebug.webDebug;
send({ type: 'loadModules', modules: JSON.parse(localStorage.getItem('modules')) });
send({ type: 'loadModules', modules: JSON.parse(localStorage.getItem('modules')).map(item => `${item.type}/${item.name}`) });
if (localStorage.getItem('autoLaunchService')) {
send({ type: 'startService', package: JSON.parse(localStorage.getItem('autoLaunchService')) });
}
Expand All @@ -76,6 +77,10 @@ function onMessage(msg) {
`;
firstOne = false;
}
loadedModules = true;
if (canLaunchModules && localStorage.getItem('autoLaunch')) {
autoLaunchModule();
}
window.selectedItem = document.querySelector(".selected");
window.currentRow = selectedItem.parentElement.parentElement;
} else {
Expand Down Expand Up @@ -116,12 +121,8 @@ function onMessage(msg) {
});
}

if (message.appControlData.module.serviceFile) {
send({ type: 'startService', package: { name: moduleName, type: moduleType } });
}

setTimeout(() => {
send({ type: 'launch', package: { name: moduleName, type: moduleType }, isTizen3, tvIp: webapis.network.getIp() });
send({ type: 'launch', package: `${moduleType}/${moduleName}`, tvIp: webapis.network.getIp() });
if (!tizenAppId) {
location.href = `${appPath}${args ? `?${args}` : ''}`;
}
Expand All @@ -130,34 +131,8 @@ function onMessage(msg) {
}

if (canAutoLaunch && localStorage.getItem('autoLaunch')) {
const autoLaunch = JSON.parse(localStorage.getItem('autoLaunch'));
const app = document.querySelector(`[data-packagename="${autoLaunch.name}"]`);
if (!app) {
showError(`Error: Could not find the module ${autoLaunch.name}.`);
return;
} else {
const appPath = app.getAttribute('data-appPath');
let keys = app.getAttribute("data-keys");
if (keys.length > 0) {
keys = selectedItem.getAttribute("data-keys").split(',');
for (var i = 0; i < keys.length; i++) {
tizen.tvinputdevice.registerKey(keys[i]);
}
}

var packageType = selectedItem.getAttribute("data-packageType");

if (packageType === 'service' || packageType === 'service-mods') {
send({ type: "startService", package: autoLaunch });
}

setTimeout(() => {
send({ type: 'launch', package: autoLaunch, isTizen3, tvIp: webapis.network.getIp() });
if (app.getAttribute('data-moddedTizenApp') === 'false') {
location.href = appPath;
}
}, 250);
}
if (!loadedModules) return;
autoLaunchModule();
}
break;
}
Expand Down Expand Up @@ -204,4 +179,29 @@ function onOpen() {
send({ type: 'getDebugStatus' });
}
} else send({ type: 'getDebugStatus' });
}

function autoLaunchModule() {
const autoLaunch = JSON.parse(localStorage.getItem('autoLaunch'));
const app = document.querySelector(`[data-packagename="${autoLaunch.name}"]`);
if (!app) {
showError(`Error: Could not find the module ${autoLaunch.name}.`);
return;
} else {
const appPath = app.getAttribute('data-appPath');
let keys = app.getAttribute("data-keys");
if (keys.length > 0) {
keys = selectedItem.getAttribute("data-keys").split(',');
for (var i = 0; i < keys.length; i++) {
tizen.tvinputdevice.registerKey(keys[i]);
}
}

setTimeout(() => {
send({ type: 'launch', package: `${autoLaunch.type}/${autoLaunch.name}`, tvIp: webapis.network.getIp() });
if (app.getAttribute('data-moddedTizenApp') === 'false') {
location.href = appPath;
}
}, 250);
}
}
35 changes: 22 additions & 13 deletions tizenbrew-app/TizenBrew/service/moduleLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,42 @@ const fetch = require('node-fetch');

function loadModules(moduleList) {
const modulePromises = moduleList.map(module => {
return fetch(`https://cdn.jsdelivr.net/${module.type}/${module.name}/package.json`)
return fetch(`https://cdn.jsdelivr.net/${module}/package.json`)
.then(res => res.json())
.then(moduleJson => {
let moduleData;
const splitData = [
module.substring(0, module.indexOf('/')),
module.substring(module.indexOf('/') + 1)
];
const moduleMetadata = {
name: splitData[1],
type: splitData[0]
}
if (moduleJson.packageType === 'app') {
moduleData = {
name: module.name,
name: moduleMetadata.name,
appName: moduleJson.appName,
description: moduleJson.description,
packageType: moduleJson.packageType,
appPath: `http://127.0.0.1:8081/module/${module.type}/${encodeURIComponent(module.name)}/${moduleJson.appPath}`,
appPath: `http://127.0.0.1:8081/module/${encodeURIComponent(module)}/${moduleJson.appPath}`,
keys: moduleJson.keys || [],
moduleType: module.type
moduleType: moduleMetadata.type
};
} else if (moduleJson.packageType === 'service') {
moduleData = {
name: module.name,
name: moduleMetadata.name,
appName: moduleJson.appName,
description: moduleJson.description,
packageType: moduleJson.packageType,
serviceFile: moduleJson.serviceFile,
appPath: `http://127.0.0.1:8081/module/${module.type}/${encodeURIComponent(module.name)}/${moduleJson.appPath}`,
appPath: `http://127.0.0.1:8081/module/${encodeURIComponent(module)}/${moduleJson.appPath}`,
keys: moduleJson.keys || [],
moduleType: module.type
moduleType: moduleMetadata.type
};
} else {
moduleData = {
name: module.name,
name: moduleMetadata.name,
appName: moduleJson.appName,
description: moduleJson.description,
appPath: moduleJson.websiteURL,
Expand All @@ -40,20 +48,21 @@ function loadModules(moduleList) {
mainFile: moduleJson.main,
keys: moduleJson.keys || [],
tizenAppId: moduleJson.tizenAppId,
moduleType: module.type
moduleType: moduleMetadata.type
};
}
return moduleData;
})
.catch(e => {
console.error(e);
return {
appName: module.name,
name: module.name,
appName: 'Unknown Module',
name: module,
appPath: '',
keys: [],
moduleType: module.type,
moduleType: moduleMetadata.type,
packageType: 'app',
description: `Unknown module ${module.name}. Please check the module name and try again.`
description: `Unknown module ${module}. Please check the module name and try again.`
}
});
});
Expand Down
29 changes: 26 additions & 3 deletions tizenbrew-app/TizenBrew/service/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tizenbrew-app/TizenBrew/service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"adbhost": "^0.0.2",
"express": "^4.19.2",
"node-fetch": "^2.7.0",
"ws": "^4.1.0"
"ws-new": "npm:ws@^7.5.10",
"ws-old": "npm:ws@^4.1.0"
}
}
Loading

0 comments on commit 103ae59

Please sign in to comment.