From 5bd357806fb0f3d0a9556dfb718f53bfb6af4fbb Mon Sep 17 00:00:00 2001 From: Gubolin Date: Sat, 6 Sep 2014 15:52:50 +0200 Subject: add vibrate block --- objects.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'objects.js') diff --git a/objects.js b/objects.js index fbb9e84..9dadfb3 100644 --- a/objects.js +++ b/objects.js @@ -878,6 +878,11 @@ SpriteMorph.prototype.initBlocks = function () { category: 'sensing', spec: 'current %dates' }, + doVibrate: { + type: 'command', + category: 'sensing', + spec: 'vibrate %n seconds' + }, // Operators reifyScript: { @@ -4991,6 +4996,8 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push(block('doSetFastTracking')); blocks.push('-'); blocks.push(block('reportDate')); + blocks.push('-'); + blocks.push(block('doVibrate')); // for debugging: /////////////// -- cgit v1.3.1 From 3c71f1a3871926a614eaefac079e79e0d9b95395 Mon Sep 17 00:00:00 2001 From: Gubolin Date: Sun, 7 Sep 2014 12:34:55 +0200 Subject: add compass heading and acceleration blocks --- mobile.sh | 2 ++ objects.js | 34 +++++++++++++++++++++ threads.js | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+) (limited to 'objects.js') diff --git a/mobile.sh b/mobile.sh index 212f711..cd41a86 100755 --- a/mobile.sh +++ b/mobile.sh @@ -15,4 +15,6 @@ git checkout mobileapp cordova platform add android cordova plugin add org.apache.cordova.plugin.softkeyboard cordova plugin add org.apache.cordova.vibration +cordova plugin add org.apache.cordova.device-motion +cordova plugin add org.apache.cordova.device-orientation cordova build android diff --git a/objects.js b/objects.js index 9dadfb3..43e4fcf 100644 --- a/objects.js +++ b/objects.js @@ -883,6 +883,26 @@ SpriteMorph.prototype.initBlocks = function () { category: 'sensing', spec: 'vibrate %n seconds' }, + reportCompassHeading: { + type: 'reporter', + category: 'sensing', + spec: 'current compass heading' + }, + reportAccelerationX: { + type: 'reporter', + category: 'sensing', + spec: 'current acceleration along the x axes' + }, + reportAccelerationY: { + type: 'reporter', + category: 'sensing', + spec: 'current acceleration along the y axes' + }, + reportAccelerationZ: { + type: 'reporter', + category: 'sensing', + spec: 'current acceleration along the z axes' + }, // Operators reifyScript: { @@ -1889,6 +1909,12 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push(block('doSetFastTracking')); blocks.push('-'); blocks.push(block('reportDate')); + blocks.push('-'); + blocks.push(block('reportCompassHeading')); + blocks.push('-'); + blocks.push(block('reportAccelerationX')); + blocks.push(block('reportAccelerationY')); + blocks.push(block('reportAccelerationZ')); // for debugging: /////////////// @@ -4263,6 +4289,8 @@ StageMorph.prototype.init = function (globals) { this.paletteCache = {}; // not to be serialized (!) this.lastAnswer = ''; // last user input, do not persist this.activeSounds = []; // do not persist + this.acceleration = null; // do not persist + this.compassHeading = null; // do not persist this.trailsCanvas = null; this.isThreadSafe = false; @@ -4998,6 +5026,12 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push(block('reportDate')); blocks.push('-'); blocks.push(block('doVibrate')); + blocks.push('-'); + blocks.push(block('reportCompassHeading')); + blocks.push('-'); + blocks.push(block('reportAccelerationX')); + blocks.push(block('reportAccelerationY')); + blocks.push(block('reportAccelerationZ')); // for debugging: /////////////// diff --git a/threads.js b/threads.js index c796642..72a694f 100644 --- a/threads.js +++ b/threads.js @@ -2601,6 +2601,108 @@ Process.prototype.reportDate = function (datefn) { return result; }; +Process.prototype.getCompassHeading = function (dest) { + var stage = this.homeContext.receiver.parentThatIsA(StageMorph); + + stage.compassHeading = null; + if (navigator.compass) { + navigator.compass.getCurrentHeading( + function (result) { + stage.compassHeading = result; + }, + function () { + stage.compassHeading = + {'magneticHeading': 0, 'trueHeading': 0, + 'headingAccuracy': 0, 'timestamp': 0}; + } + ); + } else { + stage.compassHeading = + {'magneticHeading': 0, 'trueHeading': 0, + 'headingAccuracy': 0, 'timestamp': 0}; + } +}; + +Process.prototype.reportCompassHeading = function () { + var stage = this.homeContext.receiver.parentThatIsA(StageMorph); + + if (this.context.wait) { + if (stage.compassHeading !== null) { + return stage.compassHeading.magneticHeading; + } + } else { + this.context.wait = true; + this.getCompassHeading(); + } + this.pushContext('doYield'); + this.pushContext(); +}; + +Process.prototype.getAcceleration = function (dest) { + var stage = this.homeContext.receiver.parentThatIsA(StageMorph); + + stage.acceleration = null; + if (navigator.accelerometer) { + navigator.accelerometer.getCurrentAcceleration( + function (result) { + stage.acceleration = result; + }, + function () { + stage.acceleration = + {'timestamp': 0, 'z': 0, 'y': 0, 'x': 0}; + } + ); + } else { + stage.acceleration = + {'timestamp': 0, 'z': 0, 'y': 0, 'x': 0}; + } +}; + +Process.prototype.reportAccelerationX = function () { + var stage = this.homeContext.receiver.parentThatIsA(StageMorph); + + if (this.context.wait) { + if (stage.acceleration !== null) { + return stage.acceleration.x; + } + } else { + this.context.wait = true; + this.getAcceleration(); + } + this.pushContext('doYield'); + this.pushContext(); +}; + +Process.prototype.reportAccelerationY = function () { + var stage = this.homeContext.receiver.parentThatIsA(StageMorph); + + if (this.context.wait) { + if (stage.acceleration !== null) { + return stage.acceleration.y; + } + } else { + this.context.wait = true; + this.getAcceleration(); + } + this.pushContext('doYield'); + this.pushContext(); +}; + +Process.prototype.reportAccelerationZ = function () { + var stage = this.homeContext.receiver.parentThatIsA(StageMorph); + + if (this.context.wait) { + if (stage.acceleration !== null) { + return stage.acceleration.z; + } + } else { + this.context.wait = true; + this.getAcceleration(); + } + this.pushContext('doYield'); + this.pushContext(); +}; + Process.prototype.doVibrate = function (seconds) { if ("vibrate" in navigator) { window.navigator.vibrate(seconds * 1000); -- cgit v1.3.1 From 8e14ae00f1ec4d60727702df4265bf142856cebc Mon Sep 17 00:00:00 2001 From: Gubolin Date: Sun, 7 Sep 2014 12:39:16 +0200 Subject: add vibration blocks to sprites --- objects.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 43e4fcf..0913357 100644 --- a/objects.js +++ b/objects.js @@ -1910,6 +1910,8 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push('-'); blocks.push(block('reportDate')); blocks.push('-'); + blocks.push(block('doVibrate')); + blocks.push('-'); blocks.push(block('reportCompassHeading')); blocks.push('-'); blocks.push(block('reportAccelerationX')); -- cgit v1.3.1 From a7b3c537edf83b8415716f930fd3fe518638c4db Mon Sep 17 00:00:00 2001 From: Gubolin Date: Mon, 8 Sep 2014 12:27:01 +0200 Subject: add notification blocks --- mobile.sh | 1 + objects.js | 9 +++++++++ threads.js | 14 ++++++++++++++ 3 files changed, 24 insertions(+) (limited to 'objects.js') diff --git a/mobile.sh b/mobile.sh index 81fa6f3..909f7e5 100755 --- a/mobile.sh +++ b/mobile.sh @@ -47,6 +47,7 @@ cordova plugin add org.apache.cordova.vibration cordova plugin add org.apache.cordova.device-motion cordova plugin add org.apache.cordova.device-orientation cordova plugin add org.apache.cordova.geolocation +cordova plugin add de.appplant.cordova.plugin.local-notification if [[ $1 == "android" ]] then diff --git a/objects.js b/objects.js index 49fafb5..100bd67 100644 --- a/objects.js +++ b/objects.js @@ -415,6 +415,11 @@ SpriteMorph.prototype.initBlocks = function () { spec: 'go back %n layers', defaults: [1] }, + doNotify: { + type: 'command', + category: 'looks', + spec: 'notification with title %s and content %s' + }, doScreenshot: { type: 'command', category: 'looks', @@ -1762,6 +1767,8 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push('-'); blocks.push(block('comeToFront')); blocks.push(block('goBack')); + blocks.push('-'); + blocks.push(block('doNotify')); // for debugging: /////////////// @@ -4905,6 +4912,8 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push('-'); blocks.push(block('show')); blocks.push(block('hide')); + blocks.push('-'); + blocks.push(block('doNotify')); // for debugging: /////////////// diff --git a/threads.js b/threads.js index 3e50686..7616b88 100644 --- a/threads.js +++ b/threads.js @@ -2189,6 +2189,20 @@ Process.prototype.reportTextSplit = function (string, delimiter) { return new List(str.split(del)); }; +// Process notification operations + +Process.prototype.doNotify = function (title, content) { + // TODO webkitNotification + if (window.plugin) { + if (window.plugin.notification) { + window.plugin.notification.local.add({ + message: content, + title: title + }); + } + } +}; + // Process debugging Process.prototype.alert = function (data) { -- cgit v1.3.1 From 478f3d4c387d67cb54a02ba373bfb4655d7a19f7 Mon Sep 17 00:00:00 2001 From: Gubolin Date: Tue, 9 Sep 2014 11:51:31 +0200 Subject: add file blocks --- blocks.js | 12 ++++ mobile.sh | 1 + objects.js | 44 +++++++++++++++ threads.js | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 240 insertions(+) (limited to 'objects.js') diff --git a/blocks.js b/blocks.js index 735d36b..9aec7f4 100644 --- a/blocks.js +++ b/blocks.js @@ -844,6 +844,18 @@ SyntaxElementMorph.prototype.labelPart = function (spec) { ); part.setContents(['date']); break; + case '%fileOrDir': + part = new InputSlotMorph( + null, // text + false, // non-numeric + { + 'file': ['file'], + 'directory': ['directory'] + }, + true // read-only + ); + part.setContents(['file']); + break; case '%locations': part = new InputSlotMorph( null, // text diff --git a/mobile.sh b/mobile.sh index 909f7e5..b0bcc5d 100755 --- a/mobile.sh +++ b/mobile.sh @@ -48,6 +48,7 @@ cordova plugin add org.apache.cordova.device-motion cordova plugin add org.apache.cordova.device-orientation cordova plugin add org.apache.cordova.geolocation cordova plugin add de.appplant.cordova.plugin.local-notification +cordova plugin add org.apache.cordova.file if [[ $1 == "android" ]] then diff --git a/objects.js b/objects.js index 100bd67..d432dcb 100644 --- a/objects.js +++ b/objects.js @@ -883,6 +883,36 @@ SpriteMorph.prototype.initBlocks = function () { category: 'sensing', spec: 'current %dates' }, + reportFileOrDirectoryContent: { + type: 'reporter', + category: 'sensing', + spec: 'content of the %fileOrDir %s' + }, + doSetFileContent: { + type: 'command', + category: 'sensing', + spec: 'write %s to the file %s' + }, + doCreateFileOrDirectory: { + type: 'command', + category: 'sensing', + spec: 'create %fileOrDir %s' + }, + reportFileOrDirectoryExists: { + type: 'predicate', + category: 'sensing', + spec: '%fileOrDir %s exists' + }, + doDeleteFileOrDirectory: { + type: 'command', + category: 'sensing', + spec: 'delete the %fileOrDir %s' + }, + reportHomeDirectory: { + type: 'reporter', + category: 'sensing', + spec: 'home directory' + }, doVibrate: { type: 'command', category: 'sensing', @@ -1927,6 +1957,13 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push('-'); blocks.push(block('reportDate')); blocks.push('-'); + blocks.push(block('reportFileOrDirectoryContent')); + blocks.push(block('doSetFileContent')); + blocks.push(block('doCreateFileOrDirectory')); + blocks.push(block('reportFileOrDirectoryExists')); + blocks.push(block('doDeleteFileOrDirectory')); + blocks.push(block('reportHomeDirectory')); + blocks.push('-'); blocks.push(block('reportLanguage')); blocks.push(block('reportLocation')); blocks.push('-'); @@ -5049,6 +5086,13 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push('-'); blocks.push(block('reportDate')); blocks.push('-'); + blocks.push(block('reportFileOrDirectoryContent')); + blocks.push(block('doSetFileContent')); + blocks.push(block('doCreateFileOrDirectory')); + blocks.push(block('reportFileOrDirectoryExists')); + blocks.push(block('doDeleteFileOrDirectory')); + blocks.push(block('reportHomeDirectory')); + blocks.push('-'); blocks.push(block('reportLanguage')); blocks.push(block('reportLocation')); blocks.push('-'); diff --git a/threads.js b/threads.js index 7616b88..37db5cd 100644 --- a/threads.js +++ b/threads.js @@ -2687,6 +2687,189 @@ Process.prototype.reportDate = function (datefn) { return result; }; +// Process File access +Process.prototype.reportFileOrDirectoryContent = function (typeInput, filepath) { + var myself = this; + var type = myself.inputOption(typeInput); + + if (myself.context.result == null) { + myself.context.result = 'wait'; + + if (window.resolveLocalFileSystemURL) { + window.resolveLocalFileSystemURL(filepath, + function (entry) { + if (type === 'file') { + entry.file( + function (file) { + var reader = new FileReader(); + + reader.onloadend = function (e) { + myself.context.result = this.result; + }; + + reader.readAsText(file); + }, + function (error) { + myself.context.result = error.toString(); + } + ); + } else { + var dirReader = entry.createReader(); + dirReader.readEntries( + function (results) { + var items = []; + results.forEach( + function (item) { + items.push(item.name); + } + ); + myself.context.result = new List(items); + }, + function (error) { + myself.context.result = error.toString(); + } + ); + } + }, + function (error) { + myself.context.result = error.toString(); + } + ); + } + } else { + if (myself.context.result !== 'wait') { + return myself.context.result; + } + } + + this.pushContext('doYield'); + this.pushContext(); +}; + +Process.prototype.doSetFileContent = function (content, filepath) { + var dirpath = filepath.substring(0, + filepath.lastIndexOf('/')); + var filename = filepath.substring( + filepath.lastIndexOf('/') + 1); + + if (window.resolveLocalFileSystemURL) { + window.resolveLocalFileSystemURL(dirpath, + function (dirEntry) { + dirEntry.getFile(filename, + {create: true, exclusive: false}, + function (fileEntry) { + fileEntry.createWriter( + function (fileWriter) { + var blob; + + try { + blob = new Blob([content], + {type: 'text/plain'}); + // No `new Blob` for Android + } catch (e) { + window.BlobBuilder = + window.BlobBuilder || + window.WebKitBlobBuilder || + window.MozBlobBuilder || + window.MSBlobBuilder; + + if (e.name == 'TypeError' + && window.BlobBuilder) { + var bb = new BlobBuilder(); + bb.append(content); + blob = bb.getBlob('text/plain'); + } + } + + fileWriter.write(blob); + } + ); + } + ); + } + ); + } +}; + +Process.prototype.createFileOrDirectory = function (typeInput, filepath) { + var myself = this; + var type = myself.inputOption(typeInput); + + function createDir(rootDirEntry, folders) { + rootDirEntry.getDirectory(folders[0], {create: true}, + function (dirEntry) { + if (folders.length === 1) { + if (type === 'file') { + dirEntry.getFile(folders.slice(1), + {create: true, exclusive: false}); + return; + } + } + + if (folders.length) { + createDir(dirEntry, folders.slice(1)); + } + } + ); + }; + + window.requestFileSystem(window.PERSISTENT, 0, + function (fileSystem) { + createDir(fileSystem.root, path.split('/')); + } + ); +}; + +Process.prototype.reportFileOrDirectoryExists = function (typeInput, filepath) { + var myself = this; + var type = myself.inputOption(typeInput); + + if (myself.context.result == null) { + myself.context.result = 'wait'; + + if (window.resolveLocalFileSystemURL) { + window.resolveLocalFileSystemURL(filepath, + function (entry) { + if (type === 'file') { + myself.context.result = !entry.isDirectory; + } else { + myself.context.result = entry.isDirectory; + } + }, + function (error) { + myself.context.result = false; + } + ); + } + } else { + if (myself.context.result !== 'wait') { + return myself.context.result; + } + } + + this.pushContext('doYield'); + this.pushContext(); +}; + +Process.prototype.doDeleteFileOrDirectory = function (typeInput, filepath) { + if (window.resolveLocalFileSystemURL) { + window.resolveLocalFileSystemURL(filepath, + function (entry) { + entry.remove(); + } + ); + } +}; + +Process.prototype.reportHomeDirectory = function () { + if (cordova) { + if (cordova.file) { + return cordova.file.dataDirectory; + } + } + return ''; +}; + Process.prototype.getCompassHeading = function (dest) { var stage = this.homeContext.receiver.parentThatIsA(StageMorph); -- cgit v1.3.1 From 618e034eb86b3ad7e7f4955b900862a27a0ce44c Mon Sep 17 00:00:00 2001 From: Gubolin Date: Sat, 3 Jan 2015 11:23:07 +0100 Subject: remove file blocks --- blocks.js | 12 ---- mobile.sh | 1 - objects.js | 44 ------------- threads.js | 215 ------------------------------------------------------------- 4 files changed, 272 deletions(-) (limited to 'objects.js') diff --git a/blocks.js b/blocks.js index 9aec7f4..735d36b 100644 --- a/blocks.js +++ b/blocks.js @@ -844,18 +844,6 @@ SyntaxElementMorph.prototype.labelPart = function (spec) { ); part.setContents(['date']); break; - case '%fileOrDir': - part = new InputSlotMorph( - null, // text - false, // non-numeric - { - 'file': ['file'], - 'directory': ['directory'] - }, - true // read-only - ); - part.setContents(['file']); - break; case '%locations': part = new InputSlotMorph( null, // text diff --git a/mobile.sh b/mobile.sh index 59e5da8..4b5dc48 100755 --- a/mobile.sh +++ b/mobile.sh @@ -53,7 +53,6 @@ cordova plugin add org.apache.cordova.device-motion cordova plugin add org.apache.cordova.device-orientation cordova plugin add org.apache.cordova.geolocation cordova plugin add de.appplant.cordova.plugin.local-notification -cordova plugin add org.apache.cordova.file if [[ $1 == "android" ]] then diff --git a/objects.js b/objects.js index cf7a191..d1a07ab 100644 --- a/objects.js +++ b/objects.js @@ -910,36 +910,6 @@ SpriteMorph.prototype.initBlocks = function () { category: 'sensing', spec: 'current %dates' }, - reportFileOrDirectoryContent: { - type: 'reporter', - category: 'sensing', - spec: 'content of the %fileOrDir %s' - }, - doSetFileContent: { - type: 'command', - category: 'sensing', - spec: 'write %s to the file %s' - }, - doCreateFileOrDirectory: { - type: 'command', - category: 'sensing', - spec: 'create %fileOrDir %s' - }, - reportFileOrDirectoryExists: { - type: 'predicate', - category: 'sensing', - spec: '%fileOrDir %s exists' - }, - doDeleteFileOrDirectory: { - type: 'command', - category: 'sensing', - spec: 'delete the %fileOrDir %s' - }, - reportHomeDirectory: { - type: 'reporter', - category: 'sensing', - spec: 'home directory' - }, doVibrate: { type: 'command', category: 'sensing', @@ -1988,13 +1958,6 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push('-'); blocks.push(block('reportDate')); blocks.push('-'); - blocks.push(block('reportFileOrDirectoryContent')); - blocks.push(block('doSetFileContent')); - blocks.push(block('doCreateFileOrDirectory')); - blocks.push(block('reportFileOrDirectoryExists')); - blocks.push(block('doDeleteFileOrDirectory')); - blocks.push(block('reportHomeDirectory')); - blocks.push('-'); blocks.push(block('reportLanguage')); blocks.push(block('reportLocation')); blocks.push('-'); @@ -5125,13 +5088,6 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push('-'); blocks.push(block('reportDate')); blocks.push('-'); - blocks.push(block('reportFileOrDirectoryContent')); - blocks.push(block('doSetFileContent')); - blocks.push(block('doCreateFileOrDirectory')); - blocks.push(block('reportFileOrDirectoryExists')); - blocks.push(block('doDeleteFileOrDirectory')); - blocks.push(block('reportHomeDirectory')); - blocks.push('-'); blocks.push(block('reportLanguage')); blocks.push(block('reportLocation')); blocks.push('-'); diff --git a/threads.js b/threads.js index 8fbd587..5d6020e 100644 --- a/threads.js +++ b/threads.js @@ -2716,221 +2716,6 @@ Process.prototype.reportDate = function (datefn) { return result; }; -// Process File access -// http://www.html5rocks.com/en/tutorials/file/filesystem/ -Process.prototype.fileErrorHandler = function (e) { - var msg = ''; - - switch (e.code) { - case FileError.QUOTA_EXCEEDED_ERR: - msg = localize('no space left'); - break; - case FileError.NOT_FOUND_ERR: - msg = localize('not found'); - break; - case FileError.SECURITY_ERR: - msg = localize('access denied'); - break; - case FileError.INVALID_MODIFICATION_ERR: - msg = 'INVALID_MODIFICATION_ERR'; - break; - case FileError.INVALID_STATE_ERR: - msg = 'INVALID_STATE_ERR'; - break; - default: - msg = localize('unknown error'); - break; - } - - this.handleError(msg); -}; - -Process.prototype.reportFileOrDirectoryContent = function (typeInput, filepath) { - var myself = this; - var type = myself.inputOption(typeInput); - - if (myself.context.result === null) { - myself.context.result = false; - - if (window.resolveLocalFileSystemURL) { - window.resolveLocalFileSystemURL(filepath, - function (entry) { - if (type === 'file') { - entry.file( - function (file) { - var reader = new FileReader(); - - reader.onloadend = function (e) { - myself.context.result = this.result; - }; - - reader.readAsText(file); - }, - myself.fileErrorHandler - ); - } else { - var dirReader = entry.createReader(); - dirReader.readEntries( - function (results) { - var items = []; - results.forEach( - function (item) { - items.push(item.name); - } - ); - myself.context.result = new List(items); - }, - myself.fileErrorHandler - ); - } - }, - myself.fileErrorHandler - ); - } - } else { - if (myself.context.result !== false) { - return myself.context.result; - } - } - - this.pushContext('doYield'); - this.pushContext(); -}; - -Process.prototype.doSetFileContent = function (content, filepath) { - var dirpath = filepath.substring(0, - filepath.lastIndexOf('/')); - var filename = filepath.substring( - filepath.lastIndexOf('/') + 1); - - if (window.resolveLocalFileSystemURL) { - window.resolveLocalFileSystemURL(dirpath, - function (dirEntry) { - dirEntry.getFile(filename, - {create: true, exclusive: false}, - function (fileEntry) { - fileEntry.createWriter( - function (fileWriter) { - var blob; - - try { - blob = new Blob([content], - {type: 'text/plain'}); - // No `new Blob` for Android - } catch (e) { - window.BlobBuilder = - window.BlobBuilder || - window.WebKitBlobBuilder || - window.MozBlobBuilder || - window.MSBlobBuilder; - - if (e.name == 'TypeError' - && window.BlobBuilder) { - var bb = new BlobBuilder(); - bb.append(content); - blob = bb.getBlob('text/plain'); - } - } - - fileWriter.write(blob); - }, - myself.fileErrorHandler - ); - }, - myself.fileErrorHandler - ); - }, - myself.fileErrorHandler - ); - } -}; - -Process.prototype.createFileOrDirectory = function (typeInput, filepath) { - var myself = this; - var type = myself.inputOption(typeInput); - - function createDir(rootDirEntry, folders) { - rootDirEntry.getDirectory(folders[0], {create: true}, - function (dirEntry) { - if (folders.length === 1) { - if (type === 'file') { - dirEntry.getFile(folders.slice(1), - {create: true, exclusive: false}, - function (fileEntry) { - return; - }, - myself.fileErrorHandler - ); - - return; - } - } - - if (folders.length) { - createDir(dirEntry, folders.slice(1)); - } - }, - myself.fileErrorHandler - ); - } - - window.requestFileSystem(window.PERSISTENT, 0, - function (fileSystem) { - createDir(fileSystem.root, path.split('/')); - }, - myself.fileErrorHandler - ); -}; - -Process.prototype.reportFileOrDirectoryExists = function (typeInput, filepath) { - var myself = this; - var type = myself.inputOption(typeInput); - - if (myself.context.result === null) { - myself.context.result = 'wait'; - - if (window.resolveLocalFileSystemURL) { - window.resolveLocalFileSystemURL(filepath, - function (entry) { - if (type === 'file') { - myself.context.result = !entry.isDirectory; - } else { - myself.context.result = entry.isDirectory; - } - }, - myself.fileErrorHandler - ); - } - } else { - if (myself.context.result !== 'wait') { - return myself.context.result; - } - } - - this.pushContext('doYield'); - this.pushContext(); -}; - -Process.prototype.doDeleteFileOrDirectory = function (typeInput, filepath) { - if (window.resolveLocalFileSystemURL) { - window.resolveLocalFileSystemURL(filepath, - function (entry) { - entry.remove(); - }, - myself.fileErrorHandler - ); - } -}; - -Process.prototype.reportHomeDirectory = function () { - if (cordova) { - if (cordova.file) { - return cordova.file.dataDirectory; - } - } - return ''; -}; - Process.prototype.getCompassHeading = function () { var stage = this.homeContext.receiver.parentThatIsA(StageMorph); -- cgit v1.3.1