Skip to content

Instantly share code, notes, and snippets.

@gaurave
Created October 8, 2013 23:16
Show Gist options
  • Save gaurave/6893461 to your computer and use it in GitHub Desktop.
Save gaurave/6893461 to your computer and use it in GitHub Desktop.
library git;
import 'dart:async';
import 'dart:html';
import 'dart:js';
import 'package:chrome/app.dart' as chrome;
import 'package:js/js.dart' as js;
import 'lib/utils.dart';
class GitResult {
var foo;
GitResult.fromData(this.foo);
}
class Git {
static final _jsContext = js.context;
static final JsObject _jsgit = context['GitApi'];
var fs;
Git() {
print("hello in this new world.");
_jsContext.console.log(_jsgit);
this.getFilesystem();
}
void requestFileSystemCallback(fs) {
this.fs = fs;
vlog(fs);
fs.root.createDirectory("grv")
.then(this.abc, onError: this.handleError);
}
void abc(entry) {
print('abc');
this.clone(entry);
}
void handleError(e) {
vlog(e);
print('error in getting filesystem.');
}
void getFilesystem() {
window.requestFileSystem(2*1024*1024, persistent: false)
.then(this.requestFileSystemCallback, onError: this.handleError);
}
void cloneSuccess() {
print('clone successful');
}
void cloneFailed() {
print('clone failed');
}
void vlog(obj) {
window.console.log(obj);
}
void cloneProgress(info) {
js.context.console.log("nothing");
js.context.console.log(info);
}
Future<GitResult> clone(DirectoryEntry entry) {
Completer<GitResult> completer = new Completer();
var source ="http://github.com/gaurave/trep.git";
var options = js.map({
'dir': entry,
'url': source,
'depth': 1,
'progress': this.cloneProgress
});
var successCallback = (someData) {
print('inside success.');
completer.complete(new GitResult.fromData(someData));
};
var errorCallback = (String message) {
print('inside error');
completer.complete(new GitResult.fromData(message));
};
js.context.console.log(js.context.GitApi);
print('just before');
JsObject jsgit = context['GitApi'];
//jsgit.callMethod('clone',[options, successCallback, errorCallback]);
//var callbackSuccess = new js.Callback.once(this.cloneSuccess);
//var callbackFailed = new js.Callback.once(this.cloneFailed);
//_jsgit.callMethod("clone", [options, callbackSuccess, callbackFailed]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment