Skip to content

Commit

Permalink
feat: skin avatar and re-login (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
SiongSng authored Aug 25, 2023
2 parents 44a3f03 + a5ba2f4 commit c721c40
Show file tree
Hide file tree
Showing 49 changed files with 2,031 additions and 1,136 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Install Flutter SDK
uses: subosito/flutter-action@v2
with:
flutter-version: "3.10.5"
flutter-version: "3.13.0"
channel: "stable"
cache: true
- name: Install Rust Language
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: "3.10.5"
flutter-version: "3.13.0"
channel: "stable"
cache: true
- name: Install Rust Language
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: "3.10.5"
flutter-version: "3.13.0"
channel: "stable"
cache: true
- name: Install Rust Language
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Install Flutter SDK
uses: subosito/flutter-action@v2
with:
flutter-version: "3.10.5"
flutter-version: "3.13.0"
channel: "stable"
cache: true
- name: Install Rust Language
Expand Down
Binary file added app/assets/images/steve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions app/lib/api/authentication/authentication_api.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'dart:async';
import 'dart:io';

import 'package:era_connect/api/gen/bridge_definitions.dart' as bridge;
import 'package:era_connect/api/ffi.dart';
import 'package:flutter/widgets.dart';

final AuthenticationApi authenticationApi = AuthenticationApi();

Expand Down Expand Up @@ -43,3 +45,29 @@ class AuthenticationApi {
);
}
}

extension MinecraftSkinExtension on bridge.MinecraftSkin {
Image renderHead({required double size}) {
final defaultImage = Image.asset(
'assets/images/steve.png',
width: size,
height: size,
);

final path = api.getSkinFilePath(skin: this);
if (path == null) return defaultImage;

final file = File(path);
if (!file.existsSync()) return defaultImage;

return Image.file(
file,
scale: 0.9,
width: size,
height: size,
errorBuilder: (context, error, stackTrace) {
return defaultImage;
},
);
}
}
10 changes: 9 additions & 1 deletion app/lib/api/ffi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'dart:ffi';
// Re-export the bridge so it is only necessary to import this file.
import 'dart:io' as io;

import 'package:meta/meta.dart';

import 'gen/bridge_generated.dart';

const _base = 'native';
Expand All @@ -15,6 +17,12 @@ const _base = 'native';
// but rather directly **linked** against the binary.
final _dylib = io.Platform.isWindows ? '$_base.dll' : 'lib$_base.so';

