Remove the need to hardcode Obtainium's version number

This commit is contained in:
Imran Remtulla
2024-01-14 01:22:35 -05:00
parent 5d161160aa
commit ffe612708c
5 changed files with 57 additions and 45 deletions

View File

@ -2,6 +2,12 @@ name: Build and Release
on: on:
workflow_dispatch: workflow_dispatch:
inputs:
beta:
type: boolean
description: Is beta?
environment:
type: environment
jobs: jobs:
build: build:
@ -47,12 +53,13 @@ jobs:
- name: Extract Version - name: Extract Version
id: extract_version id: extract_version
run: | run: |
VERSION=$(grep -oP "currentVersion = '\K[^']+" lib/main.dart) VERSION=$(grep -oP "^version: [^\+]+" pubspec.yaml | tail -c +10)
echo "version=$VERSION" >> $GITHUB_OUTPUT echo "version=$VERSION" >> $GITHUB_OUTPUT
TAG=$(grep -oP "'.*\\\$currentVersion.*'" lib/main.dart | head -c -2 | tail -c +2 | sed "s/\$currentVersion/$VERSION/g") if [ ${{ inputs.beta }} == true ]; then BETA=true; else BETA=false; fi
echo "tag=$TAG" >> $GITHUB_OUTPUT
if [ -n "$(echo $TAG | grep -oP '\-beta$')" ]; then BETA=true; else BETA=false; fi
echo "beta=$BETA" >> $GITHUB_OUTPUT echo "beta=$BETA" >> $GITHUB_OUTPUT
TAG="v$VERSION"
if [ $BETA == true ]; then TAG="$TAG"-beta; fi
echo "tag=$TAG" >> $GITHUB_OUTPUT
- name: Create Tag - name: Create Tag
uses: mathieudutour/github-tag-action@v6.1 uses: mathieudutour/github-tag-action@v6.1

View File

@ -7,6 +7,7 @@ import 'package:obtainium/providers/apps_provider.dart';
import 'package:obtainium/providers/logs_provider.dart'; import 'package:obtainium/providers/logs_provider.dart';
import 'package:obtainium/providers/notifications_provider.dart'; import 'package:obtainium/providers/notifications_provider.dart';
import 'package:obtainium/providers/settings_provider.dart'; import 'package:obtainium/providers/settings_provider.dart';
import 'package:obtainium/providers/source_provider.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:dynamic_color/dynamic_color.dart'; import 'package:dynamic_color/dynamic_color.dart';
@ -18,10 +19,6 @@ import 'package:easy_localization/src/easy_localization_controller.dart';
// ignore: implementation_imports // ignore: implementation_imports
import 'package:easy_localization/src/localization.dart'; import 'package:easy_localization/src/localization.dart';
const String currentVersion = '0.15.11';
const String currentReleaseTag =
'v$currentVersion-beta'; // KEEP THIS IN SYNC WITH GITHUB RELEASES
List<MapEntry<Locale, String>> supportedLocales = const [ List<MapEntry<Locale, String>> supportedLocales = const [
MapEntry(Locale('en'), 'English'), MapEntry(Locale('en'), 'English'),
MapEntry(Locale('zh'), '简体中文'), MapEntry(Locale('zh'), '简体中文'),
@ -174,7 +171,29 @@ class _ObtainiumState extends State<Obtainium> {
// If this is the first run, ask for notification permissions and add Obtainium to the Apps list // If this is the first run, ask for notification permissions and add Obtainium to the Apps list
Permission.notification.request(); Permission.notification.request();
if (!fdroid) { if (!fdroid) {
appsProvider.saveApps([obtainiumApp], onlyIfExists: false); getInstalledInfo(obtainiumId).then((value) {
if (value?.versionName != null) {
appsProvider.saveApps([
App(
obtainiumId,
obtainiumUrl,
'ImranR98',
'Obtainium',
value!.versionName,
value.versionName!,
[],
0,
{
'includePrereleases': true,
'versionDetection': 'standardVersionDetection'
},
null,
false)
], onlyIfExists: false);
}
}).catchError((err) {
print(err);
});
} }
} }
if (!supportedLocales if (!supportedLocales

View File

@ -904,7 +904,7 @@ class AppsPageState extends State<AppsPage> {
}))}">${a.name}</a></li>\n'; }))}">${a.name}</a></li>\n';
} }
urls += urls +=
'</ul>\n\n<p><a href="${obtainiumApp.url}">${tr('about')}</a></p>'; '</ul>\n\n<p><a href="$obtainiumUrl">${tr('about')}</a></p>';
Share.share(urls, Share.share(urls,
subject: subject:
'${tr('obtainium')} - ${tr('appsString')}'); '${tr('obtainium')} - ${tr('appsString')}');

View File

