From 1a070b2c41c74c5c1dabe3d06aca758f8010ae96 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Wed, 16 Jan 2019 18:14:07 +0100 Subject: [PATCH] OnBoarding: Launch the page for adding a deploy key I'd added BitBucket, but bitbucket sucks as it doesn't have any way to add an ssh key with write access. With Gitlab I couldn't link to the exact point in the page, but oh well. I'll try to file a bug with them. --- lib/screens/onboarding_screens.dart | 32 ++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/screens/onboarding_screens.dart b/lib/screens/onboarding_screens.dart index 533ba4a1..234fa5df 100644 --- a/lib/screens/onboarding_screens.dart +++ b/lib/screens/onboarding_screens.dart @@ -30,6 +30,8 @@ class OnBoardingScreenState extends State { var _pageInputUrlDone = false; var _pageSshKeyDone = false; + var _gitCloneUrl = ""; + var pageController = PageController(); final GlobalKey _scaffoldKey = new GlobalKey(); @@ -106,6 +108,9 @@ class OnBoardingScreenState extends State { ); SharedPreferences.getInstance().then((SharedPreferences pref) { + // We aren't calling setState as this isn't being used for rendering + _gitCloneUrl = sshUrl; + pref.setString("sshCloneUrl", sshUrl); this._generateSshKey(); }); @@ -200,7 +205,6 @@ class OnBoardingScreenState extends State { void _generateSshKey() { generateSSHKeys(comment: "GitJournal").then((String _publicKey) { setState(() { - print("Changing the state"); publicKey = _publicKey; Clipboard.setData(ClipboardData(text: publicKey)); @@ -209,9 +213,35 @@ class OnBoardingScreenState extends State { ._scaffoldKey .currentState .showSnackBar(new SnackBar(content: new Text(text))); + + _launchDeployKeyPage(); }); }); } + + void _launchDeployKeyPage() async { + var lastIndex = _gitCloneUrl.lastIndexOf(".git"); + if (lastIndex == -1) { + lastIndex = _gitCloneUrl.length; + } + + var repoName = + _gitCloneUrl.substring(_gitCloneUrl.lastIndexOf(":"), lastIndex); + + final gitHubUrl = 'https://github.com/' + repoName + '/settings/keys/new'; + final gitLabUrl = 'https://gitlab.com/' + repoName + '/settings/repository'; + + try { + if (_gitCloneUrl.startsWith("git@github.com:")) { + await launch(gitHubUrl); + } else if (_gitCloneUrl.startsWith("git@gitlab.com:")) { + await launch(gitLabUrl); + } + } catch (err, stack) { + print('_launchDeployKeyPage: ' + err.toString()); + print(stack.toString()); + } + } } class OnBoardingInitialChoice extends StatelessWidget {