This repository has been archived by the owner on Oct 1, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a dummy electron app for testing
- Loading branch information
1 parent
47b5c21
commit 7981e9e
Showing
9 changed files
with
247 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
MP3 Encoder | ||
=============== | ||
|
||
Dummy app to test electron using an external process, coffee-script | ||
and backbone on both windows and OSX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name" : "mp3-encoder-demo", | ||
"version" : "0.1.0", | ||
"main" : "main.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
$ -> | ||
form = new EncodeFormView | ||
logsElem: $("div.logs") | ||
|
||
form.render().$el.appendTo $("div.form") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |