Skip to content

Commit 57d82cb

Browse files
Merge pull request #22 from WillinuX-Code/webpack
Fixing app crash on WebOS 3.x
2 parents 2509cf7 + 41c8e7b commit 57d82cb

File tree

15 files changed

+12859
-34651
lines changed

15 files changed

+12859
-34651
lines changed

babel.config.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"plugins": ["@babel/plugin-transform-regenerator"],
3+
"presets": [
4+
[
5+
"@babel/preset-env",
6+
{
7+
"targets": {
8+
"chrome": "38"
9+
},
10+
"useBuiltIns": "entry",
11+
"corejs": "3.29.0"
12+
}
13+
],
14+
["@babel/preset-react", { "runtime": "automatic" }]
15+
]
16+
}

package-lock.json

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

package.json

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
{
22
"name": "webos-tvheadend",
3-
"version": "1.0.0",
3+
"version": "0.8.1",
44
"private": true,
55
"homepage": "./",
66
"dependencies": {
77
"@enact/moonstone": "^3.3.1",
88
"@procot/webostv": "^1.2.2",
9+
"core-js": "^3.29.1",
910
"ilib": "^14.6.2",
11+
"core-js": "^3.29.1",
1012
"react": "^16.14.0",
1113
"react-dom": "^16.14.0",
12-
"react-scripts": "^4.0.1"
14+
"regenerator-runtime": "^0.13.11"
1315
},
1416
"scripts": {
15-
"start": "react-scripts start",
16-
"build": "react-scripts build",
17-
"test": "react-scripts test",
18-
"eject": "react-scripts eject",
19-
"webos:emu": "npm run build && ares-package build service && ares-install com.willinux.tvh.app_1.0.0_all.ipk -d emulator && ares-launch com.willinux.tvh.app -d emulator",
17+
"start": "webpack serve --mode development --hot",
18+
"build": "webpack --mode production",
19+
"webos:emu": "npm run build && ares-package build service && ares-install com.willinux.tvh.app_${npm_package_version}_all.ipk -d emulator && ares-launch com.willinux.tvh.app -d emulator",
2020
"webos:emu-rm": "ares-install -d emulator --remove com.willinux.tvh.app",
21-
"webos:tv": "npm run build && ares-package build service && ares-install com.willinux.tvh.app_1.0.0_all.ipk -d tv && ares-launch com.willinux.tvh.app -d tv",
21+
"webos:tv": "npm run build && ares-package build service && ares-install com.willinux.tvh.app${npm_package_version}_all.ipk -d tv && ares-launch com.willinux.tvh.app -d tv",
2222
"webos:tv-rm": "ares-install -d tv --remove com.willinux.tvh.app",
2323
"inspect:emu": "ares-inspect -d emulator com.willinux.tvh.app --open",
2424
"inspect:tv": "ares-inspect -d tv com.willinux.tvh.app --open"
@@ -30,26 +30,39 @@
3030
},
3131
"browserslist": {
3232
"production": [
33-
">0.2%",
34-
"not dead",
35-
"not op_mini all"
33+
"chrome >= 38"
3634
],
3735
"development": [
38-
"last 1 chrome version",
39-
"last 1 firefox version",
40-
"last 1 safari version"
36+
"chrome >= 38"
4137
]
4238
},
4339
"devDependencies": {
40+
"@babel/core": "^7.21.3",
41+
"@babel/plugin-transform-object-assign": "^7.18.6",
42+
"@babel/plugin-transform-regenerator": "^7.20.5",
43+
"@babel/preset-env": "^7.20.2",
44+
"@babel/preset-react": "^7.18.6",
4445
"@types/react": "^17.0.0",
4546
"@types/react-dom": "^17.0.0",
4647
"@typescript-eslint/eslint-plugin": "^4.14.0",
4748
"@typescript-eslint/parser": "^4.14.0",
49+
"babel-loader": "^9.1.2",
50+
"copy-webpack-plugin": "^11.0.0",
51+
"css-loader": "^6.7.3",
4852
"eslint": "^7.18.0",
4953
"eslint-config-prettier": "^7.2.0",
5054
"eslint-config-react-app": "^6.0.0",
5155
"eslint-plugin-prettier": "^3.3.1",
5256
"eslint-plugin-react": "^7.22.0",
53-
"prettier": "^2.2.1"
57+
"html-webpack-plugin": "^5.5.0",
58+
"less": "^4.1.3",
59+
"less-loader": "^11.1.0",
60+
"prettier": "^2.2.1",
61+
"style-loader": "^3.3.2",
62+
"ts-loader": "^9.4.2",
63+
"typescript": "^4.9.5",
64+
"webpack": "^5.76.2",
65+
"webpack-cli": "^5.0.1",
66+
"webpack-dev-server": "^4.12.0"
5467
}
5568
}

