refactor: Remove unused code
This commit is contained in:
parent
4a6a77336c
commit
1f7ce96623
6 changed files with 0 additions and 323 deletions
|
|
@ -1,40 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import '../date_time_extension.dart';
|
||||
|
||||
extension PresenceExtension on CachedPresence {
|
||||
String getLocalizedLastActiveAgo(BuildContext context) {
|
||||
final lastActiveTimestamp = this.lastActiveTimestamp;
|
||||
if (lastActiveTimestamp != null) {
|
||||
return L10n.of(context)!
|
||||
.lastActiveAgo(lastActiveTimestamp.localizedTimeShort(context));
|
||||
}
|
||||
return L10n.of(context)!.lastSeenLongTimeAgo;
|
||||
}
|
||||
|
||||
String getLocalizedStatusMessage(BuildContext context) {
|
||||
final statusMsg = this.statusMsg;
|
||||
if (statusMsg != null && statusMsg.isNotEmpty) {
|
||||
return statusMsg;
|
||||
}
|
||||
if (currentlyActive ?? false) {
|
||||
return L10n.of(context)!.currentlyActive;
|
||||
}
|
||||
return getLocalizedLastActiveAgo(context);
|
||||
}
|
||||
|
||||
Color get color {
|
||||
switch (presence) {
|
||||
case PresenceType.online:
|
||||
return Colors.green;
|
||||
case PresenceType.offline:
|
||||
return Colors.grey;
|
||||
case PresenceType.unavailable:
|
||||
default:
|
||||
return Colors.red;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
extension StringCasingExtension on String {
|
||||
String removeDiacritics() {
|
||||
const withDia =
|
||||
'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
|
||||
const withoutDia =
|
||||
'AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz';
|
||||
|
||||
String str = this;
|
||||
for (int i = 0; i < withDia.length; i++) {
|
||||
str = str.replaceAll(withDia[i], withoutDia[i]);
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,117 +0,0 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
import 'platform_infos.dart';
|
||||
|
||||
/// helper class checking for updates on platforms without store release
|
||||
///
|
||||
/// Currently, this is only Windows
|
||||
class UpdateCheckerNoStore {
|
||||
static const gitLabProjectId = '16112282';
|
||||
static const gitLabHost = 'gitlab.com';
|
||||
|
||||
static Uri get tagsUri => Uri.parse(
|
||||
'https://$gitLabHost/projects/$gitLabProjectId/repository/tags',
|
||||
);
|
||||
|
||||
final BuildContext context;
|
||||
|
||||
const UpdateCheckerNoStore(this.context);
|
||||
|
||||
Future<void> checkUpdate() async {
|
||||
// platform-specific implementations
|
||||
try {
|
||||
if (PlatformInfos.isWindows) {
|
||||
final response = await get(tagsUri);
|
||||
if (response.statusCode == 200) {
|
||||
final json = jsonDecode(response.body);
|
||||
var latestTag = json[0]['name'] as String;
|
||||
var currentVersion = await PlatformInfos.getVersion();
|
||||
|
||||
if (latestTag.startsWith('v')) {
|
||||
latestTag = latestTag.substring(1);
|
||||
}
|
||||
if (currentVersion.startsWith('v')) {
|
||||
currentVersion = currentVersion.substring(1);
|
||||
}
|
||||
if (latestTag != currentVersion) {
|
||||
final metadata = UpdateMetadata(latestTag);
|
||||
await showUpdateDialog(metadata);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
throw response;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
Logs().i('Could not look for updates:', e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Uri downloadUri(UpdateMetadata metadata) {
|
||||
// platform specific
|
||||
if (PlatformInfos.isWindows) {
|
||||
return Uri.parse('https://$gitLabHost/famedly/fluffychat/-'
|
||||
'/jobs/artifacts/$metadata/raw/'
|
||||
'build/windows/runner/Release/fluffychat.msix?job=build_windows');
|
||||
} else {
|
||||
throw UnimplementedError('No download URI available for this platform.');
|
||||
}
|
||||
}
|
||||
|
||||
/// launches an app update
|
||||
///
|
||||
/// Either uses the operating systems package or app management to perform
|
||||
/// an update or launches a custom installer
|
||||
Future<void> launchUpdater(UpdateMetadata metadata) async {
|
||||
// platform specific
|
||||
try {
|
||||
if (kIsWeb) return;
|
||||
if (PlatformInfos.isWindows) {
|
||||
final dir = await getTemporaryDirectory();
|
||||
final response = await get(downloadUri(metadata));
|
||||
if (response.statusCode == 200) {
|
||||
final file = File('${dir.path}/fluffychat.msix');
|
||||
await file.writeAsBytes(response.bodyBytes);
|
||||
Process.start(file.path, [], runInShell: true);
|
||||
} else {
|
||||
throw response;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
Logs().w('Error launching th update:', e);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> showUpdateDialog(UpdateMetadata metadata) async {
|
||||
final result = await showOkCancelAlertDialog(
|
||||
title: L10n.of(context)!.updateAvailable,
|
||||
message: L10n.of(context)!.updateNow,
|
||||
context: context,
|
||||
);
|
||||
if (result == OkCancelResult.ok) {
|
||||
await launchUpdater(metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class UpdateMetadata {
|
||||
final String version;
|
||||
|
||||
const UpdateMetadata(this.version);
|
||||
|
||||
@override
|
||||
String toString() => 'v$version';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue