Skip to content

Commit

Permalink
feat: add check and warning for Wayland session
Browse files Browse the repository at this point in the history
  • Loading branch information
Merrit committed Jan 18, 2023
1 parent 5ebd9bf commit 901e4cc
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 27 deletions.
24 changes: 22 additions & 2 deletions lib/loading/cubit/loading_cubit.dart
@@ -1,7 +1,11 @@
import 'dart:io';

import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../logs/logs.dart';
import '../../native_platform/native_platform.dart';
import '../../native_platform/src/linux/linux.dart';

part 'loading_state.dart';

Expand All @@ -10,13 +14,29 @@ class LoadingCubit extends Cubit<LoadingState> {

LoadingCubit()
: nativePlatform = NativePlatform(),
super(LoadingInitial()) {
super(const LoadingInitial()) {
checkDependencies();
}

Future<void> checkDependencies() async {
log.v('Checking dependencies..');

// Make sure we are not running under Wayland.
if (Platform.isLinux) {
final sessionType = await (nativePlatform as Linux).sessionType();
if (sessionType != 'x11') {
emit(const LoadingWaylandError());
return;
}
}

final dependenciesSatisfied = await nativePlatform.checkDependencies();
final newState = dependenciesSatisfied ? LoadingSuccess() : LoadingFailed();

LoadingState newState;
newState = (dependenciesSatisfied) //
? const LoadingSuccess()
: const LoadingDependencyError();

emit(newState);
}
}
42 changes: 39 additions & 3 deletions lib/loading/cubit/loading_state.dart
Expand Up @@ -7,8 +7,44 @@ abstract class LoadingState extends Equatable {
List<Object> get props => [];
}

class LoadingInitial extends LoadingState {}
class LoadingInitial extends LoadingState {
const LoadingInitial();
}

class LoadingSuccess extends LoadingState {
const LoadingSuccess();
}

class LoadingError extends LoadingState {
final String errorMsg;

class LoadingSuccess extends LoadingState {}
const LoadingError({
required this.errorMsg,
});

@override
List<Object> get props => [errorMsg];
}

class LoadingFailed extends LoadingState {}
class LoadingDependencyError extends LoadingError {
const LoadingDependencyError()
: super(
errorMsg: '''
Dependency check failed.
Install the dependencies from your system's package manager:
- `xdotool`
- `wmctrl`''',
);
}

class LoadingWaylandError extends LoadingError {
const LoadingWaylandError()
: super(
errorMsg: '''
Wayland is not currently supported.
[Sign in using X11 instead](https://docs.fedoraproject.org/en-US/quick-docs/configuring-xorg-as-default-gnome-session/).''',
);
}
21 changes: 13 additions & 8 deletions lib/loading/loading_page.dart
Expand Up @@ -3,6 +3,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_markdown/flutter_markdown.dart';

import '../../apps_list/apps_list.dart';
import '../app/app.dart';
import '../logs/logs.dart';
import 'loading.dart';

/// Intermediate loading screen while verifying that Nyrna's dependencies are
Expand All @@ -26,18 +28,21 @@ class LoadingPage extends StatelessWidget {
}
},
builder: (context, state) {
if (state is LoadingFailed) {
if (state is LoadingError) {
return Card(
child: Container(
padding: const EdgeInsets.all(20.0),
child: const MarkdownBody(data: '''
Dependency check failed.
child: MarkdownBody(
data: state.errorMsg,
onTapLink: (text, href, title) {
if (href == null) {
log.e('Broken link: $href');
return;
}

Install the dependencies from your system's package manager:
- `xdotool`
- `wmctrl`
'''),
AppCubit.instance.launchURL(href);
},
),
),
);
} else {
Expand Down
9 changes: 9 additions & 0 deletions lib/native_platform/src/linux/linux.dart
@@ -1,3 +1,5 @@
import 'dart:io' as io;

import '../../../logs/logs.dart';
import '../native_platform.dart';
import '../process/models/process.dart';
Expand Down Expand Up @@ -169,6 +171,13 @@ Make sure these are installed on your host system.''',
return dependenciesAvailable;
}

/// Return is `x11` or `wayland` depending on which session type is running.
Future<String> sessionType() async {
final sessionType = io.Platform.environment['XDG_SESSION_TYPE'];
log.v('Current session type: $sessionType');
return sessionType!;
}

@override
Future<bool> minimizeWindow(int windowId) async {
log.v('Minimizing window with id $windowId');
Expand Down
21 changes: 7 additions & 14 deletions pubspec.lock
Expand Up @@ -409,7 +409,7 @@ packages:
name: mime
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
version: "1.0.4"
mocktail:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -542,7 +542,7 @@ packages:
name: path_provider_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.6"
version: "2.0.7"
path_provider_platform_interface:
dependency: transitive
description:
Expand Down Expand Up @@ -626,18 +626,18 @@ packages:
name: shared_preferences
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.15"
version: "2.0.16"
shared_preferences_android:
dependency: transitive
description:
name: shared_preferences_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.14"
shared_preferences_ios:
shared_preferences_foundation:
dependency: transitive
description:
name: shared_preferences_ios
name: shared_preferences_foundation
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
Expand All @@ -648,13 +648,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
shared_preferences_macos:
dependency: transitive
description:
name: shared_preferences_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
shared_preferences_platform_interface:
dependency: transitive
description:
Expand Down Expand Up @@ -897,7 +890,7 @@ packages:
name: web_socket_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
version: "2.3.0"
webdriver:
dependency: transitive
description:
Expand Down Expand Up @@ -948,7 +941,7 @@ packages:
name: xdg_directories
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0+2"
version: "0.2.0+3"
xml:
dependency: transitive
description:
Expand Down

0 comments on commit 901e4cc

Please sign in to comment.