GitSetup SSH: Make the 2nd instruction different for custom provider

This commit is contained in:
Vishesh Handa
2019-02-14 01:02:20 +01:00
parent 28fcc65772
commit c9ddf67e46
2 changed files with 104 additions and 81 deletions

@ -44,7 +44,6 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
String gitCloneErrorMessage = "";
String publicKey = "";
bool _canLaunchDeployKeyPage = false;
var pageController = PageController();
int _currentPageIndex = 0;
@ -114,7 +113,7 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
if (pos == 2) {
if (_pageChoice[0] == PageChoice0.CustomProvider) {
return GitHostSetupSshKey(
return GitHostSetupSshKeyUnknownProvider(
doneFunction: () {
setState(() {
_pageCount = pos + 2;
@ -124,8 +123,6 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
},
publicKey: publicKey,
copyKeyFunction: _copyKeyToClipboard,
openDeployKeyPage: _launchDeployKeyPage,
canOpenDeployKeyPage: _canLaunchDeployKeyPage,
);
}
@ -169,7 +166,7 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
if (_pageChoice[1] == PageChoice1.Manual) {
// FIXME: Create a new page with better instructions
return GitHostSetupSshKey(
return GitHostSetupSshKeyKnownProvider(
doneFunction: () {
setState(() {
_pageCount = 6;
@ -181,7 +178,6 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
publicKey: publicKey,
copyKeyFunction: _copyKeyToClipboard,
openDeployKeyPage: _launchDeployKeyPage,
canOpenDeployKeyPage: _canLaunchDeployKeyPage,
);
} else if (_pageChoice[1] == PageChoice1.Auto) {
return GitHostSetupGitClone(errorMessage: gitCloneErrorMessage);
@ -290,10 +286,6 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
generateSSHKeys(comment: "GitJournal").then((String publicKey) {
setState(() {
this.publicKey = publicKey;
this._canLaunchDeployKeyPage =
_gitCloneUrl.startsWith("git@github.com:") ||
_gitCloneUrl.startsWith("git@gitlab.com:");
_copyKeyToClipboard();
});
});
@ -308,6 +300,12 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
}
void _launchDeployKeyPage() async {
var canLaunch = _gitCloneUrl.startsWith("git@github.com:") ||
_gitCloneUrl.startsWith("git@gitlab.com:");
if (!canLaunch) {
return;
}
var lastIndex = _gitCloneUrl.lastIndexOf(".git");
if (lastIndex == -1) {
lastIndex = _gitCloneUrl.length;

@ -3,20 +3,18 @@ import 'package:flutter/material.dart';
import 'githostsetup_button.dart';
import 'githostsetup_loading.dart';
class GitHostSetupSshKey extends StatelessWidget {
class GitHostSetupSshKeyKnownProvider extends StatelessWidget {
final Function doneFunction;
final Function copyKeyFunction;
final String publicKey;
final Function openDeployKeyPage;
final bool canOpenDeployKeyPage;
GitHostSetupSshKey({
GitHostSetupSshKeyKnownProvider({
@required this.doneFunction,
@required this.copyKeyFunction,
@required this.openDeployKeyPage,
@required this.publicKey,
@required this.canOpenDeployKeyPage,
});
@override
@ -25,25 +23,6 @@ class GitHostSetupSshKey extends StatelessWidget {
return GitHostSetupLoadingPage("Generating SSH Key ...");
}
var publicKeyWidget = SizedBox(
width: double.infinity,
height: 160.0,
child: Container(
color: Theme.of(context).buttonColor,
child: SingleChildScrollView(
child: Container(
padding: const EdgeInsets.all(8.0),
child: Text(
publicKey,
textAlign: TextAlign.left,
maxLines: null,
style: Theme.of(context).textTheme.body1,
),
),
),
),
);
var columns = Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
@ -60,7 +39,7 @@ class GitHostSetupSshKey extends StatelessWidget {
style: Theme.of(context).textTheme.subtitle,
),
SizedBox(height: 8.0),
publicKeyWidget,
PublicKeyWidget(publicKey),
SizedBox(height: 8.0),
GitHostSetupButton(
text: "Copy Key",
@ -101,52 +80,98 @@ class GitHostSetupSshKey extends StatelessWidget {
}
}
/*
Widget copyAndDepoyWidget;
Widget cloneButton;
if (this.publicKey.isEmpty) {
copyAndDepoyWidget = Container();
cloneButton = Container();
} else {
cloneButton = GitHostSetupButton(
text: "Clone Repo",
onPressed: this.doneFunction,
);
class GitHostSetupSshKeyUnknownProvider extends StatelessWidget {
final Function doneFunction;
final Function copyKeyFunction;
final String publicKey;
if (canOpenDeployKeyPage) {
copyAndDepoyWidget = Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: RaisedButton(
child: Text(
"Copy Key",
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.button,
),
color: Theme.of(context).primaryColor,
onPressed: copyKeyFunction,
),
),
SizedBox(width: 8.0),
Expanded(
child: RaisedButton(
child: Text(
"Open Deploy Key Webpage",
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.button,
),
color: Theme.of(context).primaryColor,
onPressed: openDeployKeyPage,
),
),
],
);
} else {
copyAndDepoyWidget = GitHostSetupButton(
text: "Copy Key",
onPressed: this.copyKeyFunction,
);
}
GitHostSetupSshKeyUnknownProvider({
@required this.doneFunction,
@required this.copyKeyFunction,
@required this.publicKey,
});
@override
Widget build(BuildContext context) {
if (this.publicKey == null || this.publicKey.isEmpty) {
return GitHostSetupLoadingPage("Generating SSH Key ...");
}
*/
var columns = Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'In order to access this repository, this public key must be copied as a deploy key',
style: Theme.of(context).textTheme.title,
),
SizedBox(height: 32.0),
// Step 1
Text(
'1. Copy the key',
style: Theme.of(context).textTheme.subtitle,
),
SizedBox(height: 8.0),
PublicKeyWidget(publicKey),
SizedBox(height: 8.0),
GitHostSetupButton(
text: "Copy Key",
onPressed: copyKeyFunction,
),
SizedBox(height: 16.0),
// Step 2
Text(
'2. Give this SSH Key access to the git repo. (You need to figure it out yourself)',
style: Theme.of(context).textTheme.subtitle,
),
SizedBox(height: 16.0),
// Step 3
Text(
'3. Try Cloning ..',
style: Theme.of(context).textTheme.subtitle,
),
SizedBox(height: 8.0),
GitHostSetupButton(
text: "Clone Repo",
onPressed: this.doneFunction,
),
],
);
return Center(
child: SingleChildScrollView(
child: columns,
),
);
}
}
class PublicKeyWidget extends StatelessWidget {
final String publicKey;
PublicKeyWidget(this.publicKey);
@override
Widget build(BuildContext context) {
return SizedBox(
width: double.infinity,
height: 160.0,
child: Container(
color: Theme.of(context).buttonColor,
child: SingleChildScrollView(
child: Container(
padding: const EdgeInsets.all(8.0),
child: Text(
publicKey,
textAlign: TextAlign.left,
maxLines: null,
style: Theme.of(context).textTheme.body1,
),
),
),
),
);
}
}