final NativeImpl api = NativeImpl(io.Platform.isIOS || io.Platform.isMacOS
NativeImpl _api = NativeImpl(io.Platform.isIOS || io.Platform.isMacOS
? DynamicLibrary.executable()
: DynamicLibrary.open(_dylib));

NativeImpl get api => _api;
@visibleForTesting
set api(NativeImpl value) {
_api = value;
}
14 changes: 10 additions & 4 deletions app/lib/api/gen/bridge_definitions.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// coverage:ignore-file
// AUTO GENERATED FILE, DO NOT EDIT.
// Generated by `flutter_rust_bridge`@ 1.81.0.
// ignore_for_file: non_constant_identifier_names, unused_element, duplicate_ignore, directives_ordering, curly_braces_in_flow_control_structures, unnecessary_lambdas, slash_for_doc_comments, prefer_const_literals_to_create_immutables, implicit_dynamic_list_literal, duplicate_import, unused_import, unnecessary_import, prefer_single_quotes, prefer_const_constructors, use_super_parameters, always_use_package_imports, annotate_overrides, invalid_use_of_protected_member, constant_identifier_names, invalid_use_of_internal_member, prefer_is_empty, unnecessary_const
Expand Down Expand Up @@ -49,10 +50,13 @@ abstract class Native {

FlutterRustBridgeTaskConstMeta get kGetAccountStorageConstMeta;

Future<void> setAccountStorage(
{required AccountStorageValue value, dynamic hint});
String? getSkinFilePath({required MinecraftSkin skin, dynamic hint});

FlutterRustBridgeTaskConstMeta get kSetAccountStorageConstMeta;
FlutterRustBridgeTaskConstMeta get kGetSkinFilePathConstMeta;

Future<void> removeMinecraftAccount({required UuidValue uuid, dynamic hint});

FlutterRustBridgeTaskConstMeta get kRemoveMinecraftAccountConstMeta;

Stream<LoginFlowEvent> minecraftLoginFlow({dynamic hint});

Expand Down Expand Up @@ -106,7 +110,9 @@ sealed class LoginFlowErrors with _$LoginFlowErrors {
XstsTokenErrorType field0,
) = LoginFlowErrors_XstsError;
const factory LoginFlowErrors.gameNotOwned() = LoginFlowErrors_GameNotOwned;
const factory LoginFlowErrors.unknownError() = LoginFlowErrors_UnknownError;
const factory LoginFlowErrors.unknownError(
String field0,
) = LoginFlowErrors_UnknownError;
}

@freezed
Expand Down
72 changes: 52 additions & 20 deletions app/lib/api/gen/bridge_definitions.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -370,21 +370,21 @@ mixin _$LoginFlowErrors {
TResult when<TResult extends Object?>({
required TResult Function(XstsTokenErrorType field0) xstsError,
required TResult Function() gameNotOwned,
required TResult Function() unknownError,
required TResult Function(String field0) unknownError,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(XstsTokenErrorType field0)? xstsError,
TResult? Function()? gameNotOwned,
TResult? Function()? unknownError,
TResult? Function(String field0)? unknownError,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(XstsTokenErrorType field0)? xstsError,
TResult Function()? gameNotOwned,
TResult Function()? unknownError,
TResult Function(String field0)? unknownError,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
Expand Down Expand Up @@ -498,7 +498,7 @@ class _$LoginFlowErrors_XstsError implements LoginFlowErrors_XstsError {
TResult when<TResult extends Object?>({
required TResult Function(XstsTokenErrorType field0) xstsError,
required TResult Function() gameNotOwned,
required TResult Function() unknownError,
required TResult Function(String field0) unknownError,
}) {
return xstsError(field0);
}
Expand All @@ -508,7 +508,7 @@ class _$LoginFlowErrors_XstsError implements LoginFlowErrors_XstsError {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(XstsTokenErrorType field0)? xstsError,
TResult? Function()? gameNotOwned,
TResult? Function()? unknownError,
TResult? Function(String field0)? unknownError,
}) {
return xstsError?.call(field0);
}
Expand All @@ -518,7 +518,7 @@ class _$LoginFlowErrors_XstsError implements LoginFlowErrors_XstsError {
TResult maybeWhen<TResult extends Object?>({
TResult Function(XstsTokenErrorType field0)? xstsError,
TResult Function()? gameNotOwned,
TResult Function()? unknownError,
TResult Function(String field0)? unknownError,
required TResult orElse(),
}) {
if (xstsError != null) {
Expand Down Expand Up @@ -615,7 +615,7 @@ class _$LoginFlowErrors_GameNotOwned implements LoginFlowErrors_GameNotOwned {
TResult when<TResult extends Object?>({
required TResult Function(XstsTokenErrorType field0) xstsError,
required TResult Function() gameNotOwned,
required TResult Function() unknownError,
required TResult Function(String field0) unknownError,
}) {
return gameNotOwned();
}
Expand All @@ -625,7 +625,7 @@ class _$LoginFlowErrors_GameNotOwned implements LoginFlowErrors_GameNotOwned {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(XstsTokenErrorType field0)? xstsError,
TResult? Function()? gameNotOwned,
TResult? Function()? unknownError,
TResult? Function(String field0)? unknownError,
}) {
return gameNotOwned?.call();
}
Expand All @@ -635,7 +635,7 @@ class _$LoginFlowErrors_GameNotOwned implements LoginFlowErrors_GameNotOwned {
TResult maybeWhen<TResult extends Object?>({
TResult Function(XstsTokenErrorType field0)? xstsError,
TResult Function()? gameNotOwned,
TResult Function()? unknownError,
TResult Function(String field0)? unknownError,
required TResult orElse(),
}) {
if (gameNotOwned != null) {
Expand Down Expand Up @@ -689,6 +689,8 @@ abstract class _$$LoginFlowErrors_UnknownErrorCopyWith<$Res> {
_$LoginFlowErrors_UnknownError value,
$Res Function(_$LoginFlowErrors_UnknownError) then) =
__$$LoginFlowErrors_UnknownErrorCopyWithImpl<$Res>;
@useResult
$Res call({String field0});
}

/// @nodoc
Expand All @@ -699,58 +701,82 @@ class __$$LoginFlowErrors_UnknownErrorCopyWithImpl<$Res>
_$LoginFlowErrors_UnknownError _value,
$Res Function(_$LoginFlowErrors_UnknownError) _then)
: super(_value, _then);

@pragma('vm:prefer-inline')
@override
$Res call({
Object? field0 = null,
}) {
return _then(_$LoginFlowErrors_UnknownError(
null == field0
? _value.field0
: field0 // ignore: cast_nullable_to_non_nullable
as String,
));
}
}

/// @nodoc
class _$LoginFlowErrors_UnknownError implements LoginFlowErrors_UnknownError {
const _$LoginFlowErrors_UnknownError();
const _$LoginFlowErrors_UnknownError(this.field0);

@override
final String field0;

@override
String toString() {
return 'LoginFlowErrors.unknownError()';
return 'LoginFlowErrors.unknownError(field0: $field0)';
}

@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$LoginFlowErrors_UnknownError);
other is _$LoginFlowErrors_UnknownError &&
(identical(other.field0, field0) || other.field0 == field0));
}

@override
int get hashCode => runtimeType.hashCode;
int get hashCode => Object.hash(runtimeType, field0);

@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$LoginFlowErrors_UnknownErrorCopyWith<_$LoginFlowErrors_UnknownError>
get copyWith => __$$LoginFlowErrors_UnknownErrorCopyWithImpl<
_$LoginFlowErrors_UnknownError>(this, _$identity);

@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(XstsTokenErrorType field0) xstsError,
required TResult Function() gameNotOwned,
required TResult Function() unknownError,
required TResult Function(String field0) unknownError,
}) {
return unknownError();
return unknownError(field0);
}

@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(XstsTokenErrorType field0)? xstsError,
TResult? Function()? gameNotOwned,
TResult? Function()? unknownError,
TResult? Function(String field0)? unknownError,
}) {
return unknownError?.call();
return unknownError?.call(field0);
}

@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(XstsTokenErrorType field0)? xstsError,
TResult Function()? gameNotOwned,
TResult Function()? unknownError,
TResult Function(String field0)? unknownError,
required TResult orElse(),
}) {
if (unknownError != null) {
return unknownError();
return unknownError(field0);
}
return orElse();
}
Expand Down Expand Up @@ -791,7 +817,13 @@ class _$LoginFlowErrors_UnknownError implements LoginFlowErrors_UnknownError {
}

abstract class LoginFlowErrors_UnknownError implements LoginFlowErrors {
const factory LoginFlowErrors_UnknownError() = _$LoginFlowErrors_UnknownError;
const factory LoginFlowErrors_UnknownError(final String field0) =
_$LoginFlowErrors_UnknownError;

String get field0;
@JsonKey(ignore: true)
_$$LoginFlowErrors_UnknownErrorCopyWith<_$LoginFlowErrors_UnknownError>
get copyWith => throw _privateConstructorUsedError;
}

/// @nodoc
Expand Down
Loading

0 comments on commit c721c40

Please sign in to comment.