-
Notifications
You must be signed in to change notification settings - Fork 162
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
Refactors TwaManifest.shortcuts #99
Refactors TwaManifest.shortcuts #99
Conversation
- Change `TwaManifest.shortcuts` to be `ShortcutInfo[]` instead of `string`. - Refactor code to reflect that change - Fixes reversed if condition in `init` leading to not adding shortcuts. - Test the result of `generateShortcut()§
@rayankans can you take a look as well? |
@@ -232,10 +232,7 @@ export class TwaGenerator { | |||
await this.generateIcons(twaManifest.iconUrl, targetDirectory, IMAGES); | |||
} | |||
|
|||
// TODO(andreban): TwaManifest.shortcuts is a string, which is being parsed into an Object. | |||
// Needs to be transformed into a proper Class. | |||
// eslint-disable-next-line @typescript-eslint/no-explicit-any |
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.
@PEConn I think this is the last any
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.
🎊
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.
LGTM with a few nits, thanks!
src/lib/TwaManifest.ts
Outdated
|
||
shortcuts.push(shortcutInfo); | ||
|
||
if (shortcuts.length === 3) { |
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.
4
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.
done
@@ -148,7 +148,7 @@ task generateShorcutsFile { | |||
'intent'( | |||
'android:action': 'android.intent.action.MAIN', | |||
'android:targetPackage': twaManifest.applicationId, | |||
'android:targetClass': 'android.support.customtabs.trusted.LauncherActivity', | |||
'android:targetClass': 'com.google.androidbrowserhelper.trusted.LauncherActivity', |
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.
Are you sure about this? I'm guessing you tested it and the previous targetClass did not work.
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.
I think this is a left-over when we migrated to androix.browser-1.2.0
, which doesn't have a LauncherActivity anymore. This should have been changed with the other references across the code.
src/lib/TwaManifest.ts
Outdated
.filter((_: ShortcutInfo, i: number) => i < 4); | ||
const shortcuts: ShortcutInfo[] = []; | ||
|
||
if (webManifest.shortcuts) { |
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.
nit: for (const s of (webManifest.shortcuts || [])) {
to reduce indentation.
I'm not too familiar with TS but it seems to me that webManifest.shortcuts is guaranteed to be a list instead of a null or undefined though?
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.
This is a WebManifest shortcut, defined here: https://github.com/GoogleChromeLabs/llama-pack/blob/master/src/lib/types/WebManifest.ts#L40
It can be undefined.
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.
changed the for loop.
@@ -148,7 +148,7 @@ task generateShorcutsFile { | |||
'intent'( | |||
'android:action': 'android.intent.action.MAIN', | |||
'android:targetPackage': twaManifest.applicationId, | |||
'android:targetClass': 'android.support.customtabs.trusted.LauncherActivity', | |||
'android:targetClass': 'com.google.androidbrowserhelper.trusted.LauncherActivity', |
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.
You've tested this, right?
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.
Yes, tested against https://contentindex.dev/manifest.json
. It works :)
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.
Does the previous value not work though? It's still working for me
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.
Are you using the android-browser-helper-1.1.0
? The old class doesn't exist anymore in androidx.browser
, so I wouldn't expect it to work.
@@ -232,10 +232,7 @@ export class TwaGenerator { | |||
await this.generateIcons(twaManifest.iconUrl, targetDirectory, IMAGES); | |||
} | |||
|
|||
// TODO(andreban): TwaManifest.shortcuts is a string, which is being parsed into an Object. | |||
// Needs to be transformed into a proper Class. | |||
// eslint-disable-next-line @typescript-eslint/no-explicit-any |
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.
🎊
src/lib/TwaManifest.ts
Outdated
return this.name != undefined && this.url != undefined && this.chosenIconUrl != undefined; | ||
constructor(readonly name: string, readonly shortName: string, readonly url: string, | ||
readonly chosenIconUrl: string) { | ||
this.name = name; |
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.
You're using Parameter Properties here right? I don't think you need lines 76 to 79.
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.
This is great! Updated!
- Changes shortcut limit from 3 to 4 - Improves identation
TwaManifest.shortcuts
to beShortcutInfo[]
insteadof
string
.init
leading to not addingshortcuts.
generateShortcut()
LauncherActivity
inbuild.gradle
short_name
to 12 characters, when unavailable and copying fromname
. Recommendation for 12 chars here