Standalone Javascript Application With Chromium

Standard

JavaScript is becoming more and more popular every day and I was wondering if I could make a standalone javaScript App. I knew that a Chromium (http://www.chromium.org/) portable package has a “kiosk” mode which disables many of the integrated UI.

Next I decided to use a Chrome App together with Chromium (Portable version) and managed (after several fails and testing) to make it run locally (without a custom build) with full NaCl (Native Client) support.

The generated app can also be published on Chrome Web store and many UI functionality can easily be programmed using Javascript like developing a web page. NaCl opens the possibility of using low level stuff when needed. The Chromium App allows some customizations via a “.ini” file named exactly as the main executable (mine was in App\AppInfo\Launcher) and mine looks something like this; (Documented at portableapps.com)

[Launch]
ProgramExecutable=Chromium\32\Chrome.exe
DirectoryMoveOK=yes
MinOS=XP
SingleAppInstance=false
CommandLineArguments=--enable-local-file-accesses "../../../start.html" --load-extension="../../../Main"
SplashTime=0

There is a folder named “Main” alongside the main executable. Above commands disable the splash screen, enable local (file:\\\) accesses, load the application who’s manifest is in Main folder and starts the browser from “start.html”.

The manifest is;

{
    "key": "***",
    "name": "Test App",
    "description": "",
    "version": "0.1",
    "manifest_version": 2,
    "app": {
        "launch": {
            "local_path": "index.html"
        }
     },
    "permissions": [
        "tabs"
    ]
}

We need tabs access to be able to close the application. “start.html” is there to be able to start our Chrome App in the first tab opened by Chromium and reads:

window.location = "chrome-extension://apdfllckaahabafndbhieahigkjlhalf/index.html";

Here, “apdfllckaahabafndbhieahigkjlhalf” is the AppId corresponding to the key in the App’s manifest.

In “index.html”, I have;

//disable context menu
document.addEventListener("contextmenu", function(e) {
    e.preventDefault();
});
//close new tabs
chrome.tabs.query({},function(a) {
    if(a.length > 1)
        chrome.tabs.remove(a[a.length-1].id);
});
//exit button
document.getElementById('exit_btn').onclick = function () {
chrome.tabs.getCurrent(function(a){
    chrome.tabs.remove(a.id);
})};

“exit_btn” successfully exits the app by closing the single available tab and the above code block prevents opening of new tabs when the application is re-executed while running.

Chromium shows the API key warning if none set and to prevent this I use an AutoHotKey script to set some Environment variables and start the application;

EnvSet, GOOGLE_API_KEY, no
EnvSet, GOOGLE_DEFAULT_CLIENT_ID, no
EnvSet, GOOGLE_DEFAULT_CLIENT_SECRET, no
Run App.exe

Finally, to disable developer tools, the “Preferences” file that is located under “Data\Profiles\Default” is edited and

"devtools": {
    "disabled": true,
    "split_location": 256
}

is added if not existant.

With these configuration, I’m able to start a custom web app fullscreen without any pre-installed software on Windows. I did not have time to test the same concept on any other operating system but I’m pretty sure that it’ll work similarly. Whit this tool at hand, using naCl and WebGl, even high (relatively) performance games can be made… Currently the only drawback is that chromium continues to run in the background indefinitely. Dev channel have a processes API to solve this problem here.

Raspberry Pi Film Camera

Standard

Found an old (actually late 70s) TV camera and did my own mod. Removed most of its guts. Removed the lens on the picamera and mounted the camera module on the lens of this monster. Writes videos to an external USB card reader. It is fully programmable so I can make timelapse, stop-motion and stuff.

Since the cost of a quality raspberry pi sound card is a little too expensive, I decided not to use this for daily shooting, instead I’ll use an external audio recorder with a clapperboard etc.

Runs on a Li-Po battery and can be used as long as 2 hr with 1500 mAh capacity. The old analogue iris mechanism was replaced with a mechanical one which can be seen in the upper part of the lens right integrated on the handle.

I’ve used many of the camera’s original switches and interfaces to control the pi over GPIOs.

Thinking of replacing the CRT viewfinder with an LCD screen which is on its way from china. Focusing with the onboard CRT is really hard. I’ll update as the new screen is mounted. (This modification is done, I’ll update soon)

One of the hardest part on the software side of matters was to make sure there are no dropped frames in the output. I’ve tried many methods to detect dropped frames without much success. Picamera firmware reports minus infinity integer occasionally as DTS and even getting hold of a good timestamp information was not possible at the time. Finally I’m rather convinced that picamera will not drop frames as long as the media write speed is sufficient. Haven’t tested it for long-time recording and a separate audio track but I’ll report the results as soon as I do.

As a final note, since the pi’s image sensor is so small the image output compared to a 35mm film, corresponds to about 120-130mm lens. Happily a wide angle adapter that fits the 57mm filter diameter is also on its way, which will widen the output to 60mm. (wider lens atapter get very pricy very quickly) (This modification is also done and I’ll update soon)

To summerize, this was a fun and challenging process and I’m rather impressed with the results. I’ll post any when I have time to shoot something meaningful.

Javascript based floppy image reader

Standard

Currently working on a hobby project on reading floppy disk images using javascript. These days javascript can do anything 80’s and 90’s computer can do. There are a lot of javascript based emulators already done and being developed and I was thinking of a similar project.

I wanted to work on some byte-stuff in my own way and floppyJS was born! 🙂 Considering the software for this purpose (WinImage, WinHex etc.) are paid software, an open source javascript version may be beneficial. 

I don’t know whether JMESS (http://jsmess.textfiles.com/) has any similar component (I should check in order not to re-invent the wheel) but floppyJS mainly aims inspecting/editing floppy images.

Maybe in later stages a disk image API to combine with any JS emulator may be developed, who knows…

Currently the code is rather messy and only supports FAT12 images. If it raises any attention and if anybody is interested, a more detailed and systematical coding scheme can be introduced with some documentation.

You can reach it on GitHub -> https://github.com/anacierdem/floppyJS

Diablo 2 Windows 7 fix

Standard

Wanted to play some Diablo 2 on my Windows 7 PC. The game claims that it is Win7 compatible but there are too many parameters, too many different hardware etc. and it rejected working properly. The screen was flickering in the game.

When I hit ESC the menu renders fine but in the game itself there were gliches of some sort. Additionally some sprites seemed out-of-gamma. For example blacks were not exactly black especially in the main menu. I looked up on the net for a solution but none have worked.

Here is the actual screenshot of the broken fullscreen Diablo:

diablo

Then I’ve decided to find mine 😛

I realized that it works fine in windowed mode (which can be done with a -window command paramter [Diablo II.exe -window]) and write a auto hotkey script to run Diablo 2 window fullscreen.

It simply starts the game windowed, removes window borders,maximize it and finally restricts the mouse in a 800×600 px area. The script can be found here. And for the lazy ones, the compiled script is here.

The same concept can be applied to other games rejecting to run flawlessly in fullscreen mode.