I'm planning to create an Electron app. The app has content of multiple mp3/png/svg files which are going to be rendered inside the app. I don't want anyone to open an audio or an image outside of the app. I researched a lot to find a solution to protect theses file so that if someone installed the app won't be able to open and use the files outside of my app but it seems that it's not possible...
Note: simple protection solution with minimal security is accepted too...
Note 2: Can we store the files (mp3/ png/svg) without any extension (this way users can not open them directly on their machine) and then open the files via electron app (we have the name and extension stored in our app so we have the extension to attach to preloaded file and open the file) I mean can we preload the audio file without extension and then open the preloaded audio with mp3 format as a work around?
I saw a clever "solution" for protecting multimedia assets back in the days of interactive CD-ROMS.
The trick was to write some junk text to the end of the .mp3 or video file in order to corrupt the file and make it unplayable. Then in the app, to play the file, the file would be written to a temporary directory with the junk text removed so it could be played.
Not foolproof by any means but it prevents casual copying assets out of the app bundle.
Related
I want to open files from webpage. For example when we try to download a torrent file it redirects us to utorrent app and it continues it work. I also want to open a local file somehow using OS software. Like a video file using pot player. Is there any possible solution for me ,like making a autorun in pc to run that . Anything it may be please help me.😔😔
I searched and found a solution to open a software using protocol, but in this way I cannot open a file in that software.
Opening a specific file in a specific software would usually depend on passing some URL parameters to the protocol-URL of the app (e.g., opening a file in VSCode would use a URL like vscode:///Users/me/file.html, but this functionality would have to be explicitly handled by the app itself though, so the solution for each app would be different).
Otherwise, if the app doesn't support opening a specific file itself through a URL, you'd have to use some scripting software (e.g. AppleScript if you're on macOS) to dynamically click/open certain programs on a user's computer.
the link acts as a magnet so your torrent application is opened maybe delete torrent for sometime till you finish the project, i know how to open image in local files in html but it will only be visible to you, you can do audio and video files also using <source src="movie.mp4 and on next line `type="video/mp4">
I'm wondering if it's possible to for certain JS files to be added to the web extension directory later?
Like say I have an app where users can select certain settings from within the app and those files (js and html files, images or blobs) are somehow added into the extension from the web. Like some sort of ondemand updater without using any native apps but it seems that upgrades are done by the appstores automatically.
I'm reading the files using ajax and adding them to indexeddb but because it could be more than one file that's getting messy.
Say a user wants a certain feature on the extension and there's an html page, js files and images then this gets downloaded to a certain folder inside the installed extension.
function download() { //only saves to downloads directory
var imgurl = "https://www.google.com.hk/images/srpr/logo11w.png";
console.log('download');
browser.downloads.download({url:imgurl},function(downloadId){
console.log("download begin, the downId is:" + downloadId);
});
}
I also tried the chrome download function above but that only works for the downloads folder not the extension folder.
Is there any way to make a custom updater?! I know we can't save to disk but any leniency or workarounds for the extension folder?! Even something silly like making a shell call to some dos (and linux/mac) thing that saves the file to the extension folder. I can fetch the files, just not save them.
Ok so I'll put it as an answer. This is the solution I'm leaning on which works for my scenario and I've listed some alternatives below:
Having the other files as separate extensions and giving the user an install link instead where they can install that extension, then those child extensions talk to the mother extension and they know the address to the resources in their child extension folder, so the mother gets the just the file locations from the children to load those assets from that folder. The child extensions are like bundles of those html and js with a background script which sends the addresses of these items to the mother.
https://developer.chrome.com/extensions/messaging#external
The drawback is that I'll have to see how that affects the urls like if I inject the html page from the child extension folder into the main interface using ajax then I can't use relative url's to any images in that 'cos the urls are relative to the mother extension folder.. I'll have to rewrite the child extension urls with the absolute paths into the html page to load images and js from the child extension html code which has relative urls.
Pros:
Cleaner and more persistent than indexeddb.
Files can be loaded normally from disk.
Cons:
User has to install separate extensions.
URL structure might be a bit confusing, need to rewrite urls if loading html from child. However this is only for image src's and where the javascript is loaded from so it's not such a big deal.
Other Possible Solutions:
Indexeddb which I'm already doing seems to be the preferred way of doing this but I really do not want to store every html asset in indexeddb. The upside is that while extensions need to be installed, this method can be done silently fetching and adding files without user interaction and indexeddb seems to be somewhat persistent. Might still end up using this because it is silent but having to load each asset from a database sounds like a nightmare.
The File Handle Api might have worked if I was working on Firefox only https://wiki.mozilla.org/WebAPI/FileHandleAPI
I haven't tried the shell copy, maybe if I fetch with ajax and then save to disk using some dos function and then doing different save functions for different OS systems.
Filesystem Api only saves to downloads and doesn't work for extensions anyways, so that's useless.
UPDATE
In windows there isn't any sudo, but this worked without admin priveleges for a subfolder (not on the C:\ root though). It would work for a linux only app very nicely. If I just wanted to save a file to a windows machine this might work.
Shell copy method would be to grab the contents of file with ajax from the local or remote location, output to DOS as a stream to save to file on windows. And do this for every operating system with a shell exec command or detect the OS and do that command. This way I can even put the files in the exact folder location.
Like say I make this sort of command from the contents:
//To append you can use >> instead of >
//folder seems necessary, can't save to root without admin
echo the content I want to save > C:\folder\textfile.txt
I thought of calling it using shell exec that only works in nodejs, so digging through the other answers on
How to execute shell command in Javascript
//full code to save file using javascript on windows
var shell = WScript.CreateObject("WScript.Shell");
shell.Run("echo content to save > C:\folder\textfile.txt");
The shell command doesn't seem to work. i can't find what this is for. There doesn't seem to be a shell command in regular javascript for windows. It seems to require IE ActiveX. Doesn't work with Firefox or Chrome.
Extensions can't modify their sources because the browser verifies them and resets/disables the extension if they change. Also, in Firefox the extensions aren't even unpacked.
The solution is actually quite trivial: save the code in any storage (localStorage, chrome.storage.local, IndexedDB) as a string and then add it in your extension page as a standard DOM script element. You'll have to relax the standard CSP a bit for that.
I'm thinking of writing a Cordova app which downloads websites so they can be read offline (like HTTrack for Windows). The main reason is lack of a good offline RSS reader for Windows 10 tablets.
I know in general what I would have to do but is there some framework which could simplify some of it?
So far I think I would need to do the following:
Download the HTML of a site
Get a list of all assets (CSS, JS, images, videos)
Download those assets
Replace asset URLs with new local ones.
The biggest problem is downloading the assets. It's not as straight forward as parsing the HTML for link, script, and img tags since CSS could have imports and JS could have ajax calls.
Also, how to decide which assets to download? I wouldn't want to waste time downloading ads..
Also there are some specific questions:
How should I display a downloaded page? My first thought is in an iFrame to prevent collisions.
Are there any legal problems? Especially if I were to publish the app?
How could I save the assets so they have a URL for including in the HTML?
Might it be better using a server to do the heavy lifting (parsing, rewriting, getting URLs etc.)? Are there tools for this already?
Does anyone have any pointers? Or do you think it's impractical?
Check out https://archivebox.io, it's an open-source, self-hosted tool that creates a local, static, browsable HTML clone of websites (it saves HTML, JS, media files, PDFs, screenshot, static assets and more).
It does most of what you want, including saving assets and media files with youtube-dl, wget, and chrome headless.
Is there a way to hold a large block of text, or images/videos, embedded in a FirefoxOS app, while directly accessing them from the app (similar to /res/raw/ in Android)? I don't see where the /data/ directory is being accessed in the example app.
There are many ways that you can do this:
Distribute your web app as a packaged app. In this scenario all your resource files are zipped up in a single file, available after install via a URL scheme described in the documentation.
The Application Cache allows you to instruct the browser to download files for offline use. I like Rob Hawkes' utility for generating appcache manifest files.
You can manage the data yourself by downloading the files via XMLHttpRequest and storing the data in an IndexedDB database or on the SD card via the DeviceStorage API.
I think that your best bet is the filehandle API, but more importantly keep in mind that a Firefox OS app is basically a website so you shouldn't be thinking as an android app that can carry it's media and so on.
Good luck
If you want to display images in a website you place images in the same root folder or sub folder. The same thing works with firefox OS.Place your images in your app folder and use them. If you want to use images from the mobile then you can use device Storage API .you can find the example here
I am using PhoneGap to develop an application for Android and iOS, and recently in a discussion about this technology, someone told me a seemingly brilliant idea that I can do background updates of my application without having to submit a new application to the app store.
The problem is that, being that I am still fairly new to the HTML5/CSS and Javascript world, I cannot figure out how to download files to my www directory for permanent storage. I can dynamically load JS code or HTML pages at runtime, but I want to create some javascript module that will find that a certain .css, .html, or .js file is out of date, download the new version of that file from some http or file server to the www directory, and then have that new file permanently saved so that it is available the next time the app is opened.
I feel like this should be simple, but I can't figure out how to do it. Thanks in advance.
In order to permanently save files to the devices you will need to make use of the PhoneGap File APIs. Periodic tasks can be achieved with a simple Javascript timer.