Skip to content

Commit e07fa12

Browse files
authored
Merge pull request #20 from fukajun/set_icon
Set icon and version up electron
2 parents 90eb640 + f27cac0 commit e07fa12

File tree

19 files changed

+212
-158
lines changed

19 files changed

+212
-158
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
node_modules
2-
/main.js
3-
/index.js
42
/preload.js
53
.DS_Store
6-
/245cloud*
4+
/dist/*
5+
/build/*
6+
/*.zip

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,22 @@
22

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

5+
# development
6+
7+
```
8+
$ gulp
9+
```
10+
11+
and on other session
12+
13+
```
14+
$ npm start
15+
```
16+
17+
# build app
18+
19+
```
20+
$ npm run build
21+
```
22+
523
#### License [CC0 (Public Domain)](LICENSE.md)

build.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
DIST_DIR=./dist
3+
BUILD_DIR=./build
4+
5+
PKG_VERSION=`node -pe 'require("./package.json").version'`
6+
APP_NAME=`node -pe 'require("./package.json").name'`
7+
8+
echo "version: ${PKG_VERSION}"
9+
10+
# Clean npm_modules, *.js, *.html ...
11+
rm -rf ${BUILD_DIR}/*
12+
13+
gulp build
14+
15+
cp ./package.json ${BUILD_DIR}
16+
pushd ${BUILD_DIR} && npm install --production && popd
17+
18+
electron-packager ${BUILD_DIR} "${APP_NAME}" \
19+
--overwrite \
20+
--prune \
21+
--platform=darwin \
22+
--arch=x64 \
23+
--electron-version=1.6.6 \
24+
--build-version=${PKG_VERSION} \
25+
--icon=./icon.icns \
26+
--out=./${DIST_DIR}
27+
28+
cd ${DIST_DIR} && zip -r -y -q \
29+
"../${APP_NAME}-${PKG_VERSION}-darwin-x64.zip" \
30+
"./${APP_NAME}-darwin-x64"

build/.gitkeep

Whitespace-only changes.

dist/.gitkeep

Whitespace-only changes.

gulpfile.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ function errorHandler(err) {
1515
notifier.notify({title: 'gulp', message: 'start'})
1616

1717
gulp.task('build', function() {
18-
return gulp.src('./source/*.js')
19-
.on('error', errorHandler)
20-
.pipe($.babel({presets: ['es2015', 'react']}))
21-
.pipe(plumber({errorHandler: errorHandler}))
22-
.pipe(gulp.dest('./'))
18+
gulp.src( 'source/*.html' ).pipe( gulp.dest( 'build' ) )
19+
gulp.src( 'source/images/**' ).pipe( gulp.dest( 'build/images' ) )
20+
gulp.src( 'source/stylesheets/**' ).pipe( gulp.dest( 'build/stylesheets' ) )
21+
gulp.src('./source/*.js')
22+
.on('error', errorHandler)
23+
.pipe($.babel({presets: ['es2015', 'react']}))
24+
.pipe(plumber({errorHandler: errorHandler}))
25+
.pipe(gulp.dest('./build'))
2326
})
2427

2528
gulp.task('watch', function() {
File renamed without changes.

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"name": "245cloud-app",
3-
"version": "1.0.0",
2+
"name": "245cloud",
3+
"version": "1.1.0",
4+
"main": "index.js",
45
"description": "245cloud run on mac",
5-
"main": "main.js",
66
"scripts": {
7-
"start": "electron main.js",
8-
"build": "electron-packager . '245cloud' --platform=darwin --arch=x64 --version=1.2.8 --icon=images/icon.icns --prune --overwrite"
7+
"start": "cd ./build && NODE_ENV=development electron ./index.js",
8+
"build": "./build.sh"
99
},
1010
"repository": {
1111
"type": "git",
@@ -24,6 +24,8 @@
2424
"devDependencies": {
2525
"babel-preset-es2015": "^6.3.13",
2626
"babel-preset-react": "^6.3.13",
27+
"electron-packager": "^8.6.0",
28+
"electron-prebuilt": "^1.4.13",
2729
"gulp": "^3.9.0",
2830
"gulp-babel": "^6.1.1",
2931
"gulp-load-plugins": "^1.1.0",
@@ -32,8 +34,6 @@
3234
},
3335
"dependencies": {
3436
"d3": "^3.5.16",
35-
"electron-packager": "^5.1.1",
36-
"electron-prebuilt": "^1.2.8",
3737
"jquery": "^2.2.1",
3838
"menubar": "^5.0.0",
3939
"node-notifier": "^4.4.0",
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

index.html renamed to source/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<link rel="icon" href="./images/favicon.ico" type="image/vnd.microsoft.icon" />
77
<link rel="stylesheet" type="text/css" href="stylesheets/flaticon.css">
88
<link rel="stylesheet" type="text/css" href="stylesheets/app.css">
9-
<script src='index.js'></script>
9+
<script src='main.js'></script>
1010
</head>
1111

1212
<body class='245app'>

source/index.js

Lines changed: 128 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,132 @@
1-
import { ipcRenderer } from 'electron';
21
//
3-
// Renderer
4-
5-
document.addEventListener("DOMContentLoaded", ()=> {
6-
var quitIcon = document.querySelector('.js-quit-icon')
7-
var reloadIcon = document.querySelector('.js-reload-icon')
8-
quitIcon.addEventListener('click', ()=> {
9-
if(!confirm('終了しますか?')) {
10-
return
11-
}
12-
ipcRenderer.send('quit')
2+
// MainProcess
3+
'use strict';
4+
5+
const ACTIVE_MENUBAR_ICON = __dirname + '/images/active.png'
6+
const INACTIVE_MENUBAR_ICON = __dirname + '/images/inactive.png'
7+
const NOTIFY_ICON = __dirname + '/images/notify_icon.png'
8+
import menubar from 'menubar';
9+
import { app, ipcMain, globalShortcut, Menu } from 'electron';
10+
import notifier from 'node-notifier';
11+
import path from 'path'
12+
13+
const request = require('request');
14+
const mb = menubar({ icon: ACTIVE_MENUBAR_ICON, dir: __dirname });
15+
console.log(__dirname)
16+
17+
//const mb = menubar({ icon: ACTIVE_MENUBAR_ICON });
18+
mb.setOption('width', 500)
19+
20+
const switchIconUnread = ()=> {
21+
mb.tray.setImage(ACTIVE_MENUBAR_ICON )
22+
}
23+
const switchIconRead = ()=> {
24+
mb.tray.setImage(ACTIVE_MENUBAR_ICON )
25+
}
26+
const setTrayTitle = (title)=> {
27+
mb.tray.setTitle(title)
28+
}
29+
const initMenu = ()=> {
30+
var template = [{
31+
label: "Application",
32+
submenu: [
33+
{ label: "About Application", selector: "orderFrontStandardAboutPanel:" },
34+
{ type: "separator" },
35+
{ label: "Quit", accelerator: "Command+Q", click: function() { app.quit(); }}
36+
]}, {
37+
label: "Edit",
38+
submenu: [
39+
{ label: "Undo", accelerator: "CmdOrCtrl+Z", selector: "undo:" },
40+
{ label: "Redo", accelerator: "Shift+CmdOrCtrl+Z", selector: "redo:" },
41+
{ type: "separator" },
42+
{ label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:" },
43+
{ label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" },
44+
{ label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" },
45+
{ label: "Select All", accelerator: "CmdOrCtrl+A", selector: "selectAll:" }
46+
]}
47+
];
48+
49+
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
50+
}
51+
52+
const KEY_POMO_START = 'ctrl+shift+m'
53+
const KEY_TOGGLE_WINDOW = 'ctrl+shift+p'
54+
55+
mb.on('ready', function ready () {
56+
57+
var closeWindow = ()=> {
58+
mb.hideWindow();
59+
}
60+
var openWindow = ()=> {
61+
mb.showWindow(mb.tray.getBounds());
62+
}
63+
64+
ipcMain.on('renderer_init', function(event, arg) {
65+
66+
var sender = event.sender
67+
68+
//
69+
// Toggle window show and hide
70+
//
71+
// NOTE: Unregister shorcut key event.
72+
// Shortcut key is not left to the old webview after reload.
73+
globalShortcut.unregister(KEY_TOGGLE_WINDOW);
74+
globalShortcut.register(KEY_TOGGLE_WINDOW, ()=> {
75+
if(mb.window.isVisible()) {
76+
closeWindow();
77+
} else {
78+
openWindow();
79+
}
80+
});
81+
82+
//
83+
// Start pomodoro recently track
84+
globalShortcut.unregister(KEY_POMO_START);
85+
globalShortcut.register(KEY_POMO_START, ()=> {
86+
sender.send('pomo_start')
87+
});
88+
});
89+
90+
//
91+
// Setting ipc event
92+
ipcMain.on('notify', (event, title, message)=> {
93+
notifier.notify({
94+
title: title,
95+
icon: NOTIFY_ICON,
96+
message: message
97+
})
98+
});
99+
ipcMain.on('show_window', (event, arg)=> {
100+
openWindow();
101+
});
102+
ipcMain.on('set_title', (event, text)=> {
103+
setTrayTitle(text.trim())
104+
});
105+
ipcMain.on('mark_unread', (event, arg)=> {
106+
switchIconUnread();
107+
});
108+
ipcMain.on('quit', (event, arg)=> {
109+
app.quit();
110+
});
111+
ipcMain.on('reload', (event, arg)=> {
112+
let browserWindow = event.sender;
113+
browserWindow.reload()
114+
});
115+
notifier.on('click', (event, arg)=> {
116+
mb.showWindow();
117+
});
118+
mb.on('show', ()=> {
119+
setTimeout(()=> {
120+
switchIconRead();
121+
}, 1000);
13122
})
14-
reloadIcon.addEventListener('click', ()=> {
15-
if(!confirm('リロードしますか?')) {
16-
return
17-
}
18-
ipcRenderer.send('reload')
123+
mb.on('hide', ()=> {
124+
switchIconRead();
19125
})
20-
console.log('init')
126+
127+
mb.showWindow();
128+
mb.hideWindow();
129+
// NOTE: Comment out for display Dev tool
130+
initMenu();
131+
switchIconUnread();
21132
})

0 commit comments

Comments
 (0)