Using droidscript app as a standalone exe or js

914 views
Skip to first unread message

DistanceAnywhere

unread,
Oct 27, 2015, 7:23:29 PM10/27/15
to AndroidScript
So I made this really cool app to help me with work in keeping track of parking validations. My bosses eventually saw it, loved it, and now they want me to convert it into a standalone exe so they can run it straight off a Windows desktop. I told them it was simply not possible, but they like the app so much that they are basically telling me to find any means necessary to make it happen (even if it means learning another language and rewriting the whole thing). One of them has already told me to just start rewriting it. It took me weeks to accomplish, I really don't want to have to learn a new language and start from scratch. I even suggested using ARC Welder with a chrome browser, but that's not good enough for them. They want it one way: a double-click-and-go desktop application.

Is there any possible way to turn this code into it's own standalone exe or js so that it can run natively on Windows?

Thanks in advance for the help.

Paul Norman

unread,
Oct 28, 2015, 6:17:24 AM10/28/15
to AndroidScript
Check out the latter part of this article and the comments.

http://www.extremetech.com/computing/83812-run-android-apps-on-your-windows-pc-2

I have in the past used BlueStacks (mentioned) but experienced the ocassional freeze up mentioned, but mostly it was quite good.

Paul

Dave Smart

unread,
Oct 28, 2015, 6:51:28 AM10/28/15
to AndroidScript
HI, there a various options to make a port (conversion) more easy.

What bits of DroidScript are you using in your App?  

HTML or native controls?

Any database usage?

What version of Windows do they have?

DistanceAnywhere

unread,
Oct 28, 2015, 1:13:30 PM10/28/15
to AndroidScript
Thanks for the replies, guys.

@Paul Norman:
So I already started looking into BlueStacks. It seemed like a viable possibility, however, would it be able to launch by itself? Or would they have to open the emulator and then run the app? If it's the latter, they don't want it (same scenario with Arc Welder).

@Dave Smart:
The main Droidscript bits that I use for the app would probably boil down to buttons, layouts, and dialogues. I can post the code if necessary; I just assumed that was erroneous. And it's mostly native controls if not 100% native controls. As far as database usage, the app needs to write timestamps to a text file and then read values from that text file upon start-up. It works fine on my phone, but I can assume that might be problematic. Lastly, they're all using Windows 7, so that's good at least.

Dave Smart

unread,
Oct 28, 2015, 3:36:19 PM10/28/15
to androi...@googlegroups.com
OK, first of all, do your bosses know that Chrome Apps can be launched from outside the browser?  Once they know that, then they might be happy with an Arc Welder solution.

If that does not satisfy them, then I can think of 2 or 3 options if you want to stick with JavaScript:-

Option 1:

Convert your GUI elements to HTML and learn about .HTA files.  Most people don't know this, but if you take an .HTML file and rename it to .HTA then it will run as a standalone program on Windows with full permissions to the operating system (It runs the IE engine underneath).  You can then put some special XML tags at the top of the .HTA file to set the program icon and window border type and title etc.

Option 2:

Convert your GUI elements to HTML and use the NWJS framework to create an App that internally runs the Chrome browser engine (without the user knowing it ;)



Option 3:

