From 967fce65b05df3688cab0552568a289363958c7c Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Mon, 7 Jan 2019 16:23:01 +0100 Subject: [PATCH] Minor refactor --- lib/gitapp.dart | 88 +------------------------------------------- lib/storage/git.dart | 81 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 87 deletions(-) create mode 100644 lib/storage/git.dart diff --git a/lib/gitapp.dart b/lib/gitapp.dart index 443ac03c..c3794124 100644 --- a/lib/gitapp.dart +++ b/lib/gitapp.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; +import 'package:journal/storage/git.dart'; class GitApp extends StatelessWidget { @override @@ -46,89 +46,3 @@ buildGitButtons() { ), ]; } - -Future gitClone() async { - const platform = const MethodChannel('gitjournal.io/git'); - - print("Going to git clone"); - try { - await platform.invokeMethod('gitClone', { - 'cloneUrl': "root@bcn.vhanda.in:git/test", - 'folderName': "journal", - }); - print("Done"); - } on PlatformException catch (e) { - print("gitClone Failed: '${e.message}'."); - } -} - -Future generateSSHKeys() async { - print("generateSSHKeyss"); - try { - const platform = const MethodChannel('gitjournal.io/git'); - String publicKey = await platform.invokeMethod('generateSSHKeys', {}); - print("Public Key " + publicKey); - } on PlatformException catch (e) { - print("Failed to generateSSHKeys: '${e.message}'."); - } -} - -Future gitPull() async { - const platform = const MethodChannel('gitjournal.io/git'); - - print("Going to git pull"); - try { - await platform.invokeMethod('gitPull', { - 'folderName': "journal", - }); - print("Done"); - } on PlatformException catch (e) { - print("gitPull Failed: '${e.message}'."); - } -} - -Future gitAdd() async { - const platform = const MethodChannel('gitjournal.io/git'); - - print("Going to git add"); - try { - await platform.invokeMethod('gitAdd', { - 'folderName': "journal", - 'filePattern': ".", - }); - print("Done"); - } on PlatformException catch (e) { - print("gitAdd Failed: '${e.message}'."); - } -} - -Future gitPush() async { - const platform = const MethodChannel('gitjournal.io/git'); - - print("Going to git push"); - try { - await platform.invokeMethod('gitPush', { - 'folderName': "journal", - }); - print("Done"); - } on PlatformException catch (e) { - print("gitPush Failed: '${e.message}'."); - } -} - -Future gitCommit() async { - const platform = const MethodChannel('gitjournal.io/git'); - - print("Going to git commit"); - try { - await platform.invokeMethod('gitCommit', { - 'folderName': "journal", - 'authorName': "Vishesh Handa", - 'authorEmail': "noemail@example.com", - 'message': "Default message from GitJournal", - }); - print("Done"); - } on PlatformException catch (e) { - print("gitCommit Failed: '${e.message}'."); - } -} diff --git a/lib/storage/git.dart b/lib/storage/git.dart new file mode 100644 index 00000000..1bfaed89 --- /dev/null +++ b/lib/storage/git.dart @@ -0,0 +1,81 @@ +import 'dart:async'; +import 'dart:io'; + +import 'package:flutter/services.dart'; + +const platform = const MethodChannel('gitjournal.io/git'); + +Future gitClone() async { + print("Going to git clone"); + try { + await platform.invokeMethod('gitClone', { + 'cloneUrl': "root@bcn.vhanda.in:git/test", + 'folderName': "journal", + }); + print("Done"); + } on PlatformException catch (e) { + print("gitClone Failed: '${e.message}'."); + } +} + +Future generateSSHKeys() async { + print("generateSSHKeyss"); + try { + String publicKey = await platform.invokeMethod('generateSSHKeys', {}); + print("Public Key " + publicKey); + } on PlatformException catch (e) { + print("Failed to generateSSHKeys: '${e.message}'."); + } +} + +Future gitPull() async { + print("Going to git pull"); + try { + await platform.invokeMethod('gitPull', { + 'folderName': "journal", + }); + print("Done"); + } on PlatformException catch (e) { + print("gitPull Failed: '${e.message}'."); + } +} + +Future gitAdd() async { + print("Going to git add"); + try { + await platform.invokeMethod('gitAdd', { + 'folderName': "journal", + 'filePattern': ".", + }); + print("Done"); + } on PlatformException catch (e) { + print("gitAdd Failed: '${e.message}'."); + } +} + +Future gitPush() async { + print("Going to git push"); + try { + await platform.invokeMethod('gitPush', { + 'folderName': "journal", + }); + print("Done"); + } on PlatformException catch (e) { + print("gitPush Failed: '${e.message}'."); + } +} + +Future gitCommit() async { + print("Going to git commit"); + try { + await platform.invokeMethod('gitCommit', { + 'folderName': "journal", + 'authorName': "Vishesh Handa", + 'authorEmail': "noemail@example.com", + 'message': "Default message from GitJournal", + }); + print("Done"); + } on PlatformException catch (e) { + print("gitCommit Failed: '${e.message}'."); + } +}