mirror of
https://github.com/openstf/stf
synced 2025-10-04 02:09:32 +02:00
add filesystem(file explorer) support, done
This commit is contained in:
parent
b258837757
commit
1dccda5e2a
11 changed files with 174 additions and 74 deletions
|
@ -65,68 +65,22 @@ module.exports = syrup.serial()
|
|||
})
|
||||
})
|
||||
|
||||
router.on(wire.FileSystemListMessage, function(channel, message){
|
||||
var reply = wireutil.reply(options.serial)
|
||||
adb.readdir(options.serial, message.dir)
|
||||
.then(function(files){
|
||||
push.send([
|
||||
channel,
|
||||
reply.okay('success', files)
|
||||
])
|
||||
})
|
||||
.catch(function(err){
|
||||
log.error('Dir list %s failed\n%s', message.dir, err.stack)
|
||||
push.send([
|
||||
channel,
|
||||
reply.fail(err.message)
|
||||
])
|
||||
})
|
||||
})
|
||||
return plugin;
|
||||
|
||||
|
||||
|
||||
// function projectionFormat() {
|
||||
// return util.format(
|
||||
// '%dx%d@%dx%d/%d'
|
||||
// , display.properties.width
|
||||
// , display.properties.height
|
||||
// , display.properties.width
|
||||
// , display.properties.height
|
||||
// , display.properties.rotation
|
||||
// )
|
||||
// }
|
||||
|
||||
// plugin.capture = function() {
|
||||
// log.info('Capturing screenshot')
|
||||
|
||||
// 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
|
||||
})
|
||||
|
|
|
@ -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() {
|
||||
// Clean up all listeners and subscriptions
|
||||
|
|
|
@ -72,23 +72,12 @@ enum MessageType {
|
|||
AccountRemoveMessage = 55;
|
||||
SdStatusMessage = 61;
|
||||
ReverseForwardsEvent = 72;
|
||||
FileSystemListEvent = 80;
|
||||
FileSystemListMessage = 81;
|
||||
FileSystemGetMessage = 82;
|
||||
}
|
||||
|
||||
message FileSystemListEvent {
|
||||
required string serial = 1;
|
||||
required string dir = 2;
|
||||
}
|
||||
message FileSystemListMessage {
|
||||
required string dir = 1;
|
||||
repeated FileSystemProperty files = 2;
|
||||
}
|
||||
|
||||
message FileSystemProperty {
|
||||
required string name = 1;
|
||||
required string mod = 2;
|
||||
}
|
||||
|
||||
message FileSystemGetMessage {
|
||||
|
|
|
@ -231,6 +231,12 @@ module.exports = function ControlServiceFactory(
|
|||
})
|
||||
}
|
||||
|
||||
this.fslist = function(dir){
|
||||
return sendTwoWay('fs.list', {
|
||||
dir: dir,
|
||||
})
|
||||
}
|
||||
|
||||
this.checkAccount = function(type, account) {
|
||||
return sendTwoWay('account.check', {
|
||||
type: type
|
||||
|
|
|
@ -22,6 +22,12 @@ module.exports =
|
|||
templateUrl: 'control-panes/advanced/advanced.jade',
|
||||
filters: ['native', 'web']
|
||||
},
|
||||
{
|
||||
title: gettext('FileSystem'),
|
||||
icon: 'fa-info color-orange',
|
||||
templateUrl: 'control-panes/filesystem/fs.jade',
|
||||
filters: ['native', 'web']
|
||||
},
|
||||
{
|
||||
title: gettext('Info'),
|
||||
icon: 'fa-info color-orange',
|
||||
|
|
50
res/app/control-panes/filesystem/fs-controller.js
Normal file
50
res/app/control-panes/filesystem/fs-controller.js
Normal 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);
|
||||
}
|
17
res/app/control-panes/filesystem/fs-spec.js
Normal file
17
res/app/control-panes/filesystem/fs-spec.js
Normal 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);
|
||||
|
||||
}));
|
||||
|
||||
});
|
30
res/app/control-panes/filesystem/fs.jade
Normal file
30
res/app/control-panes/filesystem/fs.jade
Normal 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}}
|
0
res/app/control-panes/filesystem/fs.less
Normal file
0
res/app/control-panes/filesystem/fs.less
Normal file
37
res/app/control-panes/filesystem/index.js
Normal file
37
res/app/control-panes/filesystem/index.js
Normal 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'))
|
|
@ -13,6 +13,7 @@ module.exports = angular.module('control-panes', [
|
|||
require('./logs').name,
|
||||
//require('./resources').name,
|
||||
require('./screenshots').name,
|
||||
require('./filesystem').name,
|
||||
require('./info').name
|
||||
])
|
||||
.config(['$routeProvider', function ($routeProvider) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue