1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 10:19:30 +02:00

add filesystem(file explorer) support, done

This commit is contained in:
hzsunshx 2015-09-22 17:16:46 +08:00
parent b258837757
commit 1dccda5e2a
11 changed files with 174 additions and 74 deletions

View file

@ -65,68 +65,22 @@ module.exports = syrup.serial()
}) })
}) })
return plugin; router.on(wire.FileSystemListMessage, function(channel, message){
var reply = wireutil.reply(options.serial)
adb.readdir(options.serial, message.dir)
.then(function(files){
// function projectionFormat() { push.send([
// return util.format( channel,
// '%dx%d@%dx%d/%d' reply.okay('success', files)
// , display.properties.width ])
// , display.properties.height })
// , display.properties.width .catch(function(err){
// , display.properties.height log.error('Dir list %s failed\n%s', message.dir, err.stack)
// , display.properties.rotation push.send([
// ) channel,
// } reply.fail(err.message)
])
// plugin.capture = function() { })
// log.info('Capturing screenshot') })
return plugin;
// var file = util.format('/data/local/tmp/minicap_%d.jpg', Date.now())
// return minicap.run(util.format(
// '-P %s -s >%s', projectionFormat(), file))
// .then(adbkit.util.readAll)
// .then(function() {
// return adb.stat(options.serial, file)
// })
// .then(function(stats) {
// if (stats.size === 0) {
// throw new Error('Empty screenshot; possibly secure screen?')
// }
// return adb.pull(options.serial, file)
// .then(function(transfer) {
// return storage.store('image', transfer, {
// filename: util.format('%s.jpg', options.serial)
// , contentType: 'image/jpeg'
// , knownLength: stats.size
// })
// })
// })
// .finally(function() {
// return adb.shell(options.serial, ['rm', '-f', file])
// .then(adbkit.util.readAll)
// })
// }
// router.on(wire.ScreenCaptureMessage, function(channel) {
// var reply = wireutil.reply(options.serial)
// plugin.capture()
// .then(function(file) {
// push.send([
// channel
// , reply.okay('success', file)
// ])
// })
// .catch(function(err) {
// log.error('Screen capture failed', err.stack)
// push.send([
// channel
// , reply.fail(err.message)
// ])
// })
// })
// return plugin
}) })

View file

@ -836,6 +836,16 @@ module.exports = function(options) {
) )
]) ])
}) })
.on('fs.list', function(channel, responseChannel, data){
joinChannel(responseChannel)
push.send([
channel
, wireutil.transaction(
responseChannel
, new wire.FileSystemListMessage(data)
)
])
})
}) })
.finally(function() { .finally(function() {
// Clean up all listeners and subscriptions // Clean up all listeners and subscriptions

View file

@ -72,23 +72,12 @@ enum MessageType {
AccountRemoveMessage = 55; AccountRemoveMessage = 55;
SdStatusMessage = 61; SdStatusMessage = 61;
ReverseForwardsEvent = 72; ReverseForwardsEvent = 72;
FileSystemListEvent = 80;
FileSystemListMessage = 81; FileSystemListMessage = 81;
FileSystemGetMessage = 82; FileSystemGetMessage = 82;
} }
message FileSystemListEvent {
required string serial = 1;
required string dir = 2;
}
message FileSystemListMessage { message FileSystemListMessage {
required string dir = 1; required string dir = 1;
repeated FileSystemProperty files = 2;
}
message FileSystemProperty {
required string name = 1;
required string mod = 2;
} }
message FileSystemGetMessage { message FileSystemGetMessage {

View file

@ -231,6 +231,12 @@ module.exports = function ControlServiceFactory(
}) })
} }
this.fslist = function(dir){
return sendTwoWay('fs.list', {
dir: dir,
})
}
this.checkAccount = function(type, account) { this.checkAccount = function(type, account) {
return sendTwoWay('account.check', { return sendTwoWay('account.check', {
type: type type: type

View file

@ -22,6 +22,12 @@ module.exports =
templateUrl: 'control-panes/advanced/advanced.jade', templateUrl: 'control-panes/advanced/advanced.jade',
filters: ['native', 'web'] filters: ['native', 'web']
}, },
{
title: gettext('FileSystem'),
icon: 'fa-info color-orange',
templateUrl: 'control-panes/filesystem/fs.jade',
filters: ['native', 'web']
},
{ {
title: gettext('Info'), title: gettext('Info'),
icon: 'fa-info color-orange', icon: 'fa-info color-orange',

View file

@ -0,0 +1,50 @@
module.exports = function FsCtrl($scope, $timeout) {
$scope.search = ''
$scope.files = [];
$scope.paths = [];
var listdir = function(){
var path = '/'+$scope.paths.join('/');
$scope.control.fslist(path)
.then(function(result){
$scope.files = result.body;
$scope.$digest();
})
.catch(function(err){
alert(err.message);
})
}
$scope.dirEnter = function(name){
if (name){
$scope.paths.push(name);
}
listdir();
$scope.search = '';
}
$scope.dirJump = function(){
if ($scope.paths.length !== 0){
$scope.paths.pop();
}
listdir();
}
$scope.getFile = function(file){
var path = '/'+$scope.paths.join('/')+'/'+file;
$scope.control.fsretrive(path)
.then(function(result){
location.href = result.body.href+"?download"
})
.catch(function(err){
alert(err.message);
})
}
// init
// $scope.list($scope.dir); // FIXME(ssx): can't call immediately, do not known why.
$timeout(function(){
listdir();
}, 800);
}

View file

@ -0,0 +1,17 @@
describe('FsCtrl', function () {
beforeEach(angular.mock.module(require('./').name));
var scope, ctrl;
beforeEach(inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
ctrl = $controller('FsCtrl', {$scope: scope});
}));
it('should ...', inject(function () {
expect(1).toEqual(1);
}));
});

View file

@ -0,0 +1,30 @@
.stf-fs(ng-controller='FsCtrl')
.row: .col-md-6
span /{{paths.join("/")}}
button.btn.btn-xm.btn-primary-outline(ng-click='dirJump()')
span(translate) Back
form.input-group.form-inline(ng-submit='dirEnter(search)')
input(type=text, ng-model='search', placeholder="dir or file ...").form-control
span.input-group-btn
button.btn.btn-default.btn-primary-outline(type='submit')
i.fa.fa-search
span(translate) Enter
table.table
tr(ng-repeat='f in files | filter:search | orderBy: "-mode|isdir"')
td
span
i.fa.fa-folder-open(ng-show='f.mode|isdir')
i.fa.fa-file-o(ng-hide='f.mode|isdir')
td
button.btn.btn-sm.btn-primary-outline(
ng-click='dirEnter(f.name)', ng-show='f.mode|isdir')
{{f.name}}
button.btn.btn-sm.btn-primary-outline(
ng-click='getFile(f.name)', ng-hide='f.mode|isdir')
{{f.name}}
td
i {{f.mode|mode2unix}}
td {{f.size}}

View file

View file

@ -0,0 +1,37 @@
require('./fs.less')
module.exports = angular.module('stf.filesystem', [])
.run(["$templateCache", function ($templateCache) {
$templateCache.put('control-panes/filesystem/fs.jade',
require('./fs.jade')
)
}])
.filter('mode2unix', function(){
return function(mode){
if(mode !== null){
var res = [];
var s = ['x', 'w', 'r'];
for (var i = 0; i < 3; i++) {
for (var j = 0; j < 3; j++) {
if ((mode >> (i*3+j)) & 1 !== 0){
res.unshift(s[j])
} else {
res.unshift('-')
}
}
}
res.unshift(mode & 040000 ? 'd' : '-');
return res.join('');
}
}
})
.filter('isdir', function(){
return function(mode){
if(mode !== null){
mode = parseInt(mode, 10)
mode = mode - (mode & 0777);
return (mode == 040000) || (mode == 0120000);
}
}
})
.controller('FsCtrl', require('./fs-controller'))

View file

@ -13,6 +13,7 @@ module.exports = angular.module('control-panes', [
require('./logs').name, require('./logs').name,
//require('./resources').name, //require('./resources').name,
require('./screenshots').name, require('./screenshots').name,
require('./filesystem').name,
require('./info').name require('./info').name
]) ])
.config(['$routeProvider', function ($routeProvider) { .config(['$routeProvider', function ($routeProvider) {