Skip to content

Commit

Permalink
Bugfix for different ID same URL Apps (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
Imran Remtulla committed Feb 18, 2023
1 parent 86131ae commit ea81b0e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/pages/add_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class _AddAppPageState extends State<AddAppPage> {
await settingsProvider.getInstallPermission();
}
// Only download the APK here if you need to for the package ID
if (sourceProvider.isTempId(app.id) &&
if (sourceProvider.isTempId(app) &&
app.additionalSettings['trackOnly'] != true) {
// ignore: use_build_context_synchronously
var apkUrl = await appsProvider.confirmApkUrl(app, context);
Expand Down
10 changes: 9 additions & 1 deletion lib/pages/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class _AppPageState extends State<AppPage> {
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(height: 150),
const SizedBox(height: 125),
app?.installedInfo != null
? Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Image.memory(
Expand All @@ -136,6 +136,14 @@ class _AppPageState extends State<AppPage> {
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.headlineMedium,
),
const SizedBox(
height: 8,
),
Text(
app?.app.id ?? '',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.labelSmall,
),
const SizedBox(
height: 32,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/providers/apps_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class AppsProvider with ChangeNotifier {
// The former case should be handled (give the App its real ID), the latter is a security issue
var newInfo = await PackageArchiveInfo.fromPath(downloadedFile.path);
if (app.id != newInfo.packageName) {
if (apps[app.id] != null && !SourceProvider().isTempId(app.id)) {
if (apps[app.id] != null && !SourceProvider().isTempId(app)) {
throw IDChangedError();
}
var originalAppId = app.id;
Expand Down
21 changes: 6 additions & 15 deletions lib/providers/source_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -350,21 +350,12 @@ class SourceProvider {
return false;
}

String generateTempID(AppNames names, AppSource source) =>
'${names.author.toLowerCase()}_${names.name.toLowerCase()}_${source.host}';
String generateTempID(
String standardUrl, Map<String, dynamic> additionalSettings) =>
(standardUrl + additionalSettings.toString()).hashCode.toString();

bool isTempId(String id) {
List<String> parts = id.split('_');
if (parts.length < 3) {
return false;
}
for (int i = 0; i < parts.length - 1; i++) {
if (RegExp('.*[A-Z].*').hasMatch(parts[i])) {
// TODO: Look into RegEx for non-Latin characters
return false;
}
}
return true;
bool isTempId(App app) {
return app.id == generateTempID(app.url, app.additionalSettings);
}

Future<App> getApp(
Expand Down Expand Up @@ -400,7 +391,7 @@ class SourceProvider {
currentApp?.id ??
source.tryInferringAppId(standardUrl,
additionalSettings: additionalSettings) ??
generateTempID(apk.names, source),
generateTempID(standardUrl, additionalSettings),
standardUrl,
apk.names.author[0].toUpperCase() + apk.names.author.substring(1),
name.trim().isNotEmpty
Expand Down

0 comments on commit ea81b0e

Please sign in to comment.