I am struggling with getting Codova-Plugin-File to work.
the set up is like this:
function listDir(path) {
alert("in Listing Func with path: " + path);
window.resolveLocalFileSystemURL(path,
function (fileSystem) {
var reader = fileSystem.createReader();
reader.readEntries(
function (entries) {
alert("the right functions");
var textString = "";
for (var i = 0; i < entries.length; i++) {
textString = textString + entries[i];
}
alert(textString);
},
function (err) {
console.log(err);
}
);
}, function (err) {
console.log(err);
}
);
}
function findCampaignFolders() {
alert("in find folder codova: " + cordova.file);
listDir(cordova.file.applicationDirectory + "www");
alert("Did you see Files");
}
The alert is what I'm using in to see the data clearly at points.
when findCampaignFolders() is called the alerts are called like this
in find folder codova: Object[Object]
in Listing Func with path: nullwww
Did you see Files
form the nullwww, it seems as if the cordova-plugin-file is not working. I also get no prediction from VS2017, which leads me to be the cause.
I haven't done programming in a long time and the was C++.
I think I'm missing something obvious. Yes, the plugin installed on the project config.xml like so:
<plugin name="cordova-plugin-file" spec="~4.3.3" />
in the html cordova is first script called like <script type="text/javascript" src="cordova.js"></script>
And last of all when I try to navigate to the definition to see where the problem might come up, windows tells me
cannot navigate to symbol under caret
my only assumptions are that I not set it up correctly and if not what have I done wrong.
or visual studio 2017 hasn't actually installed the files, which I'm not sure how to really find that out.
VisualStudio2017 looks like this to show the plugin location
Any help would be grand or if there another way to use a filesystem on mobile I'm happy to hear about it
Since i wrote this I have been trying to shift through the code of the cordova i can get at to see what i can figure out , it a little above my head. But i found
interface CordovaPlugins {}
I feel like i should be adding something into this Interface like cordova-plugins-file or something. It is found in a file called index.d.ts
Also it seems corodva missing the functionality VS2017 can only see:
enter image description here
Related
One of the most time-consuming portions of development on a handlebars.js app is finding the location of the template/partial that is being used for that specific piece of HTML. Is there is a way to create a hyperlink on a localhost server to be able to click and open the template without having to manually search for text etc?
This would also help other users editing the code as it would simplify traceability.
There could be scope for an npm module or similar to do this, just not sure the exact approach.
Likely due to the sublime / browser interface, it should perhaps be a chrome extension. The other option would be to have an admin user-level interface, that allowed code editing from a modal.
Please let me know if you have a solution for this, or if there is some kind of glaringly obvious simple approach that I am missing?
So I have managed to implement a workaround for this using Grunt.
Basically, it adds a button in the HTML page that can be clicked in the browser that opens that handlebars template in sublime for editing. Local
Express
exports.editfile = function(req, res,next) {
var filename = req.query['filename']
const { exec, spawn } = require('child_process');
exec('grunt editfile --filename='+filename, (err, stdout, stderr) => {
if (err) {
console.error(err);
return;
}
console.log(stdout);
});
res.send('complete');
};
Grunt
//In the grunt init
shell: {
'openfile':openFile(),
}
grunt.loadNpmTasks('grunt-shell');
function openFile(){
var openString = ''
var fileName = grunt.option('filename'); //get value of target, my_module
openString = {
command: [
'cd..','cd..','cd..','cd '+process.env.ROOTFOLDER,
'sublime_text.exe "'+fileName+'"',
].join('&&')
}
return openString
}
grunt.registerTask('editfile',[
'shell:openfile'
]);
Handlebars
<a class="btn btn-outline-warning bt-sm adminedit" style="" data-filename="{{filename}}" id="{{uniqueid}}" onclick="editFile(this.id)" href="#" class="text-warning">edit</a>
<script type="text/javascript">
function editFile(iditem){
var editFilename = $('#'+iditem).attr("data-filename")
$.ajax({
url : '/semini/admin/editfile/?filename='+editFilename,
success : function( data ) {
console.log('executing : ',data)
},
error : function( xhr, err ) {
alert('Error',err);
}
});
}
</script>
Note, to get sublime to open from the CMD, you have to add an environment variable in windows. Not too difficult, just google.
It works great ..... but
I cannot get a partial on handlebars to provide its name, and as such this only works for the first rendered page and not partials.
I'm using the Office JS library to create an Excel add-in, and the Microsoft object is not being recognized. All the other classes from the library seem to to work fine, but when I call dialog.addEventHandler(Microsoft.Office.WebExtension.EventType.DialogMessageReceived,processMessage the Microsoft object is not evaluated properly. This is despite every other object from this library working fine.
I'm following this tutorial https://learn.microsoft.com/en-us/office/dev/add-ins/tutorials/excel-tutorial
I'm using CDN from this link: https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js
The method that calls Microsoft.Office.WebExtension fails, and I knew it would because WebStorm tells me its not recognized.
All of the other objects from Office JS work fine though...here's an example of working code:
function sortTable() {
Excel.run(function (context) {
// Queue commands to sort the table by merchant name
var currentWorkbook = context.workbook.worksheets.getActiveWorksheet();
var expensesTable = currentWorkbook.tables.getItem('ExpensesTable');
var sortFields = [
{
key: 1,
ascending: false,
}
];
expensesTable.sort.apply(sortFields);
return context.sync();
}).catch(function (error) {
console.log("Error" + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});
}
I've review in detail the Office JavaScript API documentation: https://learn.microsoft.com/en-us/office/dev/add-ins/reference/overview/excel-add-ins-reference-overview
I've reviewed that there is an older common API: https://learn.microsoft.com/en-us/javascript/api/office?view=word-js-preview
I have suspected that I need access to this older common API, but the only documentation I've found says that you are just supposed to use the office.js library I've linked above.
Here's the whole function I'm trying to use:
function openDialog() {
//Call the Office Common API that opens a dialog
Office.context.ui.displayDialogAsync(
'https://localhost:3000/popup.html',
{height: 45, width:55},
function (result) {
dialog = result.value;
dialog.addEventHandler(Microsoft.Office.WebExtension.EventType.DialogMessageReceived,processMessage);
}
)
}
It does in fact open a dialog box as the Office.context.ui.displayDialogAsync method works. But as soon as you get to Microsoft.Office.WebExtension.EventType.DialogMessageReceived WebStorm tells me that the element Microsoft is an unresolved reference.
And here's the function it should call if it worked, processMessage. Because it does not get this far, the element does not get updated, and the dialog box does not close. I'm near 100% certain the issue is not with the function below, but I'm not ruling it out yet.
function processMessage(arg) {
console.log("made it inside processMessage")
document.getElementById("user-name").innerHTML = arg.message;
console.log("made ti just before dialog.close")
dialog.close();
}
The full name has been shortened to Office.EventType.DialogMessageReceived. Here's the GitHub issue: https://github.com/OfficeDev/office-js-docs-pr/issues/1710
I am building a Cordova App by myself and i need to create a new folder to store images in phone's internal storage. I have visited a lot of articles online and everyone is giving the same solution but it is not working for me.
Following is the code i am using in OnDeviceReady event but it is not working.
var new_directory = 'TEST';
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getDirectory(new_directory, { create: true }, function (file) {
alert("got the file: "+ file.name + ', ' + file.fullPath);
});
}, function(error) {
alert("can't even get the file system: " + error.code);
});
For Debugging i have also tried to alert
cordova.file
object but it is shown as undefined.
I have tried writing simple file request statement even its is not working
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, alert('success'), alert('failed'));
also the rest of the javascript code does not work when i write above code.
Please help me to get on with this.
Have you been asked to grant the proper permissions when you try to save the file? A window like this should have appeared:
If this is not the case, you are using an obsolete plugin version. Otherwise, there is something wrong with your code, sorry but I can't help you with that.
For around 3 weeks I've been working on an Electron app and finally decided to get around to adding update checking. For my research, the standard way to do this in Electron (using Squirrel) requires the user to physically install the application onto their computer. I would rather not do this, and keep everything as portable as possible. I then decided to try making my own update script by having the program download the update.zip, and extract it to overwrite the existing files. This works well, up until the very end. At the very end of the extraction, I receive a Invalid package error, and the actual app.asar file is missing, rendering the application useless.
I am using this to download and extract the updates:
function downloadFile(url, target, fileName, cb) { // Downloads
var req = request({
method: 'GET',
uri: url
});
var out = fs.createWriteStream(target+'/'+fileName);
req.pipe(out);
req.on('end', function() {
unzip(target+'/'+fileName, target, function() {
if (cb) {
cb();
}
});
});
}
function unzip(file, target, cb) { // Unzips
var out = fs.createReadStream(file);
out.pipe(unzipper.Extract({ path: target })).on('finish', function () {
dialog.showMessageBox({
type: 'question',
message: 'Finished extracting to `'+target+'`'
});
if (cb) {
cb();
}
});
}
And call it with:
downloadFile('http://example.com/update.zip', path.join(__dirname, './'), 'update.zip', function() { // http://example.com/update.zip is not the real source
app.relaunch();
app.quit();
});
And I use the unzipper NPM package (https://www.npmjs.com/package/unzipper).
The code works perfectly for all other zips, but it fails when trying to extract a zip containing an Electron app.
Anything I'm doing wrong, or maybe a different package that properly supports extracting zips with .asar files?
Edit 1
I just found https://www.npmjs.com/package/electron-basic-updater, which does not throw the same JavaScript error however it still does not extract the .asar files correctly, and will throw it's own error. Since the .asar is still missing, the app is still useless after the "update"
Thanks to your link to electron-basic-updater, I have found this issue mentioned there: https://github.com/TamkeenLMS/electron-basic-updater/issues/4.
They refer to the issue in the electron app: https://github.com/electron/electron/issues/9304.
Finally, in the end of the second topic there's a solution:
This is due to the electron fs module treating asar files as directories rather than files. To make the unzip process work you need to do one of two things:
Set process.noAsar = true
Use original-fs instead of fs
I have seen the people working with original-fs. But it looked like a big trouble to me.
So I tried setting process.noAsar = true (and then process.noAsar = false after unzipping) - and that worked like a charm.
I'm new to javascript and node js.
I've following code in my authentication.js file
I'm trying to get the intellisense working when I press client. ( and CTRL + space), I do not see anything.
How do I be able to see functions that are within auth.OAuth2 modules.
I remember in VS you can use /// reference paths. Not sure if that is the standard approach in ATOM as well. I looked over the internet and could not find any satisfactory answer.
How do people know what methods to use and what is their required signature without intellisense?
I'm literally crawling to make things work right now because of this. Do I have to read documentation for every modules/packages before I start using it? That'd take a lot of time.
Please also note that I have added all the packages like autocomplete, autocomplete-plus and so on for the intellisense to work magically but it doesn't. Intellisense does work but it displays everything else but not the functions of the modules I'm referring to in the example.
Any help/suggestion is much appreciated?
'use strict';
var config = require("../../config/config");
exports.verifyUser = function(req, res, next) {
var GoogleAuth = require('google-auth-library');
var auth = new GoogleAuth;
var client = new auth.OAuth2(config.clientID, config.clientSecret,config.callbackURL);
**client. //no intellisense**
// check header or url parameters or post parameters for token
var token = req.body.id_token || req.query.id_token || req.headers['id_token'];
if (token) {
client.verifyIdToken(
token,
config.clientID,
function (err) {
if (err) {
res.send("Un authorized");
} else {
next();
}
});
}
}
I've had great success using Visual Studio Code.
Its a lightweight IDE similar to Atom, its actually also built using Electron.
You can check out a tutorial about how to get things set up here.
https://blog.tallan.com/2017/03/02/synthetic-type-inference-in-javascript/
You need to add an intellesense plugin for the language you're using. Atom isn't really suited to noobs though, you should try out netbeans if you want a fully featured editor.