public/appinfo.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"id": "com.willinux.tvh.app",
3-
"version": "1.0.0",
4-
"vendor": "My Company",
3+
"version": "0.8.1",
4+
"vendor": "WillinuX-Code",
55
"type": "web",
66
"main": "index.html",
7-
"title": "TVheadend",
7+
"title": "TVheadend Client",
88
"splashBackground": "splash.png",
99
"icon": "icon.png",
1010
"largeIcon": "largeIcon.png",

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1" />
66
<meta name="theme-color" content="#000000" />
7-
<title>WebOS Client 4 TVheadend</title>
7+
<title>WebOS TVheadend Client</title>
88
</head>
99
<body>
1010
<noscript>You need to enable JavaScript to run this app.</noscript>

service/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.willinux.tvh.app",
3-
"version": "1.0.0",
3+
"version": "0.8.1",
44
"description": "TVHeadend webos service",
55
"main": "service.js",
66
"author": "Jens Willhardt",

src/App.tsx

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,34 @@ const App = () => {
8181

8282
// retrieve channel infos etc
8383
setIsChannelsRetrieved(false);
84-
tvhDataService.retrieveM3UChannels().then((channels) => {
85-
epgData.updateChannels(channels);
86-
setIsChannelsRetrieved(true);
87-
88-
// safe persistent token if available
89-
if (channels.length > 0) {
90-
safePersistentAuthToken(channels[0].getStreamUrl());
91-
}
92-
// preload images
93-
preloadImages(channels);
94-
95-
// retrieve epg and update channels
96-
tvhDataService.retrieveTVHEPG(0, (channels) => {
97-
// note: channels are already updated as we are working on references here
84+
tvhDataService
85+
.retrieveM3UChannels()
86+
.then((channels) => {
9887
epgData.updateChannels(channels);
88+
setIsChannelsRetrieved(true);
89+
90+
// safe persistent token if available
91+
if (channels.length > 0) {
92+
safePersistentAuthToken(channels[0].getStreamUrl());
93+
}
94+
// preload images
95+
preloadImages(channels);
96+
97+
// retrieve epg and update channels
98+
tvhDataService.retrieveTVHEPG(0, (channels) => {
99+
// note: channels are already updated as we are working on references here
100+
epgData.updateChannels(channels);
101+
});
102+
103+
// retrieve recordings and update channels
104+
tvhDataService.retrieveUpcomingRecordings((recordings) => {
105+
epgData.updateRecordings(recordings);
106+
});
107+
})
108+
.catch((error) => {
109+
console.log('Failed to retrieve channels: ', error);
99110
});
100111

101-
// retrieve recordings and update channels
102-
tvhDataService.retrieveUpcomingRecordings((recordings) => {
103-
epgData.updateRecordings(recordings);
104-
});
105-
});
106-
107112
setAppViewState(AppViewState.TV);
108113
} else {
109114
setAppViewState(AppViewState.SETTINGS);
@@ -114,9 +119,13 @@ const App = () => {
114119
try {
115120
// retrieve local info
116121
const localInfoResult = await tvhDataService.getLocaleInfo();
117-
const locale = localInfoResult.settings.localeInfo.locales.UI;
118-
setLocale(locale);
122+
let locale = localInfoResult.settings.localeInfo.locales.UI;
119123
console.log('Retrieved locale info:', locale);
124+
if (locale === undefined) {
125+
locale = 'en-US';
126+
console.log('locale fallback to:', locale);
127+
}
128+
setLocale(locale);
120129
} catch (error) {
121130
console.log('Failed to retrieve locale info: ', error);
122131
}

src/components/DialogPopup.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import kind from '@enact/core/kind';
77

88
interface ButtonProps {
99
source: 'confirm' | 'abort';
10+
children: React.ReactNode;
1011
}
1112

1213
const DialogPopup = (props: {

src/components/TV.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,15 @@ const TV = () => {
279279
videoElement.appendChild(source);
280280

281281
// Auto-play video with some (unused) error handling
282-
videoElement
283-
.play()
284-
.then(() => setIsVideoPlaying(true))
285-
.catch((error) => console.log('channel switched before it could be played', error));
282+
const playPromise = videoElement.play();
283+
// workarund for promise not beeing returned in webos 3.x
284+
if (playPromise !== undefined) {
285+
playPromise
286+
.then(() => setIsVideoPlaying(true))
287+
.catch((error) => console.log('channel switched before it could be played', error));
288+
} else {
289+
setIsVideoPlaying(true);
290+
}
286291
};
287292

288293
const getWidth = () => window.innerWidth;

src/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'core-js/stable';
2+
import 'regenerator-runtime';
13
import React from 'react';
24
import ReactDOM from 'react-dom';
35
import App from './App';

src/polyfills.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import 'core-js/actual';
2+
import 'regenerator-runtime/runtime';

src/services/TVHDataService.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export default class TVHDataService {
9595
private httpProxyServiceAdapter = Config.httpProxyServiceAdapter;
9696
private epgCacheService = new EPGCacheService();
9797
private webosService = new WebOSService();
98-
private maxTotalEpgEntries = 10000;
98+
private maxTotalEpgEntries = 20000;
9999
private channels: EPGChannel[] = [];
100100
private url?: string;
101101
// private profile: string;
@@ -119,7 +119,7 @@ export default class TVHDataService {
119119
*/
120120
async getLocaleInfo() {
121121
const localeInfo = await this.webosService.getLocaleInfo();
122-
// console.log('getLocaleInfo:', localeInfo);
122+
console.log('getLocaleInfo:', localeInfo);
123123
return localeInfo;
124124
}
125125

@@ -429,10 +429,10 @@ export default class TVHDataService {
429429
});
430430
}
431431

432-
retrieveTVHEPG(start: number, callback: EPGCallback) {
432+
retrieveTVHEPG(start: number, callback: EPGCallback): void {
433433
let totalCount = 0;
434434

435-
return this.httpProxyServiceAdapter
435+
this.httpProxyServiceAdapter
436436
.call<TVHEvents>({
437437
url: this.url + TVHDataService.API_EPG + start,
438438
user: this.user,

src/services/WebOSService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default class WebOSService {
1717
*/
1818
async getLocaleInfo() {
1919
const localeInfo = await this.lunaServiceAdapter.getLocaleInfo();
20-
// console.log('getLocaleInfo:', localeInfo);
20+
console.log('getLocaleInfo:', localeInfo);
2121
return localeInfo;
2222
}
2323
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"moduleResolution": "node", // Resolve modules using Node.js style
1717
"isolatedModules": true, // Unconditionally emit imports for unresolved files
1818
"resolveJsonModule": true, // Include modules imported with .json extension
19-
"noEmit": true, // Do not emit output (meaning do not compile code, only perform type checking)
19+
"noEmit": false, // Do not emit output (meaning do not compile code, only perform type checking)
2020
"jsx": "react", // Support JSX in .tsx files
2121
"sourceMap": false, // Generate corrresponding .map file
2222
"declaration": false, // Generate corresponding .d.ts file

webpack.config.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
const path = require('path');
2+
const CopyPlugin = require('copy-webpack-plugin');
3+
const HtmlWebpackPlugin = require('html-webpack-plugin');
4+
5+
module.exports = {
6+
entry: {
7+
polyfills: './src/polyfills.js',
8+
index: './src/index.tsx'
9+
},
10+
output: {
11+
asyncChunks: true,
12+
clean: true,
13+
filename: '[name].bundle.js',
14+
path: path.resolve(__dirname, 'build')
15+
},
16+
plugins: [
17+
new HtmlWebpackPlugin({
18+
template: path.join(__dirname, 'public', 'index.html')
19+
}),
20+
new CopyPlugin({
21+
// copy appinfo and resources to build folder
22+
patterns: ['public/appinfo.json', 'public/splash.png', 'public/largeIcon.png', 'public/icon.png']
23+
})
24+
],
25+
devServer: {
26+
static: {
27+
directory: path.join(__dirname, 'build')
28+
},
29+
port: 3000
30+
},
31+
module: {
32+
rules: [
33+
{
34+
test: /\.(m?js|jsx)$/,
35+
//exclude: /node_modules/,
36+
use: ['babel-loader']
37+
},
38+
{
39+
test: /\.(ts|tsx)$/,
40+
exclude: /node_modules/,
41+
use: ['ts-loader']
42+
},
43+
{
44+
test: /\.(css)$/,
45+
use: ['style-loader', 'css-loader']
46+
},
47+
{
48+
test: /\.less$/i,
49+
use: [
50+
// compiles Less to CSS
51+
'style-loader',
52+
'css-loader',
53+
'less-loader'
54+
]
55+
}
56+
]
57+
},
58+
// pass all js files through Babel
59+
resolve: {
60+
extensions: ['*', '.js', '.jsx', '.ts', '.tsx']
61+
},
62+
optimization: {
63+
splitChunks: {
64+
chunks: 'all'
65+
}
66+
}
67+
};

0 commit comments

Comments
 (0)