Skip to content

Commit

Permalink
removed updater by default
Browse files Browse the repository at this point in the history
  • Loading branch information
gokadzev committed Mar 30, 2023
1 parent 2a6fde6 commit b5ff8bc
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 60 deletions.
60 changes: 60 additions & 0 deletions add_updater.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
echo 'import "dart:convert";
import "dart:io";
import "package:file_picker/file_picker.dart";
import "package:flutter/material.dart";
import "package:flutter_downloader/flutter_downloader.dart";
import "package:flutter_gen/gen_l10n/app_localizations.dart";
import "package:http/http.dart" as http;
import "package:musify/API/version.dart";
import "package:musify/utilities/flutter_toast.dart";
late String dlUrl;
const apiUrl =
"https://raw.githubusercontent.com/gokadzev/Musify/update/check.json";
bool isUpdaterEnabled = true;
Future<void> checkAppUpdates(BuildContext context) async {
final response = await http.get(Uri.parse(apiUrl));
if (response.statusCode != 200) {
throw Exception("Failed to fetch app updates");
}
final map = json.decode(response.body) as Map<String, dynamic>;
if (map["version"].toString() != appVersion) {
await downloadAppUpdates();
showToast(
"${AppLocalizations.of(context)!.appUpdateAvailableAndDownloading}!",
);
}
}
Future<void> downloadAppUpdates() async {
final response = await http.get(Uri.parse(apiUrl));
if (response.statusCode != 200) {
throw Exception("Failed to fetch app updates");
}
final map = json.decode(response.body) as Map<String, dynamic>;
final dlUrl = await getCPUArchitecture() == "aarch64"
? map["arm64url"].toString()
: map["url"].toString();
final dlPath = await FilePicker.platform.getDirectoryPath();
final file = File("$dlPath/Musify.apk");
if (await file.exists()) {
await file.delete();
}
await FlutterDownloader.enqueue(
url: dlUrl,
savedDir: dlPath!,
fileName: "app.apk",
showNotification: true,
);
}
Future<String> getCPUArchitecture() async {
final info = await Process.run("uname", ["-m"]);
final cpu = info.stdout.toString().replaceAll("\n", "");
return cpu;
}
' > lib/services/update_manager.dart
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
analyzer:
exclude:
- packages/**
- lib/services/update_manager.dart

linter:
rules:
Expand Down
16 changes: 9 additions & 7 deletions lib/screens/more_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,15 @@ class SettingsCards extends StatelessWidget {
),
},
),
SettingBar(
AppLocalizations.of(context)!.downloadAppUpdate,
FluentIcons.arrow_download_24_filled,
() => {
checkAppUpdates(context),
},
),
isUpdaterEnabled
? SettingBar(
AppLocalizations.of(context)!.downloadAppUpdate,
FluentIcons.arrow_download_24_filled,
() => {
checkAppUpdates(context),
},
)
: const SizedBox(),
// CATEGORY: OTHERS
Text(
AppLocalizations.of(context)!.others,
Expand Down
55 changes: 2 additions & 53 deletions lib/services/update_manager.dart
Original file line number Diff line number Diff line change
@@ -1,56 +1,5 @@
import 'dart:convert';
import 'dart:io';

import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_downloader/flutter_downloader.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:http/http.dart' as http;
import 'package:musify/API/version.dart';
import 'package:musify/utilities/flutter_toast.dart';

late String dlUrl;
const apiUrl =
'https://raw.githubusercontent.com/gokadzev/Musify/update/check.json';

Future<void> checkAppUpdates(BuildContext context) async {
final response = await http.get(Uri.parse(apiUrl));
if (response.statusCode != 200) {
throw Exception('Failed to fetch app updates');
}
final map = json.decode(response.body) as Map<String, dynamic>;
if (map['version'].toString() != appVersion) {
await downloadAppUpdates();
showToast(
'${AppLocalizations.of(context)!.appUpdateAvailableAndDownloading}!',
);
}
}

Future<void> downloadAppUpdates() async {
final response = await http.get(Uri.parse(apiUrl));
if (response.statusCode != 200) {
throw Exception('Failed to fetch app updates');
}
final map = json.decode(response.body) as Map<String, dynamic>;
final dlUrl = await getCPUArchitecture() == 'aarch64'
? map['arm64url'].toString()
: map['url'].toString();
final dlPath = await FilePicker.platform.getDirectoryPath();
final file = File('$dlPath/Musify.apk');
if (await file.exists()) {
await file.delete();
}
await FlutterDownloader.enqueue(
url: dlUrl,
savedDir: dlPath!,
fileName: 'Musify.apk',
showNotification: true,
);
}
bool isUpdaterEnabled = false;

Future<String> getCPUArchitecture() async {
final info = await Process.run('uname', ['-m']);
final cpu = info.stdout.toString().replaceAll('\n', '');
return cpu;
}
void checkAppUpdates(BuildContext context) {}

0 comments on commit b5ff8bc

Please sign in to comment.