Try out my unfinished and undocumented scripting framework (it's the Windows equivalent of DroidScript) which allows you to use JavaScript to easily create Windows Apps with support for most common windows GUI elements, Images, listviews, buttons, text, checkboxes, combo boxes + SQLite, SystemTray Icons, Encryption, DirectShow, GridView, 3rdParty COM objects, ActiveX, Networking, WebViews, Joystick, Zip, Canvas, Sound and more. This framework has lots of samples but no docs and I've only tested it on Win7 and Win8.1.


Option 1 has lots of online docs and samples, Option 2 is probably the most forward thinking, option 3 is probably the quickest and easiest for a DroidScript user to get to grips with if you don't have much HTML and CSS experience.

Regards
David







DistanceAnywhere

unread,
Oct 28, 2015, 4:43:58 PM10/28/15
to AndroidScript
Firstly, yes, my bosses know about Arc Welder launching outside the browser. That was actually how I first displayed it. They, for some silly reason, don't like having to launch it through Arc Welder/app launcher in the first place.

Secondly, Option 3 sounds like the most convenient option for me. Do you have a link?

Steve Garman

unread,
Oct 29, 2015, 3:25:20 AM10/29/15
to AndroidScript
I don't have Windows 7 available at the moment but have you tried right-clicking on your app in the Chrome Launcher to see if it will let you create a shortcut on the desktop and Start menu?

Dave Smart

unread,
Oct 30, 2015, 3:08:31 PM10/30/15
to androi...@googlegroups.com
Hi Guys,

I've put a 'taster' version of my JavaScript scripting framework for Windows at this location:-



And there is a discussion forum here:-


I have many more components available for this framework that I have not had time to include in this package yet, but if people think that this framework will be useful then I can add more of the other components via requests placed on the SmartScript forum.

These are the available components:-

Standard GUIs, System Utils, Filing, GridView, Canvas, SQLite, SystemTray Icons, Encryption, DirectShow, ActiveX, Networking, WebViews, Joystick, Zip, Folder Lister, Video Player, NXT Controller, Sound/Midi Player, Light weight WebServer.

Note: You can embed an IE browser control, just like in DroidScript (and access it's DOM too) and you can also use any 3rd party COM components or ActiveXs that you can find on the web too :)

Please bear in mind that this framework was created before DroidScript and never finished properly... but if someone finds it useful then that's great :)

Regards
David
 

DistanceAnywhere

unread,
Nov 4, 2015, 1:29:04 PM11/4/15
to AndroidScript
Alright, thank you again for all the replies and help!

So I downloaded smart script and gave it a try. My js file won't open with it, but I think this is a step in the right direction. It looks like it definitely has the potential to do exactly what I'm looking for, but I think this initial setback might be on my end. For instance, I'm not entirely sure how I'm supposed to use the smart script. I tried to follow the methods you outlined on the discussion board. I took my js file (from /DroidScript/[insert my apk name here]/), put it on the desired computer, moved it to the smart script directory, deleted the original main.js, renamed my js to "main," and double clicked smartscript.exe. Nothing happened. Something I noticed, though, unlike your example js files, is that my js file is not separated line-by-line like it should be. What was easily over a hundred lines of code has been jumbled into around ten lines when I open it with notepad. This could just be how DroidScript was intended to read this js file, I have no idea. Anyways, If I accurately separate the lines, do you think it would be able to open? Or is it another issue altogether?

Dave Smart

unread,
Nov 4, 2015, 1:52:54 PM11/4/15
to AndroidScript
Hi,

It's not going to be as simple as that I'm afraid.  You can't just drop DroidScript code into SmartScript.  The controls are different and the methods and properties on them are all different.  

You will have to convert your code by hand, replacing all the DroidScript layouts and controls with SmartScript controls.  Your 'pure' JavaScript functions will still work the same, but anywhere you have accessed graphical controls or the file system or the internet etc. you will have to change those bits of code.

If you want your *.js files to execute on double click... you need to associate that file extension with SmartScript.exe by using the 'Open With' context menu in file explorer.  That can be convenient, but you don't really need to do that if you just edit the main.js file.

Regards
David

DistanceAnywhere

unread,
Nov 9, 2015, 1:44:53 PM11/9/15
to AndroidScript
Oh, I see. Well, I went back to ARC Welder to try what you originally suggested (launching it as an arc welder shortcut). It actually works better than i expected, and i think my bosses won't know the difference. The only problem, which is actually a big problem, is that when the program runs in ARC Welder, it's not able to use app.WriteFile or even access the PC directory at all. My program is almost completely dependent on a log file that it writes to time-stamp button presses and accurately log and relay information so i really need to find a solution to that issue before ARC Welder becomes it's official home.  Do you know of any way to fix this issue? I've done some research and have tried changing enableExternalDirectory to true and then choosing a directory, but my program still refuses to write or read to/from that directory. It seems that the only result from doing all that is the creation of two folders: "Android" and a folder with the name of my program. The Android folder has a few sub folders but it leads to nothing and the other folder is empty as well.

Dave Smart

unread,
Nov 9, 2015, 2:01:11 PM11/9/15
to AndroidScript
Hi,

When you built your Arc Welded app (with the enableExternalDirectory ) option, did you get prompted to choose a folder when you first ran it?

You should be able to choose a folder which acts as a substitute for you phone's sdcard.  You should be able to save things to that folder (in theory).  You can change that folder by clicking on the top left folder icon on the Arc Welded App.

You might like to try experimenting with our "Droid Runner" (Arc Welded App) to see what is possible.

Regards
David

DistanceAnywhere

unread,
Nov 9, 2015, 2:23:02 PM11/9/15
to AndroidScript
Yes, I get the prompt to choose a directory folder. Unfortunately, when I choose a folder, the program only writes two blank folders to the directory. It does not write or read anything to those folders. I understand that it's supposed to mimic the phone's sd card, but do I need to designate the name of the folder that I'm writing to as "sd card?" For instance, I have a folder called "Arc Welder Test" on the desktop. At the startup of my app, it asks for 2 file paths inputted by the user through text edits: the time-stamp log file path (and consequently the name; ie. C:\Users\ME\Desktop\Arc Welder Test\testlog.txt) and a logo picture file path. I've tried designating every folder inside the created "Android" folder, and I've tried the same with the other self-titled folder. I have not, however, tried naming it "sd card" or anything along those lines. Do you think that would help?

John TZ

unread,
Nov 11, 2015, 5:01:02 AM11/11/15
to AndroidScript
Hi DistanceAnywhere,
Have you tried to set the path to a folder without 'blank'? As we know some applications couldn't recognize that kind of folder. Try to put it at only st like 'C:\test' and maybe it will solve the problem??

DistanceAnywhere

unread,
Nov 12, 2015, 2:38:37 PM11/12/15
to DroidScript
Thanks for the reply!

Okay, here's what I did. I started out by making a new folder in C:\ called "test." Then, I threw my .apk into C:\test\. Next, I launched Arc Welder, pointed it to my .apk, typed "{"enableExternalDirectory": true} in the add metadata section, and clicked download zip. I then extracted the zip file right there at C:\test\ and deleted the zip file. After that, I opened chrome and went to chrome://extensions, enabled developer mode, and clicked "Load unpacked extension..." I chose my C:\test\ directory and then launched my app from the extensions page. My app launched and I wrote "C:\test\mylogo.png" for the logo path and "C:\test\log.txt" for the timestamp log.

My results, unfortunately, were the same as before. My app did not read the logo file, and it did not write the timestamp log file.

I'm not sure what to do. I'm so close I can taste it!

Dave Smart

unread,
Nov 13, 2015, 8:42:25 AM11/13/15
to DroidScript
Try writing to the App private directory using the app.GetPrivateFolder() method.

DistanceAnywhere

unread,
Nov 13, 2015, 12:28:54 PM11/13/15
to DroidScript
Alright, I just tried quickly integrating the app.GetPrivateFolder() method, and it seems to have no effect whatsoever once I build the .apk and launch the app on the PC. As of now, I'm running a test build that alerts app.GetPrivateFolder at the start of the program. It comes up as /data/data/com.smartphoneremote.androidscriptfree/app_PV (I named it "PV") on both my phone and on the PC.

Dave Smart

unread,
Nov 14, 2015, 9:07:41 AM11/14/15
to DroidScript
Did you try writing to the folder?  The files must get written somewhere on your PC.

DistanceAnywhere

unread,
Nov 16, 2015, 12:33:14 PM11/16/15
to DroidScript
I'm not sure I understand what folder you're talking about. There is no data/data/com.smartphoneremote.androidscriptfree/app_PV for me to write to on the PC.

Steve Garman

unread,
Nov 16, 2015, 12:44:38 PM11/16/15
to DroidScript
Dave is suggesting you write from your APK and see where the file appears.

Try adding some temporary code to your app like the code below to see whether the write works.

If it does, you should be able to find the folder and file.


var fldr = app.GetPrivateFolder("sjgfold");
var fil = fldr+"/sjgfile";
var reddit;
app.WriteFile(fil,"testing");
alert("Written");
reddit=app.ReadFile(fil);
txt.SetText(reddit);

DistanceAnywhere

unread,
Nov 16, 2015, 3:50:14 PM11/16/15
to DroidScript
Here's an extreme nutshell of the code I used to try to implement your suggestion:

---------------------------------------------------------------------------------------------------------------------------------------------------------

var Prvt = app.GetPrivateFolder("PV");

var logpath = Prvt + "/PVlog.txt";

alert(logpath);

if(app.FileExists(logpath)){
alert("exists");
} else {
alert("doesn't exist");
}

if(logpath != null){
app.WriteFile(logpath, "a bunch of variables" + "various iterations of etc.GetText()", "Append");
}

---------------------------------------------------------------------------------------------------------------------------------------------------------

I have no app.ReadFile because I don't want the program to read it. The text output is best read outside the program in my opinion.

When I ran this on the PC, it first reads "/data/data/com.smartphoneremote.androidscriptfree/app_PV/PVlog.txt" then reads "doesn't exist". This is working as intended because the app.WriteFile methods are occurring on button presses after the alerts; and thus, the file should not exist before any of the buttons are pressed (or essentially on the program's first play-through). The program then runs normally, and I press the buttons that are supposed to trigger the app.WriteFile methods. Next, I close the program and relaunch it.
Now, theoretically the file should exist somewhere in the computer at the variable, "logpath." When I run the program for the second time; however, it reads "/data/data/com.smartphoneremote.androidscriptfree/app_PV/PVlog.txt" as intended, then reads "doesn't exist".

This is the problem.

Apparently nothing has been written to the PC. On my phone, the second play-through yields "/data/data/com.smartphoneremote.androidscriptfree/app_PV/PVlog.txt" and "exists" all as intended. I can't seem to access /data/data/ on my phone without rooting it, but I'm assured by the program that it is there and it exists. I'm sure I could use app.ReadFile to read the output if necessary, but only on my phone. If it reads "doesn't exist" on the PC then there is no way for me to read it or append to it.
Reply all
Reply to author
Forward
0 new messages