@ -234,6 +234,20 @@ Future<File> downloadFile(
return downloadedFile; return downloadedFile;
} }
Future<PackageInfo?> getInstalledInfo(String? packageName,
{bool printErr = true}) async {
if (packageName != null) {
try {
return await pm.getPackageInfo(packageName: packageName);
} catch (e) {
if (printErr) {
print(e); // OK
}
}
}
return null;
}
class AppsProvider with ChangeNotifier { class AppsProvider with ChangeNotifier {
// In memory App state (should always be kept in sync with local storage versions) // In memory App state (should always be kept in sync with local storage versions)
Map<String, AppInMemory> apps = {}; Map<String, AppInMemory> apps = {};
@ -404,7 +418,7 @@ class AppsProvider with ChangeNotifier {
.isNotEmpty; .isNotEmpty;
Future<bool> canInstallSilently(App app) async { Future<bool> canInstallSilently(App app) async {
if (app.id == obtainiumApp.id) { if (app.id == obtainiumId) {
return false; return false;
} }
if (!settingsProvider.enableBackgroundUpdates) { if (!settingsProvider.enableBackgroundUpdates) {
@ -428,7 +442,7 @@ class AppsProvider with ChangeNotifier {
} catch (e) { } catch (e) {
// Probably not installed - ignore // Probably not installed - ignore
} }
if (installerPackageName != obtainiumApp.id) { if (installerPackageName != obtainiumId) {
// If we did not install the app (or it isn't installed), silent install is not possible // If we did not install the app (or it isn't installed), silent install is not possible
return false; return false;
} }
@ -639,6 +653,7 @@ class AppsProvider with ChangeNotifier {
MapEntry<String, String>? apkUrl; MapEntry<String, String>? apkUrl;
var trackOnly = apps[id]!.app.additionalSettings['trackOnly'] == true; var trackOnly = apps[id]!.app.additionalSettings['trackOnly'] == true;
if (!trackOnly) { if (!trackOnly) {
// ignore: use_build_context_synchronously
apkUrl = await confirmApkUrl(apps[id]!.app, context); apkUrl = await confirmApkUrl(apps[id]!.app, context);
} }
if (apkUrl != null) { if (apkUrl != null) {
@ -673,7 +688,7 @@ class AppsProvider with ChangeNotifier {
// Move Obtainium to the end of the line (let all other apps update first) // Move Obtainium to the end of the line (let all other apps update first)
appsToInstall = appsToInstall =
moveStrToEnd(appsToInstall, obtainiumApp.id, strB: obtainiumTempId); moveStrToEnd(appsToInstall, obtainiumId, strB: obtainiumTempId);
Future<void> updateFn(String id, {bool skipInstalls = false}) async { Future<void> updateFn(String id, {bool skipInstalls = false}) async {
try { try {
@ -775,20 +790,6 @@ class AppsProvider with ChangeNotifier {
return appsDir; return appsDir;
} }
Future<PackageInfo?> getInstalledInfo(String? packageName,
{bool printErr = true}) async {
if (packageName != null) {
try {
return await pm.getPackageInfo(packageName: packageName);
} catch (e) {
if (printErr) {
print(e); // OK
}
}
}
return null;
}
bool isVersionDetectionPossible(AppInMemory? app) { bool isVersionDetectionPossible(AppInMemory? app) {
if (app?.app == null) { if (app?.app == null) {
return false; return false;
@ -1678,8 +1679,7 @@ Future<void> bgUpdateCheck(String taskId, Map<String, dynamic>? params) async {
} }
if (toInstall.isNotEmpty) { if (toInstall.isNotEmpty) {
logs.add('BG install task: Started (${toInstall.length}).'); logs.add('BG install task: Started (${toInstall.length}).');
var tempObtArr = var tempObtArr = toInstall.where((element) => element.key == obtainiumId);
toInstall.where((element) => element.key == obtainiumApp.id);
if (tempObtArr.isNotEmpty) { if (tempObtArr.isNotEmpty) {
// Move obtainium to the end of the list as it must always install last // Move obtainium to the end of the list as it must always install last
var obt = tempObtArr.first; var obt = tempObtArr.first;

View File

@ -15,22 +15,8 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:shared_storage/shared_storage.dart' as saf; import 'package:shared_storage/shared_storage.dart' as saf;
String obtainiumTempId = 'imranr98_obtainium_${GitHub().hosts[0]}'; String obtainiumTempId = 'imranr98_obtainium_${GitHub().hosts[0]}';
String obtainiumId = 'dev.imranr.obtainium';
App obtainiumApp = App( String obtainiumUrl = 'https://github.com/ImranR98/Obtainium';
'dev.imranr.obtainium',
'https://github.com/ImranR98/Obtainium',
'ImranR98',
'Obtainium',
currentReleaseTag,
currentReleaseTag,
[],
0,
{
'includePrereleases': true,
'versionDetection': 'standardVersionDetection'
},
null,
false);
enum InstallMethodSettings { normal, shizuku, root } enum InstallMethodSettings { normal, shizuku, root }