Skip to content
Permalink
Browse files

embed welcome screen into tabbed editor, load last project, add menu

  • Loading branch information...
mmckegg committed Sep 11, 2016
1 parent 2a96c4f commit a5c35dcdcf50977df53f4d69869a63ff95886d51
Showing with 233 additions and 347 deletions.
  1. +4 −1 index.js
  2. +14 −116 lib/menu.js
  3. +77 −87 main.js
  4. +2 −14 nodes/project/tabbed-editor.js
  5. +63 −0 nodes/project/welcome.js
  6. +2 −0 package.json
  7. +71 −60 styles/choose-project.mcss
  8. +0 −69 views/welcome.html
@@ -17,6 +17,8 @@ var renderNode = require('lib/render-node')
var MidiStream = require('web-midi')
var PeriodicWaves = require('lib/periodic-waves')

var version = require('./package.json').version

// apply css styles
insertCss(require('./styles'))
electron.webFrame.setZoomLevelLimits(1, 1)
@@ -64,7 +66,8 @@ var rootContext = window.rootContext = {
midiPorts: midiPorts,
nodes: nodes.objectLookup,
nodeInfo: nodes,
zoom: Property(1.1)
zoom: Property(1.1),
version: version
}

watch(rootContext.zoom, function (value) {
@@ -1,118 +1,16 @@
var electron = require('electron')
var BrowserWindow = electron.BrowserWindow
var defaultMenu = require('electron-default-menu')

module.exports = [
{
label: 'Loop Drop',
submenu: [
{
label: 'Services',
submenu: []
},
{
type: 'separator'
},
{
label: 'Hide Loop Drop',
accelerator: 'Command+H',
selector: 'hide:'
},
{
label: 'Hide Others',
accelerator: 'Command+Shift+H',
selector: 'hideOtherApplications:'
},
{
label: 'Show All',
selector: 'unhideAllApplications:'
},
{
type: 'separator'
},
{
label: 'Quit',
accelerator: 'Command+Q',
click: function() { electron.app.quit(); }
},
]
},
{
label: 'Edit',
submenu: [
{
label: 'Undo',
accelerator: 'Command+Z',
selector: 'undo:'
},
{
label: 'Redo',
accelerator: 'Shift+Command+Z',
selector: 'redo:'
},
{
type: 'separator'
},
{
label: 'Cut',
accelerator: 'Command+X',
selector: 'cut:'
},
{
label: 'Copy',
accelerator: 'Command+C',
selector: 'copy:'
},
{
label: 'Paste',
accelerator: 'Command+V',
selector: 'paste:'
},
{
label: 'Select All',
accelerator: 'Command+A',
selector: 'selectAll:'
},
]
},
{
label: 'View',
submenu: [
{
label: 'Reload',
accelerator: 'Command+R',
click: function() { BrowserWindow.getFocusedWindow().webContents.send('reload'); }
},
{
label: 'Toggle DevTools',
accelerator: 'Alt+Command+I',
click: function() { BrowserWindow.getFocusedWindow().toggleDevTools(); }
},
]
},
{
label: 'Window',
submenu: [
{
label: 'Minimize',
accelerator: 'Command+M',
selector: 'performMiniaturize:'
},
{
label: 'Close',
accelerator: 'Command+W',
selector: 'performClose:'
},
{
type: 'separator'
},
{
label: 'Bring All to Front',
selector: 'arrangeInFront:'
},
]
},
{
label: 'Help',
submenu: []
},
]
var menu = defaultMenu(electron.app, electron.shell)
menu.splice(1, 0, {
label: 'Project',
submenu: [
{
label: 'New Project...',
click: (item, focusedWindow) => {
electron.dialog.showMessageBox({ message: 'Do something', buttons: ['OK'] })
}
}
]
})
module.exports = menu
164 main.js
@@ -1,96 +1,91 @@
var electron = require('electron')
var defaultMenu = require('electron-default-menu')
var BrowserWindow = electron.BrowserWindow
var fs = require('fs')
var Menu = electron.Menu
var menu = Menu.buildFromTemplate(require('lib/menu'))
var join = require('path').join

var welcomeWindow = null
var mainWindow = null
var currentProject = null
var quiting = false
var loading = false
var storage = require('electron-json-storage')

// expose manual gc()
electron.app.commandLine.appendSwitch('js-flags', '--expose_gc')

electron.app.on('before-quit', function () {
quiting = true
var menu = defaultMenu(electron.app, electron.shell)
menu.splice(1, 0, {
label: 'Project',
submenu: [
{ label: 'New Project...', click: newProject },
{ label: 'Choose Project...', click: chooseProject },
{ type: 'separator' },
{ label: 'Load Demo Project', click: loadDemoProject }
]
})

electron.ipcMain.on('choose-project', function (event, arg) {
if (arg === 'new') {
electron.dialog.showSaveDialog({
title: 'Create New Project'
}, function (path) {
if (path) {
createProject(path)
}
})
} else if (arg === 'demo') {
loadProject(getDemoProjectPath())
} else if (arg === 'browse') {
electron.dialog.showOpenDialog({
title: 'Browse for Project Folder',
properties: [ 'openDirectory' ]
}, function (paths) {
if (paths && paths.length) {
loadProject(paths[0])
}
})
} else {
chooseProject()
}
})
menu.find(m => m.label === 'View').submenu.find(m => m.label === 'Reload').click = function () {
BrowserWindow.getFocusedWindow().webContents.send('reload')
}

function newProject () {
electron.dialog.showSaveDialog({
title: 'Create New Project',
buttonLabel: 'Create Project'
}, function (path) {
if (path) {
createProject(path)
}
})
}

function chooseProject () {
electron.dialog.showOpenDialog({
title: 'Browse for Project Folder',
buttonLabel: 'Load Project',
properties: [ 'openDirectory' ]
}, function (paths) {
if (paths && paths.length) {
loadProject(paths[0])
}
})
}

function loadDemoProject () {
loadProject(getDemoProjectPath())
}

function loadLastProject () {
storage.get('lastProject', function (err, path) {
if (err) throw err
if (typeof path === 'string' && fs.existsSync(path)) {
loadProject(path)
} else {
loadDemoProject()
}
})
}

electron.ipcMain.on('new-project', newProject)
electron.ipcMain.on('choose-project', chooseProject)
electron.ipcMain.on('load-demo-project', loadDemoProject)

electron.ipcMain.on('loaded', function (event, arg) {
event.sender.send('load-project', currentProject)
})

electron.app.on('window-all-closed', function () {
electron.app.quit()
if (!loading) {
mainWindow = null
electron.app.quit()
}
})

electron.app.on('ready', function () {
if (process.platform === 'darwin') {
Menu.setApplicationMenu(menu)
}
chooseProject()
Menu.setApplicationMenu(Menu.buildFromTemplate(menu))
loadLastProject()
})

function chooseProject () {
if (mainWindow) {
mainWindow.close()
}

if (welcomeWindow) {
welcomeWindow.show()
} else {
welcomeWindow = new BrowserWindow({
title: 'Choose Project',
acceptFirstMouse: true,
width: 500,
height: 550,
show: false,
backgroundColor: '#444'
})

welcomeWindow.once('ready-to-show', function () {
welcomeWindow.show()
})

welcomeWindow.webContents.on('will-navigate', function (e, url) {
e.preventDefault()
electron.shell.openExternal(url)
})

welcomeWindow.loadURL('file://' + __dirname + '/views/welcome.html')

welcomeWindow.on('closed', function () {
welcomeWindow = null
})
}
}

function createProject (path) {
fs.mkdir(path, function (err) {
if (err) throw err
@@ -115,17 +110,12 @@ function getDemoProjectPath () {
}

function loadProject (path) {
if (mainWindow) {
mainWindow.close()
}

if (welcomeWindow) {
welcomeWindow.hide()
}
loading = true

storage.set('lastProject', path)
currentProject = path

mainWindow = new BrowserWindow({
var window = new BrowserWindow({
width: 1400,
height: 900,
title: path + ' — Loop Drop',
@@ -138,25 +128,25 @@ function loadProject (path) {
backgroundColor: '#444'
})

mainWindow.once('ready-to-show', function () {
mainWindow.show()
window.once('ready-to-show', function () {
window.show()
loading = false
})

mainWindow.webContents.on('will-navigate', function (e) {
window.webContents.on('will-navigate', function (e) {
e.preventDefault()
})

mainWindow.webContents.on('will-navigate', function (e, url) {
window.webContents.on('will-navigate', function (e, url) {
e.preventDefault()
electron.shell.openExternal(url)
})

mainWindow.loadURL('file://' + __dirname + '/views/window.html')
window.loadURL('file://' + __dirname + '/views/window.html')

mainWindow.on('closed', function () {
mainWindow = null
if (!quiting) {
chooseProject()
}
})
if (mainWindow) {
mainWindow.close()
}

mainWindow = window
}

0 comments on commit a5c35dc

Please sign in to comment.
You can’t perform that action at this time.