Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
Add a dummy electron app for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
anaisbetts committed Apr 11, 2016
1 parent 47b5c21 commit 7981e9e
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Expand Up @@ -26,8 +26,8 @@ build/Release
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
node_modules

lib
test-dist
docs
/lib
/test-dist
/docs

.DS_Store
5 changes: 5 additions & 0 deletions test/electron-app/README.md
@@ -0,0 +1,5 @@
MP3 Encoder
===============

Dummy app to test electron using an external process, coffee-script
and backbone on both windows and OSX
20 changes: 20 additions & 0 deletions test/electron-app/index.html
@@ -0,0 +1,20 @@
<html>
<head>
<title>MP3 Encoder</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="vendor/js/underscore.js"></script>
<script type="text/javascript" src="vendor/js/jquery.js"></script>
<script type="text/javascript" src="vendor/js/backbone.js"></script>
<script type="text/javascript" src="lib/main.js"></script>
<style>
span.error { color: red; }
span.good { color: green; }
</style>
</head>
<body>
<h1>Dummy MP3 encoder</h1>
<h2>Pick up a .wav file</h2>
<div class="form"></div>
<div class="logs"></div>
</body>
</html>
112 changes: 112 additions & 0 deletions test/electron-app/lib/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions test/electron-app/main.js
@@ -0,0 +1,33 @@
var app = require('app'); // Module to control application life.
var BrowserWindow = require('browser-window'); // Module to create native browser window.

// Report crashes to our server.
require('crash-reporter').start();

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed.
var mainWindow = null;

// Quit when all windows are closed.
app.on('window-all-closed', function() {
if (process.platform != 'darwin')
app.quit();
});

// This method will be called when Electron has done everything
// initialization and ready for creating browser windows.
app.on('ready', function() {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600});

// and load the index.html of the app.
mainWindow.loadUrl('file://' + __dirname + '/index.html');

// Emitted when the window is closed.
mainWindow.on('closed', function() {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
});
5 changes: 5 additions & 0 deletions test/electron-app/package.json
@@ -0,0 +1,5 @@
{
"name" : "mp3-encoder-demo",
"version" : "0.1.0",
"main" : "main.js"
}
5 changes: 5 additions & 0 deletions test/electron-app/src/main.coffee
@@ -0,0 +1,5 @@
$ ->
form = new EncodeFormView
logsElem: $("div.logs")

form.render().$el.appendTo $("div.form")
36 changes: 36 additions & 0 deletions test/electron-app/src/utils/encoder.coffee
@@ -0,0 +1,36 @@
{spawn} = require "child_process"
{platform} = require "os"
{chmodSync} = require "fs"


class Encoder
constructor: ({@source, @bitrate, @target, @log}) ->
@target ||= @source.replace /\.wav$/, ".mp3"
if @target == @source
@target = @target.replace(/\.([^.]+)$/, ' encoded.$1')

@bitrate ||= 128

switch platform()
when "darwin"
@pathToBin = "vendor/bin/osx/shineenc"
when "win32"
@pathToBin = "vendor/bin/win32/shineenc.exe"

# binary may not be executable due to zip compression..
chmodSync @pathToBin, 0o755

process: ->
@log "Starting encoding process.."

@child = spawn @pathToBin, ["-b", @bitrate, @source, @target]

@child.stdout.on "data", (data) =>
@log "#{data.toString().replace(/\n/g, '<br>')}"

@child.stderr.on "data", (data) =>
@log "ERROR: #{data.toString().replace(/\n/g, '<br>')}", 'error'

@child.on "exit", (code) =>
style = if code == 0 then 'good' else 'error'
@log "Encoding process exited with code: #{code}", style
28 changes: 28 additions & 0 deletions test/electron-app/src/views/form.coffee
@@ -0,0 +1,28 @@
class EncodeFormView extends Backbone.View
tagName: "form"
events:
"submit" : "onSubmit"

initialize: ({@logsElem}) ->

render: ->
@$el.html """
File: <input class="file" type="file" accept=".wav,.wave"><br>
Bitrate: <input class="bitrate" type="text" value="128"><br>
<input type="submit" value="Encode!">
"""

this

onSubmit: (e) ->
e.preventDefault()

data =
source: @$("input.file").val()
bitrate: parseInt @$("input.bitrate").val()
log: (data, type = 'info') =>
@logsElem.html "#{@logsElem.html()}<br><span class='#{type}'>#{data}</span>"

return console.log "no file!" unless data.source?

(new Encoder data).process()

0 comments on commit 7981e9e

Please sign in to comment.