Skip to content
This repository has been archived by the owner on Mar 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from drilonrecica/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
drilonrecica committed Feb 14, 2021
2 parents de6a5b0 + 48ca89f commit 2e23bbd
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 22 deletions.
26 changes: 20 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class MyApp extends StatelessWidget {
),
home: MyHomePage(title: 'Scrcpy++', box: box, initial: true),
routes: <String, WidgetBuilder>{
'/homepageAsInitial': (BuildContext context) =>
MyHomePage(title: 'Scrcpy++', box: box, initial: true),
'/homepageAsSetting': (BuildContext context) =>
MyHomePage(title: 'Scrcpy++', box: box, initial: false),
'/scrcpypage': (BuildContext context) => ScrcpyPage(),
Expand Down Expand Up @@ -86,11 +88,14 @@ class _MyHomePageState extends State<MyHomePage> {
});
}
} else {
widget.box.writeIfNull(MyApp.keyscrcpyPath, "/usr/local/bin/scrcpy");
scrcpyPath = widget.box.read(MyApp.keyscrcpyPath);
setState(() {
_scrcpyPathController.text = scrcpyPath;
});
if (Platform.isMacOS && widget.initial && firstPageLoad) {
widget.box.writeIfNull(MyApp.keyscrcpyPath, "/usr/local/bin/scrcpy");
scrcpyPath = widget.box.read(MyApp.keyscrcpyPath);
setState(() {
_scrcpyPathController.text = scrcpyPath;
firstPageLoad = false;
});
}
}

if (!widget.initial && firstPageLoad) {
Expand All @@ -106,7 +111,16 @@ class _MyHomePageState extends State<MyHomePage> {
}

return Scaffold(
appBar: AppBar(title: Text(widget.title), backgroundColor: Colors.indigo),
appBar: AppBar(
title: GestureDetector(
onDoubleTap: () {
widget.box.erase();
Future.delayed(Duration.zero, () {
Navigator.popAndPushNamed(context, '/homepageAsInitial');
});
},
child: Text(widget.title)),
backgroundColor: Colors.indigo),
body: Padding(
padding: const EdgeInsets.all(32.0),
child: Column(
Expand Down
69 changes: 53 additions & 16 deletions lib/scrcpy.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:get_storage/get_storage.dart';
import 'package:process_run/shell_run.dart';
Expand Down Expand Up @@ -51,9 +53,17 @@ class _ScrcpyPageState extends State<ScrcpyPage> {
title: Row(
children: [
Expanded(
child: Text(
"Scrcpy++",
textAlign: TextAlign.center,
child: GestureDetector(
onDoubleTap: () {
box.erase();
Future.delayed(Duration.zero, () {
Navigator.popAndPushNamed(context, '/homepageAsInitial');
});
},
child: Text(
"Scrcpy++",
textAlign: TextAlign.center,
),
),
),
GestureDetector(
Expand Down Expand Up @@ -105,8 +115,12 @@ class _ScrcpyPageState extends State<ScrcpyPage> {
children: [
Text(
"Rotation ",
style:
TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
decoration: Platform.isLinux
? TextDecoration.lineThrough
: TextDecoration.none),
),
Padding(
padding: const EdgeInsets.fromLTRB(8, 0, 0, 0),
Expand Down Expand Up @@ -285,7 +299,11 @@ class _ScrcpyPageState extends State<ScrcpyPage> {
child: Text(
"Stay awake",
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 16),
fontWeight: FontWeight.bold,
fontSize: 16,
decoration: Platform.isLinux
? TextDecoration.lineThrough
: TextDecoration.none),
),
),
],
Expand Down Expand Up @@ -313,7 +331,11 @@ class _ScrcpyPageState extends State<ScrcpyPage> {
child: Text(
"Disable Screensaver",
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 16),
fontWeight: FontWeight.bold,
fontSize: 16,
decoration: Platform.isLinux
? TextDecoration.lineThrough
: TextDecoration.none),
),
),
],
Expand Down Expand Up @@ -482,8 +504,12 @@ class _ScrcpyPageState extends State<ScrcpyPage> {
children: [
Text(
"Lock video orientation ___",
style:
TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
decoration: Platform.isLinux
? TextDecoration.lineThrough
: TextDecoration.none),
),
Padding(
padding: const EdgeInsets.fromLTRB(8, 0, 0, 0),
Expand Down Expand Up @@ -606,14 +632,20 @@ class _ScrcpyPageState extends State<ScrcpyPage> {
}

Future<void> _startScrcpy() async {
bool notLinux = !Platform.isLinux;

if (_titleController.text.isEmpty) {
_deviceTitle = "Android Device";
} else {
_deviceTitle = _titleController.text;
}

var scrcpyCommand =
"./scrcpy --window-title '$_deviceTitle' --rotation $_rotationValue --bit-rate $_bitrateValue";
"./scrcpy --window-title '$_deviceTitle' --bit-rate $_bitrateValue";

if (notLinux) {
scrcpyCommand = scrcpyCommand + " --rotation $_rotationValue";
}

if (_maxHeight != '0') {
scrcpyCommand = scrcpyCommand + " --max-size $_maxHeight";
Expand All @@ -635,19 +667,19 @@ class _ScrcpyPageState extends State<ScrcpyPage> {
scrcpyCommand = scrcpyCommand + " --show-touches";
}

if (_stayAwake) {
if (notLinux && _stayAwake) {
scrcpyCommand = scrcpyCommand + " --stay-awake";
}

if (_disableScreensaver) {
if (notLinux && _disableScreensaver) {
scrcpyCommand = scrcpyCommand + " --disable-screensaver";
}

if (_framerateValue != 0) {
scrcpyCommand = scrcpyCommand + " --max-fps $_framerateValue";
}

if (_videoOrientationValue != 0) {
if (notLinux && _videoOrientationValue != 0) {
scrcpyCommand =
scrcpyCommand + " --lock-video-orientation $_videoOrientationValue";
}
Expand All @@ -663,9 +695,14 @@ class _ScrcpyPageState extends State<ScrcpyPage> {
"adb": adbPath,
"ADB": adbPath
};
await Shell(
environment: environment, workingDirectory: "/usr/local/bin/")
.run("$tempScrcpyCommand");
Shell shell;
if (Platform.isMacOS) {
shell = Shell(
environment: environment, workingDirectory: "/usr/local/bin/");
} else {
shell = Shell(environment: environment);
}
await shell.run("$tempScrcpyCommand");
} on ShellException catch (_) {
// We might get a shell exception
}
Expand Down

0 comments on commit 2e23bbd

Please sign in to comment.