Deleting a file in JavaScript - javascript

I am developing a native android app using HTML/CSS/JavaScript. During the App flow, I need to permanently delete certain HTML files (stored locally). Can this be done?
I am a high school teacher trying to develop an educational app. I have basic knowledge of HTML/CSS and near zero knowledge of JavaScript!

modern broswer support javascript file operation but this file system is only in broswer and isolated from local files, refer https://developer.mozilla.org/en/docs/Web/API/File
if u do need delete file on android system, then u need your app provide a bridge to and call from js, run in app, in java code, delete the file
the code might look like
JsBradge.delete(file)

Javascript disigned as a web document script language, so it has many security essentials, such as absolute isolation in browser, which means no write acces to file system.
So, you have two options - first is create your own bridge to java, for example call prompt('your_file_name'), catch it in java and delete your_file_name.
Second - use any of mobile app framework, for example - Cordova.
Sorry, but no easy ways =(

Related

Electron/Netralinojs source source code "protection"

I am evaluating which framework to create a desktop app. A requirement I have is that the source code "protection" (no one should see the original source code).
For Neautrlinojs I have found this:
https://github.com/neutralinojs/neutralinojs/issues/153#issuecomment-817842757
Now we are using the .asar format (But it is .neu in our scenario). Therefore, I will close this issue. Thanks for reporting the issue/idea.
But, as I know, the sourcecode (js) of an asar file che be obtained.
Is there a way to make impossible to get the "original" code from the build of Neautrlinojs or Electron?
I know that in a build made with nw.js, source code is very difficult to be obtained
For this kind of requirement, which framework is the most suitable?
Thank you!
If you need source code protection you need to use a tool that builds your source code to a native binary. NW.js allows for this by capturing your JS code running in memory in the V8 engine (a "V8 Snapshot"). Which means you need to run it's nwjc tool on each platform to capture it running in memory.
Other tools exist for creating Cross-Platform Desktop Apps (XPDAs):
https://xpda.net
However if you want to use JavaScript as your source code, your only real option is NW.js, or to store it on a remote server and access it via the internet.
https://nwjs.io - Official website
https://nwutils.io - Community website

How to create website-based desktop application for Windows, Linux and MacOS?

I have one but a bit complicated question.
To complete my project, I need to create an application for computers in 100%. It is to support both devices with Windows as well as those based on MacOS and Linux.
The application itself is supposed to contain several elements from its "cousin" which is the website. More specifically, it is supposed to be a login and a message system. It would be best if I could just create a folder "Application", copy any files I want with the pages and resources I want to it (simply put - any structure) and somehow convert it to the appropriate filesystems for the above-mentioned filesystems.
And now the question comes - are there suitable pages, packages for this, or maybe I have to write this application myself?
Most importantly - let me add that the only programming languages I know are JavaScript, HTML and CSS, so this task may be difficult.
Electron is a very popular approach for this sort of thing. Using front-end code (HTML, JS, CSS), you can construct an application (which essentially runs a webpage - or few) and then make it executable in any environment.
If you need any (privileged) backend code, you can write it in Node (in Electron's main process) and have it communicate to the page script through the preload script.

Is there a thing such as "packaged web app"?

Let's say I have a HTML/JS application, which is on a website and runs without any server-side component (except the web server, of course). So it's basically just a bunch of .html, .css and .js files (and some others, like images or SQLite databases)
Someday, an user comes to me to ask me if I can make an offline version, so they can access the app when they are offline.
My first reaction would be to provide them all the files of the app in a .zip file or something, but this is not really good: it's not "clear" to an average user, and the files and code are apparent (which could be "dangerous" if the user edits or deletes them by accident).
So I was wondering: is there a kind of format that would makes me able to store the files of the app in a packaged file?
The file would be something like a .zip file, but when you click to the file, instead of opening up the archive, it opens the /index.html (or similar) which is inside.
So for the user, it would be similar to open an .exe or a single .html file, but still that's not a native app, as that's still a browser app.
Given that I know about:
Apache Cordova; but most of the time, I just use the browser functions, and I don't have a need to use advanced native functionalities;
UWP and PWA, but I don't know if it's exactly what I want (I imagine it as a mix of website and mobile app, but I'm surely wrong);
Open Web App (a standard from Mozilla), but based on what I've read about it, it seems deprecated and not used anymore. Plus, I don't really look forward to "certify" my app... I just want to package some files.
PWA I don't think is a solution to your problem as you wont be able to redistribute the code as an executable package.
UWP would be too Windows specific and might make you lose the platform independence that you already have since you are using plain HTML and JS, plus from what I understand you would need to distribute the app on Windows Store.
I believe packaging as an Electron app would be the best solution as you can provide executable files that can be executed in almost all platforms.
Electron would be the best solution for you. I had a client that first wanted to run app on php server and eventually they figured out they need it as a desktop app. It was easy to rewrite php stuff to node and package as Electron app. You have access to everything files, system etc. so you can do more if needed.
Another solution would be to just inline everything into a single html file.

Is there a way to read a local netcdf file from a web application?

We are building a web service for data analysis and would like to access netcdf files from the local machine where the browser is running. Javascript offers a file browser, but (for security reasons as I learned) it will automatically upload a file after selection, instead of allowing (read-only) access to it. This presents a show-stopper, because the netcdf files can be HUGE. Note, that the netcdf format and API explicitly allow slicing and extraction of individual variables, which is one reason why the format is so popular.
Now, some research into this issue revealed that the server-client architecture normally doesn't allow access to the local file structure to prevent spying. On the other hand, in HTML5 there is a file API which supports exactly the kind of operations we need -- except that you can access portions of a file by specifying byte ranges, but there is no netcdf API available; hence one would be left again with copying the entire file before being able to slice it on the server.
Of course, the other option are web services such as OpenDAP which are meant to do exactly what we want, i.e. access parts of a netcdf file over the internet. However, this of course requires that every user would have to install the OpenDAP server before they could access their local files from within the web service. (Or, at a minimum they would have to install a web server so that one could access the file via http://localhost/...).
So: does anyone know of a solution to read specific portions of a local netcdf file from a web application? Specifically, are there javascript tools available for this?
Currently you can use netcdfjs, that it's a javascript library that allows to read NetCDF v3 files. Because it's a NodeJS package you can run it server side, and for regular size files you can read it online, here you have an example.
There are no Javascript tools to read NetCDF, but there are Java libraries: http://www.unidata.ucar.edu/downloads/netcdf/index.jsp.
You could deploy a Java Applet to read the NetCDF file locally. From there you could have the Applet try to process the file, or communicate with a backend service, or even try to call on the Applet from Javascript: http://docs.oracle.com/javase/tutorial/deployment/applet/invokingAppletMethodsFromJavaScript.html.
There are no specific Javascript libs for reading NetCDF, as far as I know. But let me drop some thoughts:
As you say, you can install a local webserver, and use a server-side language to execute a program that reads the file in your disk. You could use a command-line software called ncdump-json. I intentionally wrote this software for that purpose.
You say that you don't want to install software like OpenDAP or webservers, but maybe a desktop app, a standalone .exe would be OK for you. Using node.js plus chromium (this is called nw.js) you have a program that is at the same time a nodejs server, and a chromium browser. This way you can write a web application that reads the data (e.g. using the embedded nodejs server and spawning ncdump-json...).
And now the simplest scenario, a 100% client-side solution... I think this can only be achieved using Javascript... or anything that can "compile to" Javascript. We need to have the netCDF libraries in Javascript, is that possible? I guess so. Emscripten is a LLVM-to-Javascript compiler, and netCDF is C so it has to be possible to compile it with clang/LLVM, therefore it has to be possible to use Emscripten to have a netCDF JS library version with almost no effort, without having to write from scratch (and also maintain) a JS port. If I'm not wrong, to random access the files there's the method slice in the html5 file api, so that should not be a problem.
Hope I helped.

How to invoke Javascript in .NET in WPF & WinRT?

Here is a use case. I need to:
Invoke JavaScript from .NET (C#) code
JavaScript won't be compile, it comes from a dynamic source
I need to pass .NET objects to that javascript code, preferable a dynamic object
I also need to receive objects back from this javascript code
I need this code to run in WPF (Windows 7) & Windows Store (WinRT)
So far I've only seen activation of Windows Script Engines (i.e. IActiveScript) or using open source project.
I would prefer to stay clear of Open Source project and would prefer to use IE JavaScript engine (Chakra). Windows Script Engine doesn't seems to work on WinRT. I can live with hosting a browser in my app as it is a UI app.
Code doesn't need to be identical in WPF & WinRT (I can write something to wrap the two implementation behind an common interface).
How can I do that?
Chakra does not expose a public hosting interface, so you won't be able to do what you want without hosting something like V8 inside your application.
Another option for the metro app would be to build the main app in JavaScript and call out to WinRT objects written in .NET for the majority of the work. Won't help you in WPF though.

Categories

Resources