Skip to content

update the dependency 'jqPlot' and add push file page #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"angular-route": "~1.2.16",
"angular-sanitize": "~1.2.16",
"bootstrap": "~3.0.2",
"jqplot": "*"
"jqPlot": "*"
},
"description": "Chrome ADB(Android Debug Bridge) Client",
"homepage": "https://github.com/importre/chromeadb",
Expand Down
11 changes: 7 additions & 4 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<script src="scripts/controllers.js"></script>

<link href="bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="bower_components/jqplot/jquery.jqplot.min.css" rel="stylesheet">
<link href="bower_components/jqPlot/src/jquery.jqplot.css" rel="stylesheet">
<link href="styles/chromeadb.css" rel="stylesheet">
</head>

Expand Down Expand Up @@ -136,6 +136,9 @@ <h3 class="panel-title">
<a href="#packages" data-toggle="tab"
ng-click="loadPackages(devInfo.serial);">Packages</a>
</li>
<li>
<a href="#pushfile" data-toggle="tab">Push File</a>
</li>
<li>
<a href="#controller" data-toggle="tab"
ng-click="initMousePad(devInfo.serial);">Controller</a>
Expand Down Expand Up @@ -208,9 +211,9 @@ <h4 class="modal-title" id="alertLabel">{{ tempPkgCmd.packageName }}</h4>
</div>

<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/jqplot/jquery.jqplot.min.js"></script>
<script src="bower_components/jqplot/plugins/jqplot.canvasTextRenderer.min.js"></script>
<script src="bower_components/jqplot/plugins/jqplot.canvasAxisLabelRenderer.min.js"></script>
<script src="bower_components/jqPlot/src/jquery.jqplot.js"></script>
<script src="bower_components/jqPlot/src/plugins/jqplot.canvasTextRenderer.js"></script>
<script src="bower_components/jqPlot/src/plugins/jqplot.canvasAxisLabelRenderer.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>

</body>
Expand Down
3 changes: 3 additions & 0 deletions src/scripts/chromeadb.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ adb.config(function ($routeProvider) {
.when('/packages', {
templateUrl: chrome.runtime.getURL('../views/packages.html')
})
.when('/pushfile', {
templateUrl: chrome.runtime.getURL('../views/pushfile.html')
})
.when('/controller', {
templateUrl: chrome.runtime.getURL('../views/controller.html')
})
Expand Down
126 changes: 124 additions & 2 deletions src/scripts/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,26 @@ adb.controller('controller', ['$scope', '$q', 'socketService', '$sce', function
});
};

$scope.pushFile = function (serial, fileEntry, filePath) {
$scope.pushFile = function (serial, fileEntry, filePath, targetPath) {
fileEntry.file(function (file) {
var reader = new FileReader();
reader.onerror = function (e) {
$scope.logMessage = {
cmd: 'File Error',
res: e.target.error.message
};
$scope.$apply();
};
reader.onloadend = function (e) {
if (!e.target.error) {
$scope.pushFileCommandsWithTargetPath(e, serial, filePath, targetPath);
}
};
reader.readAsArrayBuffer(file);
});
};

$scope.pushFileAndInstall = function (serial, fileEntry, filePath) {
fileEntry.file(function (file) {
var reader = new FileReader();
reader.onerror = function (e) {
Expand All @@ -259,6 +278,92 @@ adb.controller('controller', ['$scope', '$q', 'socketService', '$sce', function
});
};

$scope.pushFileCommandsWithTargetPath = function (e, serial, filePath, targetPath) {
var fileName = filePath.replace(/^.*[\\\/]/, '');
var cmd1 = 'host:transport:' + serial;
var cmd2 = 'sync:';
var sendCmd1 = 'SEND';
var targetFilePath = targetPath + '/' + fileName;
var sendCmd3 = targetFilePath + ',33206';
var sendCmd2 = integerToArrayBuffer(sendCmd3.length);
var dataCmd1 = 'DATA';
var doneCmd = 'DONE';

$scope.logMessage = {
cmd: 'Push File',
res: 'Pushing...'
};

$scope.getNewCommandPromise(cmd1)
.then(function (param) {
if (param.data === 'OKAY') {
return $scope.getCommandPromise(cmd2, param.createInfo);
}
})
.then(function (param) {
if (param.data === 'OKAY') {
return socketService.write(param.createInfo, sendCmd1);
}
})
.then(function (param) {
return socketService.writeBytes(param.createInfo, sendCmd2.buffer);
})
.then(function (param) {
return socketService.write(param.createInfo, sendCmd3);
})
.then(function (param) {
var defer = $q.defer();
var promise = defer.promise;
var file = e.target.result;
var maxChunkSize = 64 * 1024;
var chunkFunc = function (i, chunkSize) {
var fileSlice = file.slice(i, i + chunkSize);
promise = promise.then(function (param) {
return socketService.write(param.createInfo, dataCmd1);
})
.then(function (param) {
var chunkSizeInBytes = integerToArrayBuffer(chunkSize);
return socketService.writeBytes(param.createInfo, chunkSizeInBytes.buffer);
})
.then(function (param) {
return socketService.writeBytes(param.createInfo, fileSlice);
});
};

for (var i = 0; i < file.byteLength; i += maxChunkSize) {
var chunkSize = maxChunkSize;
//check if on last chunk
if (i + maxChunkSize > file.byteLength) {
chunkSize = file.byteLength - i;
}
chunkFunc(i, chunkSize);
}

promise.then(function (param) {
return socketService.write(param.createInfo, doneCmd);
})
.then(function (param) {
return socketService.write(param.createInfo, integerToArrayBuffer(0));
});
defer.resolve(param);

return promise;
})
.then(() => {
$scope.logMessage = {
cmd: 'Push File',
res: `Push to ${targetFilePath} successfully.`
};
})
.catch(function (param) {
$scope.initVariables();
$scope.logMessage = {
cmd: 'Connection Error',
res: 'Cannot find any devices'
};
});
};

$scope.pushFileCommands = function (e, serial, filePath) {
var fileName = filePath.replace(/^.*[\\\/]/, '');
var cmd1 = 'host:transport:' + serial;
Expand Down Expand Up @@ -576,7 +681,24 @@ adb.controller('controller', ['$scope', '$q', 'socketService', '$sce', function
$scope.chooseAndInstallPackage = function () {
chrome.fileSystem.chooseEntry({'type': 'openFile'}, function (entry, fileEntries) {
chrome.fileSystem.getDisplayPath(entry, function (displayPath) {
$scope.pushFile($scope.devInfo.serial, entry, displayPath);
$scope.pushFileAndInstall($scope.devInfo.serial, entry, displayPath);
});
});
};

$scope.chooseAndPushFile = function () {
const pushFilePath = document.getElementById('push-file-path').value;
console.log(pushFilePath);
if (pushFilePath === '') {
$scope.logMessage = {
cmd: 'Push File',
res: 'Please input a file path on the device.'
};
return;
}
chrome.fileSystem.chooseEntry({'type': 'openFile'}, function (entry, fileEntries) {
chrome.fileSystem.getDisplayPath(entry, function (displayPath) {
$scope.pushFile($scope.devInfo.serial, entry, displayPath, pushFilePath);
});
});
};
Expand Down
13 changes: 13 additions & 0 deletions src/styles/chromeadb.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,28 @@ tr > td.active {
width: 150px !important;
}

.push-file-button {
width: 150px !important;
}

div .search-packages {
float: right;
width: 80%;
}

div .search-files {
float: right;
width: 80%;
}

div .install-package {
float: left;
}

div .push-file {
float: left;
}

.navbar-brand {
padding: 0 0 0 15px;
}
Expand Down
17 changes: 17 additions & 0 deletions src/views/pushfile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!--pushfile tab-->

<div class="tab-pane" id="pushfile">
<div>
<div class="search-files">
<input id="push-file-path" class="form-control" type="search" ng-model="packageQuery"
placeholder="Search files">
</div>
<div class="push-file">
<button class="btn btn-primary push-file-button"
ng-click="chooseAndPushFile();">
Push File
</button>
</div>
</div>
</div>