Skip to content

Commit

Permalink
Merge pull request #20 from fukajun/set_icon
Browse files Browse the repository at this point in the history
Set icon and version up electron
  • Loading branch information
fukajun committed Apr 13, 2017
2 parents 90eb640 + f27cac0 commit e07fa12
Show file tree
Hide file tree
Showing 19 changed files with 212 additions and 158 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
node_modules
/main.js
/index.js
/preload.js
.DS_Store
/245cloud*
/dist/*
/build/*
/*.zip
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,22 @@

**245cloud run on your pc and mac**

# development

```
$ gulp
```

and on other session

```
$ npm start
```

# build app

```
$ npm run build
```

#### License [CC0 (Public Domain)](LICENSE.md)
30 changes: 30 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
DIST_DIR=./dist
BUILD_DIR=./build

PKG_VERSION=`node -pe 'require("./package.json").version'`
APP_NAME=`node -pe 'require("./package.json").name'`

echo "version: ${PKG_VERSION}"

# Clean npm_modules, *.js, *.html ...
rm -rf ${BUILD_DIR}/*

gulp build

cp ./package.json ${BUILD_DIR}
pushd ${BUILD_DIR} && npm install --production && popd

electron-packager ${BUILD_DIR} "${APP_NAME}" \
--overwrite \
--prune \
--platform=darwin \
--arch=x64 \
--electron-version=1.6.6 \
--build-version=${PKG_VERSION} \
--icon=./icon.icns \
--out=./${DIST_DIR}

cd ${DIST_DIR} && zip -r -y -q \
"../${APP_NAME}-${PKG_VERSION}-darwin-x64.zip" \
"./${APP_NAME}-darwin-x64"
Empty file added build/.gitkeep
Empty file.
Empty file added dist/.gitkeep
Empty file.
13 changes: 8 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ function errorHandler(err) {
notifier.notify({title: 'gulp', message: 'start'})

gulp.task('build', function() {
return gulp.src('./source/*.js')
.on('error', errorHandler)
.pipe($.babel({presets: ['es2015', 'react']}))
.pipe(plumber({errorHandler: errorHandler}))
.pipe(gulp.dest('./'))
gulp.src( 'source/*.html' ).pipe( gulp.dest( 'build' ) )
gulp.src( 'source/images/**' ).pipe( gulp.dest( 'build/images' ) )
gulp.src( 'source/stylesheets/**' ).pipe( gulp.dest( 'build/stylesheets' ) )
gulp.src('./source/*.js')
.on('error', errorHandler)
.pipe($.babel({presets: ['es2015', 'react']}))
.pipe(plumber({errorHandler: errorHandler}))
.pipe(gulp.dest('./build'))
})

gulp.task('watch', function() {
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "245cloud-app",
"version": "1.0.0",
"name": "245cloud",
"version": "1.1.0",
"main": "index.js",
"description": "245cloud run on mac",
"main": "main.js",
"scripts": {
"start": "electron main.js",
"build": "electron-packager . '245cloud' --platform=darwin --arch=x64 --version=1.2.8 --icon=images/icon.icns --prune --overwrite"
"start": "cd ./build && NODE_ENV=development electron ./index.js",
"build": "./build.sh"
},
"repository": {
"type": "git",
Expand All @@ -24,6 +24,8 @@
"devDependencies": {
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"electron-packager": "^8.6.0",
"electron-prebuilt": "^1.4.13",
"gulp": "^3.9.0",
"gulp-babel": "^6.1.1",
"gulp-load-plugins": "^1.1.0",
Expand All @@ -32,8 +34,6 @@
},
"dependencies": {
"d3": "^3.5.16",
"electron-packager": "^5.1.1",
"electron-prebuilt": "^1.2.8",
"jquery": "^2.2.1",
"menubar": "^5.0.0",
"node-notifier": "^4.4.0",
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion index.html → source/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<link rel="icon" href="./images/favicon.ico" type="image/vnd.microsoft.icon" />
<link rel="stylesheet" type="text/css" href="stylesheets/flaticon.css">
<link rel="stylesheet" type="text/css" href="stylesheets/app.css">
<script src='index.js'></script>
<script src='main.js'></script>
</head>

<body class='245app'>
Expand Down
145 changes: 128 additions & 17 deletions source/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,132 @@
import { ipcRenderer } from 'electron';
//
// Renderer

document.addEventListener("DOMContentLoaded", ()=> {
var quitIcon = document.querySelector('.js-quit-icon')
var reloadIcon = document.querySelector('.js-reload-icon')
quitIcon.addEventListener('click', ()=> {
if(!confirm('終了しますか?')) {
return
}
ipcRenderer.send('quit')
// MainProcess
'use strict';

const ACTIVE_MENUBAR_ICON = __dirname + '/images/active.png'
const INACTIVE_MENUBAR_ICON = __dirname + '/images/inactive.png'
const NOTIFY_ICON = __dirname + '/images/notify_icon.png'
import menubar from 'menubar';
import { app, ipcMain, globalShortcut, Menu } from 'electron';
import notifier from 'node-notifier';
import path from 'path'

const request = require('request');
const mb = menubar({ icon: ACTIVE_MENUBAR_ICON, dir: __dirname });
console.log(__dirname)

//const mb = menubar({ icon: ACTIVE_MENUBAR_ICON });
mb.setOption('width', 500)

const switchIconUnread = ()=> {
mb.tray.setImage(ACTIVE_MENUBAR_ICON )
}
const switchIconRead = ()=> {
mb.tray.setImage(ACTIVE_MENUBAR_ICON )
}
const setTrayTitle = (title)=> {
mb.tray.setTitle(title)
}
const initMenu = ()=> {
var template = [{
label: "Application",
submenu: [
{ label: "About Application", selector: "orderFrontStandardAboutPanel:" },
{ type: "separator" },
{ label: "Quit", accelerator: "Command+Q", click: function() { app.quit(); }}
]}, {
label: "Edit",
submenu: [
{ label: "Undo", accelerator: "CmdOrCtrl+Z", selector: "undo:" },
{ label: "Redo", accelerator: "Shift+CmdOrCtrl+Z", selector: "redo:" },
{ type: "separator" },
{ label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:" },
{ label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" },
{ label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" },
{ label: "Select All", accelerator: "CmdOrCtrl+A", selector: "selectAll:" }
]}
];

Menu.setApplicationMenu(Menu.buildFromTemplate(template));
}

const KEY_POMO_START = 'ctrl+shift+m'
const KEY_TOGGLE_WINDOW = 'ctrl+shift+p'

mb.on('ready', function ready () {

var closeWindow = ()=> {
mb.hideWindow();
}
var openWindow = ()=> {
mb.showWindow(mb.tray.getBounds());
}

ipcMain.on('renderer_init', function(event, arg) {

var sender = event.sender

//
// Toggle window show and hide
//
// NOTE: Unregister shorcut key event.
// Shortcut key is not left to the old webview after reload.
globalShortcut.unregister(KEY_TOGGLE_WINDOW);
globalShortcut.register(KEY_TOGGLE_WINDOW, ()=> {
if(mb.window.isVisible()) {
closeWindow();
} else {
openWindow();
}
});

//
// Start pomodoro recently track
globalShortcut.unregister(KEY_POMO_START);
globalShortcut.register(KEY_POMO_START, ()=> {
sender.send('pomo_start')
});
});

//
// Setting ipc event
ipcMain.on('notify', (event, title, message)=> {
notifier.notify({
title: title,
icon: NOTIFY_ICON,
message: message
})
});
ipcMain.on('show_window', (event, arg)=> {
openWindow();
});
ipcMain.on('set_title', (event, text)=> {
setTrayTitle(text.trim())
});
ipcMain.on('mark_unread', (event, arg)=> {
switchIconUnread();
});
ipcMain.on('quit', (event, arg)=> {
app.quit();
});
ipcMain.on('reload', (event, arg)=> {
let browserWindow = event.sender;
browserWindow.reload()
});
notifier.on('click', (event, arg)=> {
mb.showWindow();
});
mb.on('show', ()=> {
setTimeout(()=> {
switchIconRead();
}, 1000);
})
reloadIcon.addEventListener('click', ()=> {
if(!confirm('リロードしますか?')) {
return
}
ipcRenderer.send('reload')
mb.on('hide', ()=> {
switchIconRead();
})
console.log('init')

mb.showWindow();
mb.hideWindow();
// NOTE: Comment out for display Dev tool
initMenu();
switchIconUnread();
})

0 comments on commit e07fa12

Please sign in to comment.