Skip to content

Commit

Permalink
Merge pull request #55 from leoafarias/fix/crash-on-process
Browse files Browse the repository at this point in the history
Fix/crash on process
  • Loading branch information
leoafarias authored Apr 26, 2021
2 parents 5bc82f7 + 476e29b commit 6b99ebc
Show file tree
Hide file tree
Showing 20 changed files with 171 additions and 39 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ jobs:
- name: Enable desktop
run: flutter config --enable-linux-desktop

- name: Analyze Flutter
- name: Get packages
run: flutter pub get

- name: Analyze
run: flutter analyze

- name: Flutter build app
run: flutter build linux
build-macos:
Expand All @@ -48,9 +51,12 @@ jobs:
- name: Enable desktop
run: flutter config --enable-macos-desktop

- name: Analyze Flutter
- name: Get packages
run: flutter pub get

- name: Analyze
run: flutter analyze

- name: Flutter build app
run: flutter build macos

Expand All @@ -69,8 +75,11 @@ jobs:
- name: Enable desktop
run: flutter config --enable-windows-desktop

- name: Analyze Flutter
- name: Get packages
run: flutter pub get

- name: Analyze
run: flutter analyze

- name: Flutter build app
run: flutter build windows
5 changes: 4 additions & 1 deletion lib/components/atoms/console.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ class Console extends HookWidget {
right: 0,
child: Row(
children: [
const SpinKitFadingFour(color: Colors.cyan, size: 15),
SpinKitFadingFour(
color: Theme.of(context).accentColor,
size: 15,
),
IconButton(
onPressed: null,
icon: expand
Expand Down
2 changes: 1 addition & 1 deletion lib/components/atoms/typography.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class StdoutText extends StatelessWidget {
maxLines: 1,
style: GoogleFonts.ibmPlexMono().copyWith(
fontSize: 12,
color: Colors.cyan,
color: Theme.of(context).accentColor,
),
);
}
Expand Down
14 changes: 4 additions & 10 deletions lib/components/molecules/update_available_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,10 @@ class UpdateAvailableButton extends HookWidget {
Heading("Update available."),
],
),
content: Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Paragraph(
"Current ${latest.value.currentVersion}\n"
"New ${latest.value.latestVersion}",
),
],
content: Container(
child: Paragraph(
"Current ${latest.value.currentVersion}\n"
"New ${latest.value.latestVersion}",
),
),
actions: <Widget>[
Expand Down
7 changes: 5 additions & 2 deletions lib/components/organisms/terminal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:sidekick/components/atoms/typography.dart';
import 'package:sidekick/dto/release.dto.dart';
import 'package:sidekick/providers/terminal_provider.dart';
import 'package:sidekick/providers/shell_provider.dart';
import 'package:sidekick/utils/notify.dart';

class PlaygroundTerminal extends HookWidget {
Expand Down Expand Up @@ -169,7 +169,10 @@ class PlaygroundTerminal extends HookWidget {
),
),
terminalState.processing
? const SpinKitFadingFour(color: Colors.cyan, size: 15)
? SpinKitFadingFour(
color: Theme.of(context).accentColor,
size: 15,
)
: Container()
],
),
Expand Down
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ void main() async {
setWindowMinSize(const Size(800, 500));
setWindowMaxSize(Size.infinite);
}

runApp(ProviderScope(child: FvmApp()));
}

