-
Notifications
You must be signed in to change notification settings - Fork 584
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
kiosk: persist built game js in local storage #9726
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,17 @@ function delValue(key: string) { | |
localStorage.removeItem(key); | ||
} | ||
|
||
function matchingKeys(pattern: RegExp): string[] { | ||
const keys: string[] = []; | ||
for (let i = 0; i < localStorage.length; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It isn't clear to me what this function is used for, could you clarify? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function returns all local storage keys matching a regex pattern. It is called by the |
||
const key = localStorage.key(i); | ||
if (key && pattern.test(key)) { | ||
keys.push(key); | ||
} | ||
} | ||
return keys; | ||
} | ||
|
||
function getJsonValue<T>(key: string, defaultValue?: T): T | undefined { | ||
var value = getValue(key); | ||
if (value) { | ||
|
@@ -109,10 +120,29 @@ function clearKioskCode() { | |
delValue(Constants.legacy_kioskCodeExpirationStorageKey); | ||
} | ||
|
||
function getBuiltJsInfo(gameId: string): ts.pxtc.BuiltSimJsInfo | undefined { | ||
const ver = pxt.appTarget?.versions?.target; | ||
if (!ver) return undefined; | ||
const key = `builtjs:${ver}:${gameId}`; | ||
const rec = getJsonValue<ts.pxtc.BuiltSimJsInfo>(key); | ||
return rec; | ||
} | ||
|
||
function setBuiltJsInfo(gameId: string, builtJs: ts.pxtc.BuiltSimJsInfo) { | ||
const ver = pxt.appTarget?.versions?.target; | ||
if (!ver) return; | ||
const key = `builtjs:${ver}:${gameId}`; | ||
setJsonValue(key, builtJs); | ||
} | ||
|
||
function clearBuiltJsInfo() { | ||
const keys = matchingKeys(/^builtjs:/); | ||
for (const key of keys) { | ||
delValue(key); | ||
} | ||
} | ||
|
||
export { | ||
getValue, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these no longer used anywhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to restrict the use of these calls to only this file, to ensure that new code would follow the pattern of adding bespoke apis for the specific fields being persisted. Exposing the low-level apis can lead to unnecessarily complicated code elsewhere. |
||
setValue, | ||
delValue, | ||
getJsonValue, | ||
setJsonValue, | ||
getUserAddedGames, | ||
|
@@ -123,4 +153,7 @@ export { | |
setKioskCode, | ||
getKioskCode, | ||
clearKioskCode, | ||
getBuiltJsInfo, | ||
setBuiltJsInfo, | ||
clearBuiltJsInfo, | ||
}; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,3 +70,18 @@ export function nodeListToArray<U extends Node>(list: NodeListOf<U>): U[] { | |
} | ||
return out; | ||
} | ||
|
||
// Copied from pxt.Utils, modified to skip undefined values. | ||
export function stringifyQueryString(url: string, qs: any) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is more work and may not be needed, but I'm just wondering if there's benefit to defining a type for the object that is passed in for the query strings instead of just using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just copied this from pxt.Util in order to fix what seemed like a bug. Given that we use this function in so many places, I felt it too risky to fix it in place without causing a regression somewhere. The testing surface is quite large. The bug is that when I'll file an issue to track it. |
||
for (let k of Object.keys(qs)) { | ||
if (qs[k] != null) { | ||
if (url.indexOf("?") >= 0) { | ||
url += "&"; | ||
} else { | ||
url += "?"; | ||
} | ||
url += encodeURIComponent(k) + "=" + encodeURIComponent(qs[k]); | ||
} | ||
} | ||
return url; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I like this change! It makes it a lot clearer what the url is doing.