Skip to content

Commit

Permalink
Merge pull request #454 from lamarios/feature/dependency-updates-2024…
Browse files Browse the repository at this point in the history
…0112

update dependencies
  • Loading branch information
lamarios authored Jan 12, 2024
2 parents a034ac8 + 169c88b commit cf9c484
Show file tree
Hide file tree
Showing 5 changed files with 272 additions and 148 deletions.
8 changes: 4 additions & 4 deletions lib/player/states/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import 'package:invidious/player/models/media_event.dart';
import 'package:invidious/settings/states/settings.dart';
import 'package:invidious/videos/models/base_video.dart';
import 'package:logging/logging.dart';
import 'package:pretty_bytes/pretty_bytes.dart';
import 'package:wakelock/wakelock.dart';
import 'package:wakelock_plus/wakelock_plus.dart';

import '../../globals.dart';
import '../../main.dart';
import '../../utils/pretty_bytes.dart';
import '../../videos/models/video.dart';
import '../views/components/player_controls.dart';
import '../views/tv/components/player_controls.dart';
Expand Down Expand Up @@ -44,7 +44,7 @@ class VideoPlayerCubit extends MediaPlayerCubit<VideoPlayerState> {

@override
disposeControllers() {
Wakelock.disable();
WakelockPlus.disable();
log.fine("Disposing video controller");
var state = this.state.copyWith();
videoController?.exitFullScreen();
Expand Down Expand Up @@ -309,7 +309,7 @@ class VideoPlayerCubit extends MediaPlayerCubit<VideoPlayerState> {
);
}

Wakelock.enable();
WakelockPlus.enable();

bool fillVideo = settings.state.fillFullscreen;

Expand Down
164 changes: 164 additions & 0 deletions lib/utils/pretty_bytes.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import 'dart:math';

import 'package:intl/intl.dart';

const BYTE_UNITS = [
'B',
'KB',
'MB',
'GB',
'TB',
'PB',
'EB',
'ZB',
'YB',
];

const BIBYTE_UNITS = [
'B',
'KiB',
'MiB',
'GiB',
'TiB',
'PiB',
'EiB',
'ZiB',
'YiB',
];

const BIT_UNITS = [
'b',
'Kbit',
'Mbit',
'Gbit',
'Tbit',
'Pbit',
'Ebit',
'Zbit',
'Ybit',
];

const BIBIT_UNITS = [
'b',
'Kibit',
'Mibit',
'Gibit',
'Tibit',
'Pibit',
'Eibit',
'Zibit',
'Yibit',
];

double log10(num x) => log(x) / ln10;

var removeTrailingZerosRegex = RegExp(r'([.]*0)(?!.*\d)');

String toLocaleString(double number, String? locale, int? minimumFractionDigits,
int? maximumFractionDigits) {
if (locale == null) {
return number.toString().replaceAll(removeTrailingZerosRegex, '');
}
final formatter = NumberFormat(null, locale);
if (maximumFractionDigits != null) {
formatter.minimumFractionDigits = minimumFractionDigits!;
}
if (minimumFractionDigits != null) {
formatter.maximumFractionDigits = maximumFractionDigits!;
}
return formatter.format(number);
}

String prettyBytes(
double number, {
/// Include plus sign for positive numbers. If the difference is exactly zero a space character will be prepended instead for better alignment.
/// Default: false.
bool? signed,

/// - If `null`: Output won't be localized.
/// - If `string`: Expects a [BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) (For example: `en`, `de`, …)
/// @default null
String? locale,

/// Format the number as [bits](https://en.wikipedia.org/wiki/Bit) instead of [bytes](https://en.wikipedia.org/wiki/Byte). This can be useful when, for example, referring to [bit rate](https://en.wikipedia.org/wiki/Bit_rate).
/// Default: false.
/// @example
/// ```
/// prettyBytes(1337, bits: true);
/// //=> '1.34 kbit'
/// ```
bool? bits,

/// Format the number using the [Binary Prefix](https://en.wikipedia.org/wiki/Binary_prefix) instead of the [SI Prefix](https://en.wikipedia.org/wiki/SI_prefix). This can be useful for presenting memory amounts. However, this should not be used for presenting file sizes.
/// Default: false.
/// @example
/// ```
/// prettyBytes(1000, binary: true);
/// //=> '1000 bit'
/// prettyBytes(1024, binary: true);
/// //=> '1 kiB'
/// ```
bool? binary,

/// The minimum number of fraction digits to display.
/// If neither `minimumFractionDigits` or `maximumFractionDigits` are set, the default behavior is to round to 3 significant digits.
/// @default null
/// ```
/// // Show the number with at least 3 fractional digits
/// prettyBytes(1900, {minimumFractionDigits: 3});
/// //=> '1.900 kB'
/// prettyBytes(1900);
/// //=> '1.9 kB'
/// ```
int? minimumFractionDigits,

/// The maximum number of fraction digits to display.
/// If neither `minimumFractionDigits` or `maximumFractionDigits` are set, the default behavior is to round to 3 significant digits.
/// @default null
/// ```
/// // Show the number with at most 1 fractional digit
/// prettyBytes(1920, {maximumFractionDigits: 1});
/// //=> '1.9 kB'
/// prettyBytes(1920);
/// //=> '1.92 kB'
/// ```
int? maximumFractionDigits,
}) {
final UNITS = (bits == true)
? (binary == true ? BIBIT_UNITS : BIT_UNITS)
: (binary == true ? BIBYTE_UNITS : BYTE_UNITS);

if (signed == true && number == 0) {
return ' 0 ${UNITS[0]}';
}

final isNegative = number < 0;
final prefix = isNegative ? '-' : (signed == true ? '+' : '');

if (isNegative) {
number = -number;
}

if (number < 1) {
final numberStr = toLocaleString(
number, locale, minimumFractionDigits, maximumFractionDigits);
return prefix + numberStr + ' ' + UNITS[0];
}

final exponent = min(
(binary != null ? log(number) / log(1024) : log10(number) / 3)
.floorToDouble(),
(UNITS.length - 1).toDouble())
.toInt();
number /= pow(binary != null ? 1024 : 1000, exponent);
if (minimumFractionDigits == null && maximumFractionDigits == null) {
number = double.parse(number.toStringAsPrecision(3));
}

final numberStr = toLocaleString(
number, locale, minimumFractionDigits, maximumFractionDigits);

final unit = UNITS[exponent];

return '$prefix$numberStr $unit';
}
4 changes: 2 additions & 2 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import path_provider_foundation
import share_plus
import sqflite
import url_launcher_macos
import wakelock_macos
import wakelock_plus

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AudioServicePlugin.register(with: registry.registrar(forPlugin: "AudioServicePlugin"))
Expand All @@ -34,5 +34,5 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
WakelockMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockMacosPlugin"))
WakelockPlusMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockPlusMacosPlugin"))
}
Loading

0 comments on commit cf9c484

Please sign in to comment.