Expand Down
5 changes: 0 additions & 5 deletions lib/providers/flutter_releases.provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ class AppReleasesState {

/// Returns all releases and channels that are cached
List<ReleaseDto> get allCached {
// final versionNames = all.map((version) => version.name).toSet();
// final _allCached = all.where((release) => release.isCached).toList();
// _allCached.retainWhere((version) => versionNames.remove(version.name));

// Only get unique cached releases
// Some releases replicate across channels
// They can only be installed once and conflict
Expand All @@ -53,7 +49,6 @@ final _fetchFlutterReleases = FutureProvider<FlutterReleases>(
(_) => FVMClient.getFlutterReleases(),
);

// ignore: top_level_function_literal_block
final releasesStateProvider = Provider<AppReleasesState>((ref) {
// Filter only version that are valid releases
FlutterReleases payload;
Expand Down
2 changes: 1 addition & 1 deletion lib/providers/packages.provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ final packagesProvider = FutureProvider((ref) async {
return json.map((value) => PackageDetail.fromJson(value)).toList();
} else {
// Get dependencies
final googleDeps = await getGooglePackages();
for (final project in projects.list) {
final pubspec = project.pubspec;
final deps = pubspec.dependencies;

for (final dep in deps.keys) {
// Get google deps
final googleDeps = await getGooglePackages();

if (deps[dep] is HostedDependency &&
googleDeps.contains(dep) == false) {
Expand Down
5 changes: 3 additions & 2 deletions lib/providers/settings.provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:fvm/fvm.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:sidekick/dto/settings.dto.dart';
import 'package:sidekick/providers/projects_provider.dart';
import 'package:sidekick/services/flutter_config_service.dart';
import 'package:sidekick/services/settings_service.dart';
import 'package:state_notifier/state_notifier.dart';

Expand Down Expand Up @@ -76,7 +77,7 @@ class SettingsProvider extends StateNotifier<Settings> {
// Return if nothing changed
if (changed) {
// Toggle analytics
await FVMClient.setFlutterConfig(settings.toMap());
await FlutterConfigService.setFluterConfig(settings.toMap());
}
}

Expand All @@ -96,7 +97,7 @@ class SettingsProvider extends StateNotifier<Settings> {

//Go get async state
final fvmSettings = await FVMClient.readSettings();
final flutterSettings = await FVMClient.getFlutterConfig();
final flutterSettings = await FlutterConfigService.getFlutterConfig();
state = Settings(
// Set state
sidekick: sidekickSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ class TerminalStateNotifier extends StateNotifier<TerminalState> {
);
}

/// Send command isolate
Future<void> sendIsolate(
String cmd,
ReleaseDto release,
Project project, {

/// Supress display command on terminal
// Supress display command on terminal
bool supressCmdOutput = false,
}) async {
try {
Expand Down Expand Up @@ -212,7 +212,7 @@ class TerminalStateNotifier extends StateNotifier<TerminalState> {
// Receiver port for isolate
final receivePort = ReceivePort();
// Create model of Terminal Cmd to send to isolate
final terminalCmd = TerminalCmd(
final terminalCmd = ProcessCmd(
execPath: execPath,
workingDirectory: project.projectDir.path,
args: args,
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/playground_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:sidekick/components/atoms/typography.dart';
import 'package:sidekick/components/organisms/terminal.dart';
import 'package:sidekick/dto/release.dto.dart';
import 'package:sidekick/providers/flutter_releases.provider.dart';
import 'package:sidekick/providers/terminal_provider.dart';
import 'package:sidekick/providers/shell_provider.dart';

class PlaygroundScreen extends HookWidget {
final Project project;
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class SettingsScreen extends HookWidget {
return ListTile(
leading: Icon(
sectionIcons[idx],
size: 16,
size: 20,
),
title: Text(
section,
Expand Down
88 changes: 88 additions & 0 deletions lib/services/flutter_config_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import 'dart:io';

import 'package:fvm/fvm.dart';
import 'package:sidekick/utils/helpers.dart';

class FlutterConfigService {
FlutterConfigService._();

/// Runs a simple Flutter cmd
static Future<String> _runCmd(
List<String> args,
) async {
// Get exec path for flutter
final globalVersion = await FVMClient.getGlobal();

if (globalVersion == null) {
throw Exception(
'Can only check flutter settings with a global version configured',
);
}

final result = await Process.run(globalVersion.flutterExec, args);

if (result.exitCode == 0) {
return result.stdout as String;
} else {
return result.stderr as String;
}
}

/// Sets Flutter config
static Future<void> setFluterConfig(Map<String, bool> config) async {
final analytics =
config['analytics'] == true ? '--analytics' : '--no-analytics';
final web = config['web'] == true ? '--enable-web' : '--no-enable-web';
final macos = config['macos'] == true
? '--enable-macos-desktop'
: '--no-enable-macos-desktop';
final windows = config['windows'] == true
? '--enable-windows-desktop'
: '--no-enable-windows-desktop';
final linux = config['linux'] == true
? '--enable-linux-desktop'
: '--no-enable-linux-desktop';

await _runCmd([
'config',
analytics,
macos,
windows,
linux,
web,
]);
}

/// Returns configured Flutter settings
static Future<Map<String, bool>> getFlutterConfig() async {
final result = await _runCmd(['config']);
final analytics = containsIgnoringWhitespace(
result,
'Analytics reporting is currently enabled',
);
final macos = containsIgnoringWhitespace(
result,
'enable-macos-desktop: true',
);
final windows = containsIgnoringWhitespace(
result,
'enable-windows-desktop: true',
);
final linux = containsIgnoringWhitespace(
result,
'enable-linux-desktop: true',
);
final web = containsIgnoringWhitespace(
result,
'enable-web: true',
);

return {
'analytics': analytics,
'macos': macos,
'windows': windows,
'linux': linux,
'web': web,
};
}
}
1 change: 1 addition & 0 deletions lib/services/settings_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:sidekick/dto/settings.dto.dart';

// ignore: avoid_classes_with_only_static_members
class SettingsService {
SettingsService._();
static const key = 'settings_box';
static Box<SidekickSettings> box;

Expand Down
3 changes: 2 additions & 1 deletion lib/utils/dependencies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Future<List<PackageDetail>> fetchPackages(
pkgFutures.add(client.packageInfo(pkg));
}

final packages = await Future.wait(pkgFutures);
final packages = await Future.wait(pkgFutures, eagerError: true);

final topPackages = _getTopValidPackages(packages, packagesCount);
final results = await _complementPackageInfo(topPackages, packagesCount);

Expand Down
29 changes: 29 additions & 0 deletions lib/utils/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,32 @@ Future<Directory> getSidekickTempDir({

return tempDir;
}

/// Checks if string contains
bool containsIgnoringWhitespace(String source, String toSearch) {
return collapseWhitespace(source).contains(collapseWhitespace(toSearch));
}

/// Utility function to collapse whitespace runs to single spaces
/// and strip leading/trailing whitespace.
/// taken from matcher
String collapseWhitespace(String string) {
var result = StringBuffer();
var skipSpace = true;
for (var i = 0; i < string.length; i++) {
var character = string[i];
if (_isWhitespace(character)) {
if (!skipSpace) {
result.write(' ');
skipSpace = true;
}
} else {
result.write(character);
skipSpace = false;
}
}
return result.toString().trim();
}

bool _isWhitespace(String ch) =>
ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
8 changes: 4 additions & 4 deletions lib/utils/terminal_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ import 'dart:convert';
import 'dart:io';
import 'dart:isolate';

import 'package:sidekick/providers/terminal_provider.dart';
import 'package:sidekick/providers/shell_provider.dart';

class TerminalCmd {
class ProcessCmd {
final List<String> args;
final String execPath;
final String workingDirectory;
final SendPort sendPort;
TerminalCmd({
ProcessCmd({
this.args,
this.execPath,
this.workingDirectory,
this.sendPort,
});
}

Future<void> isolateProcess(TerminalCmd cmd) async {
Future<void> isolateProcess(ProcessCmd cmd) async {
try {
final process = await Process.start(
cmd.execPath,
Expand Down
7 changes: 7 additions & 0 deletions macos/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ class AppDelegate: FlutterAppDelegate {
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
}

// TODO: Added this due to the following issue
// https://github.com/tekartik/process_run.dart/issues/36#issuecomment-770226249
// Once this is addressed it can be removed
override func applicationDidBecomeActive(_ notification: Notification) {
signal(SIGPIPE, SIG_IGN) //Ignore signal
}
}
Loading

0 comments on commit 6b99ebc

Please sign in to comment.