mirror of
https://github.com/openstf/stf
synced 2025-10-04 02:09:32 +02:00
APKs can now be drag & dropped to the device screen, which will install the application. Still lacking UI, and the app doesn't get launched.
This commit is contained in:
parent
5771507fc9
commit
dfe3d97de3
12 changed files with 280 additions and 8 deletions
62
lib/util/storage.js
Normal file
62
lib/util/storage.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
var events = require('events')
|
||||
var util = require('util')
|
||||
var fs = require('fs')
|
||||
|
||||
var uuid = require('node-uuid')
|
||||
|
||||
function Storage() {
|
||||
events.EventEmitter.call(this)
|
||||
this.files = Object.create(null)
|
||||
this.timer = setInterval(this.check.bind(this), 60000)
|
||||
}
|
||||
|
||||
util.inherits(Storage, events.EventEmitter)
|
||||
|
||||
Storage.prototype.store = function(file) {
|
||||
var id = uuid.v4()
|
||||
|
||||
this.files[id] = {
|
||||
timeout: 600000
|
||||
, lastActivity: Date.now()
|
||||
, data: file
|
||||
}
|
||||
|
||||
return id
|
||||
}
|
||||
|
||||
Storage.prototype.remove = function(id) {
|
||||
var file = this.files[id]
|
||||
if (file) {
|
||||
delete this.files[id]
|
||||
fs.unlink(file.data.path, function() {})
|
||||
}
|
||||
}
|
||||
|
||||
Storage.prototype.retrieve = function(id) {
|
||||
var file = this.files[id]
|
||||
if (file) {
|
||||
file.lastActivity = Date.now()
|
||||
return file.data
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
Storage.prototype.check = function() {
|
||||
var now = Date.now()
|
||||
|
||||
Object.keys(this.files).forEach(function(id) {
|
||||
var file = this.files[id]
|
||||
, inactivePeriod = now - file.lastActivity
|
||||
|
||||
if (inactivePeriod >= file.timeout) {
|
||||
this.remove(id)
|
||||
this.emit('timeout', id, file.data)
|
||||
}
|
||||
}, this)
|
||||
}
|
||||
|
||||
Storage.prototype.stop = function() {
|
||||
clearInterval(this.timer)
|
||||
}
|
||||
|
||||
module.exports = Storage
|
Loading…
Add table
Add a link
Reference in a new issue