Skip to content

Commit 242a5b8

Browse files
Merge pull request #259 from rdkcentral/dev
Release v4.6.0
2 parents eeb7843 + 88be70a commit 242a5b8

File tree

8 files changed

+114
-39
lines changed

8 files changed

+114
-39
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## v4.6.0
4+
5+
*16 aug 2021*
6+
7+
- Added context to Pin plugin
8+
- Added option to overwrite the font loader from platform
9+
- Added cleanup of App fonts on app close
10+
- Fixed initial focus bug
11+
- Added storeSameHash flag to accepted config flags of Router
12+
- Fixed getQueryStringParams() using active hash in Router
13+
314
## v4.5.0
415

516
*12 july 2021*

docs/changelog.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## v4.6.0
4+
5+
*16 aug 2021*
6+
7+
- Added context to Pin plugin
8+
- Added option to overwrite the font loader from platform
9+
- Added cleanup of App fonts on app close
10+
- Fixed initial focus bug
11+
- Added storeSameHash flag to accepted config flags of Router
12+
- Fixed getQueryStringParams() using active hash in Router
13+
314
## v4.5.0
415

516
*12 july 2021*

docs/plugins/pin.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@ Pin.hide()
3636

3737
Sends a Pin code to the middleware layer for verification. If the code is correct, the STB will be unlocked.
3838

39+
The `submit` method accepts `pin` and `context` as it's arguments. The context argument indicates in with what purpsose the Pin dialog is being used. The accepted values van be either `parental` or `purchase`. `context` defaults to `purchase`, but it's recommended to explicitly specify the context
40+
3941
The `submit` method is automatically invoked when you are using the built-in **Pin** dialog. Use this method for sending the Pin code *only* if you are making a fully custom **Pin** dialog in your App.
4042

4143
```js
42-
Pin.submit('0000')
44+
Pin.submit('0000', context)
4345
.then(() => console.log('Unlocked!'))
4446
.catch(e => console.log('Pin error', e))
4547
```
4648

47-
The `submit` method returns a *Promise*. If the supplied Pin code is correct, the Promise resolves with `true` and the STB will be unlocked. If the Pin code is wrong, the Promise resolves with `false`.
49+
The `submit` method returns a *Promise*. If the supplied Pin code is correct (and context is valid), the Promise resolves with `true` and the STB will be unlocked. If the Pin code or context are wrong, the Promise resolves with `false`.
4850

4951
If the middleware is unable to unlock the STB, the Promise is *rejected* (with an optional error message).
5052

@@ -55,7 +57,7 @@ During development, the default Pin code is `0000`. Optionally, you can overwri
5557
Checks if the STB is currently *unlocked*.
5658

5759
```js
58-
Pin.unlocked()
60+
Pin.unlocked(context)
5961
.then(
6062
unlocked => unlocked === true ?
6163
console.log('STB is unlocked') :
@@ -71,7 +73,7 @@ If the middleware is unable to retrieve the current state, the Promise is *rejec
7173
Checks if the STB is currently *locked*.
7274

7375
```js
74-
Pin.locked()
76+
Pin.locked(context)
7577
.then(
7678
locked => locked === true ?
7779
console.log('STB is locked') :

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lightningjs/sdk",
3-
"version": "4.5.0",
3+
"version": "4.6.0",
44
"license": "Apache-2.0",
55
"scripts": {
66
"postinstall": "node ./scripts/postinstall.js",

src/Application/index.js

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,30 @@ if (window.innerHeight === 720) {
6262
defaultOptions.stage['precision'] = 0.6666666667
6363
}
6464

65+
const customFontFaces = []
66+
67+
const fontLoader = (fonts, store) =>
68+
new Promise((resolve, reject) => {
69+
fonts
70+
.map(({ family, url, urls, descriptors }) => () => {
71+
const src = urls
72+
? urls.map(url => {
73+
return 'url(' + url + ')'
74+
})
75+
: 'url(' + url + ')'
76+
const fontFace = new FontFace(family, src, descriptors || {})
77+
store.push(fontFace)
78+
Log.info('Loading font', family)
79+
document.fonts.add(fontFace)
80+
return fontFace.load()
81+
})
82+
.reduce((promise, method) => {
83+
return promise.then(() => method())
84+
}, Promise.resolve(null))
85+
.then(resolve)
86+
.catch(reject)
87+
})
88+
6589
export default function(App, appData, platformSettings) {
6690
return class Application extends Lightning.Application {
6791
constructor(options) {
@@ -99,6 +123,8 @@ export default function(App, appData, platformSettings) {
99123

100124
this.childList.a(AppInstance)
101125

126+
this._refocus()
127+
102128
Log.info('App version', this.config.version)
103129
Log.info('SDK version', sdkVersion)
104130

@@ -149,31 +175,27 @@ export default function(App, appData, platformSettings) {
149175
close() {
150176
Log.info('Closing App')
151177
this.childList.remove(this.tag('App'))
152-
178+
this.cleanupFonts()
153179
// force texture garbage collect
154180
this.stage.gc()
155181
this.destroy()
156182
}
157183

158184
loadFonts(fonts) {
159-
return new Promise((resolve, reject) => {
160-
fonts
161-
.map(({ family, url, urls, descriptors }) => () => {
162-
const src = urls
163-
? urls.map(url => {
164-
return 'url(' + url + ')'
165-
})
166-
: 'url(' + url + ')'
167-
const fontFace = new FontFace(family, src, descriptors || {})
168-
document.fonts.add(fontFace)
169-
return fontFace.load()
170-
})
171-
.reduce((promise, method) => {
172-
return promise.then(() => method())
173-
}, Promise.resolve(null))
174-
.then(resolve)
175-
.catch(reject)
176-
})
185+
return platformSettings.fontLoader && typeof platformSettings.fontLoader === 'function'
186+
? platformSettings.fontLoader(fonts, customFontFaces)
187+
: fontLoader(fonts, customFontFaces)
188+
}
189+
190+
cleanupFonts() {
191+
if ('delete' in document.fonts) {
192+
customFontFaces.forEach(fontFace => {
193+
Log.info('Removing font', fontFace.family)
194+
document.fonts.delete(fontFace)
195+
})
196+
} else {
197+
Log.info('No support for removing manually-added fonts')
198+
}
177199
}
178200

179201
loadLanguage(config) {

src/Pin/index.js

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
import Settings from '../Settings'
2121
import PinDialog from './dialog'
2222
import { ApplicationInstance } from '../Launch'
23+
import { Log } from '../../index'
2324

2425
// only used during local development
2526
let unlocked = false
27+
const contextItems = ['purchase', 'parental']
2628

27-
let submit = pin => {
29+
let submit = (pin, context) => {
2830
return new Promise((resolve, reject) => {
2931
if (pin.toString() === Settings.get('platform', 'pin', '0000').toString()) {
3032
unlocked = true
@@ -35,7 +37,7 @@ let submit = pin => {
3537
})
3638
}
3739

38-
let check = () => {
40+
let check = context => {
3941
return new Promise(resolve => {
4042
resolve(unlocked)
4143
})
@@ -52,6 +54,17 @@ export const initPin = config => {
5254

5355
let pinDialog = null
5456

57+
const contextCheck = context => {
58+
if (context === undefined) {
59+
Log.info('Please provide context explicitly')
60+
return contextItems[0]
61+
} else if (!contextItems.includes(context)) {
62+
Log.warn('Incorrect context provided')
63+
return false
64+
}
65+
return context
66+
}
67+
5568
// Public API
5669
export default {
5770
show() {
@@ -73,34 +86,49 @@ export default {
7386
)
7487
pinDialog = null
7588
},
76-
submit(pin) {
89+
submit(pin, context) {
7790
return new Promise((resolve, reject) => {
7891
try {
79-
submit(pin)
80-
.then(resolve)
81-
.catch(reject)
92+
context = contextCheck(context)
93+
if (context) {
94+
submit(pin, context)
95+
.then(resolve)
96+
.catch(reject)
97+
} else {
98+
reject('Incorrect Context provided')
99+
}
82100
} catch (e) {
83101
reject(e)
84102
}
85103
})
86104
},
87-
unlocked() {
105+
unlocked(context) {
88106
return new Promise((resolve, reject) => {
89107
try {
90-
check()
91-
.then(resolve)
92-
.catch(reject)
108+
context = contextCheck(context)
109+
if (context) {
110+
check(context)
111+
.then(resolve)
112+
.catch(reject)
113+
} else {
114+
reject('Incorrect Context provided')
115+
}
93116
} catch (e) {
94117
reject(e)
95118
}
96119
})
97120
},
98-
locked() {
121+
locked(context) {
99122
return new Promise((resolve, reject) => {
100123
try {
101-
check()
102-
.then(unlocked => resolve(!!!unlocked))
103-
.catch(reject)
124+
context = contextCheck(context)
125+
if (context) {
126+
check(context)
127+
.then(unlocked => resolve(!!!unlocked))
128+
.catch(reject)
129+
} else {
130+
reject('Incorrect Context provided')
131+
}
104132
} catch (e) {
105133
reject(e)
106134
}

src/Router/utils/helpers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export const getConfigMap = () => {
8888
'autoRestoreRemote',
8989
'numberNavigation',
9090
'updateHash',
91+
'storeSameHash',
9192
].reduce((config, key) => {
9293
config.set(key, isObj ? routerSettings[key] : Settings.get('platform', key))
9394
return config

0 commit comments

Comments
 (0)