forked from hainproject/hain
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Heejin
committed
Mar 15, 2016
0 parents
commit 201c457
Showing
51 changed files
with
3,022 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["es2015", "react"] | ||
} |
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 @@ | ||
{ | ||
"extends": "airbnb/base", | ||
"rules": { | ||
"comma-dangle": ["error", "never"], | ||
"no-unused-vars": "warn", | ||
"camelcase": "off", | ||
"object-shorthand": "off", | ||
"guard-for-in": "warn", | ||
"arrow-body-style": "off", | ||
"consistent-return": "warn", | ||
"no-throw-literal": "warn", | ||
"quote-props": "off", | ||
"new-cap": "warn", | ||
"default-case": "off", | ||
"no-empty": "warn", | ||
"curly": "off", | ||
"padded-blocks": "off", | ||
"no-use-before-define": "warn" | ||
} | ||
} |
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,12 @@ | ||
node_modules | ||
/.vscode | ||
/main/ | ||
/_localStorage/ | ||
/dist/app.bundle.js | ||
|
||
/platform-util/build | ||
/platform-util/node_modules | ||
|
||
/plugins/ | ||
|
||
/debug.log |
Binary file not shown.
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,17 @@ | ||
<html> | ||
|
||
<head> | ||
<title>fred</title> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"> | ||
<script type="text/javascript"> | ||
window.$ = window.jQuery = require('jquery'); | ||
</script> | ||
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-scrollTo/2.1.0/jquery.scrollTo.min.js"></script> | ||
</head> | ||
|
||
<body style="margin: 55px 12px 12px 12px; overflow: hidden"> | ||
<div id="app"></div> | ||
<script src="app.bundle.js"></script> | ||
</body> | ||
|
||
</html> |
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,38 @@ | ||
'use strict'; | ||
|
||
const gulp = require('gulp'); | ||
const gutil = require('gulp-util'); | ||
const babel = require('gulp-babel'); | ||
const sourcemaps = require('gulp-sourcemaps'); | ||
const shell = require('gulp-shell'); | ||
|
||
const webpack = require('webpack'); | ||
|
||
gulp.task('main', () => { | ||
gulp.src('./main-es6/**/*.js') | ||
.pipe(sourcemaps.init()) | ||
.pipe(babel({ | ||
presets: ['es2015', 'react'] | ||
})) | ||
.pipe(sourcemaps.write()) | ||
.pipe(gulp.dest('main')); | ||
gulp.src('./main-es6/**/*.json') | ||
.pipe(gulp.dest('main')); | ||
}); | ||
|
||
gulp.task('renderer', (complete) => { | ||
webpack(require('./webpack.config.js'), (err, stats) => { | ||
if (err) { | ||
throw new gutil.PluginError('webpack', err); | ||
} | ||
gutil.log('webpack', stats.toString()); | ||
complete(); | ||
}); | ||
}); | ||
|
||
gulp.task('watch', ['main', 'renderer'], () => { | ||
gulp.watch('./main-es6/**/*.js', ['main']); | ||
gulp.watch('./renderer/**/*', ['renderer']); | ||
}); | ||
|
||
gulp.task('default', ['main', 'renderer']); |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
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,86 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
const electron = require('electron'); | ||
const cp = require('child_process'); | ||
|
||
const dialog = electron.dialog; | ||
const app = electron.app; | ||
const globalShortcut = electron.globalShortcut; | ||
|
||
const logger = require('./logger').create('main'); | ||
|
||
const window = require('./window'); | ||
const server = require('./server'); | ||
const iconProtocol = require('./icon-protocol'); | ||
const toast = require('./services/toast'); | ||
const autolaunch = require('./autolaunch'); | ||
|
||
function registerShortcut() { | ||
globalShortcut.register('alt+space', () => { | ||
if (window.isContentLoading() || server.isLoading()) { | ||
logger.log('please wait a seconds, you can use shortcut after loaded'); | ||
return; | ||
} | ||
window.showWindowOnCenter(); | ||
}); | ||
} | ||
|
||
let _isRestarting = false; | ||
|
||
const shouldSetAutolaunch = (_.includes(process.argv, '--setautolaunch')); | ||
if (shouldSetAutolaunch) { | ||
autolaunch.activate(); | ||
} | ||
|
||
const isRestarted = (_.includes(process.argv, '--restarted')); | ||
const shouldQuit = app.makeSingleInstance((cmdLine, workingDir) => { | ||
if (_isRestarting) | ||
return; | ||
window.showWindowOnCenter(); | ||
}); | ||
|
||
if (shouldQuit && !isRestarted) { | ||
app.quit(); | ||
} else { | ||
app.on('ready', () => { | ||
window.createTray(); | ||
server.start().then(() => { | ||
registerShortcut(); | ||
window.createWindow(() => { | ||
if (isRestarted) { | ||
window.showWindowOnCenter(); | ||
toast('restarted'); | ||
} | ||
}); | ||
}).catch((err) => { | ||
logger.log(err); | ||
dialog.showErrorBox('unhandled error occured!', err); | ||
app.quit(); | ||
}); | ||
}); | ||
|
||
app.on('will-quit', () => { | ||
globalShortcut.unregisterAll(); | ||
window.destroyRefs(); | ||
}); | ||
|
||
iconProtocol.register(); | ||
} | ||
|
||
function restart() { | ||
if (_isRestarting) | ||
return; | ||
_isRestarting = true; | ||
|
||
const argv = [].concat(process.argv); | ||
if (!_.includes(argv, '--restarted')) { | ||
argv.push('--restarted'); | ||
} | ||
cp.exec(argv.join(' ')); | ||
setTimeout(() => app.quit(), 500); | ||
} | ||
|
||
module.exports = { | ||
restart: restart | ||
}; |
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,54 @@ | ||
'use strict'; | ||
|
||
const co = require('co'); | ||
const Registry = require('winreg'); | ||
const regKey = new Registry({ | ||
hive: Registry.HKCU, | ||
key: '\\Software\\Microsoft\\Windows\\CurrentVersion\\Run' | ||
}); | ||
|
||
const VALUE_NAME = 'Hain'; | ||
|
||
function activate() { | ||
return new Promise((resolve, reject) => { | ||
regKey.set(VALUE_NAME, Registry.REG_SZ, `"${process.execPath}"`, (err) => { | ||
if (err) | ||
return reject(err); | ||
return resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
function deactivate() { | ||
return new Promise((resolve, reject) => { | ||
regKey.remove(VALUE_NAME, (err) => { | ||
if (err) | ||
return reject(err); | ||
return resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
function isActivated() { | ||
return new Promise((resolve, reject) => { | ||
regKey.get(VALUE_NAME, (err, item) => { | ||
return resolve(item !== null); | ||
}); | ||
}); | ||
} | ||
|
||
function* toggle() { | ||
const activated = yield isActivated(); | ||
if (activated) { | ||
yield deactivate(); | ||
} else { | ||
yield activate(); | ||
} | ||
} | ||
|
||
module.exports = { | ||
activate, | ||
deactivate, | ||
isActivated, | ||
toggle: co.wrap(toggle) | ||
}; |
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,65 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
const path = require('path'); | ||
const SimpleCache = require('simple-lru-cache'); | ||
|
||
const electron = require('electron'); | ||
const app = electron.app; | ||
|
||
const platformUtil = require('../platform-util'); | ||
const logger = require('./logger').create('iconprotocol'); | ||
|
||
function register() { | ||
app.on('ready', () => { | ||
const cache = new SimpleCache({ maxSize: 100 }); | ||
|
||
const protocol = electron.protocol; | ||
protocol.registerBufferProtocol('icon', (req, callback) => { | ||
let filePath = null; | ||
try { | ||
const path_base64 = req.url.substr(7); | ||
filePath = new Buffer(path_base64, 'base64').toString(); | ||
} catch (e) { | ||
// error | ||
return callback(); | ||
} | ||
|
||
if (filePath === null || filePath.length === 0) { | ||
// error | ||
return callback(); | ||
} | ||
|
||
let cacheKey = filePath; | ||
const extName = path.extname(filePath).toLowerCase(); | ||
|
||
if (extName.length > 0 && extName !== '.exe' && extName !== '.lnk') { | ||
cacheKey = extName; | ||
} else { | ||
cacheKey = filePath; | ||
} | ||
|
||
const buffer = cache.get(cacheKey); | ||
if (buffer === undefined) { | ||
platformUtil.fetchFileIconAsPng(filePath, (err, buf) => { | ||
if (err || buf === null) { | ||
logger.log(`internal error ${err}`); | ||
return callback(); | ||
} | ||
cache.set(cacheKey, buf); | ||
callback({ mimeType: 'image/png', data: buf }); | ||
}); | ||
} else { | ||
callback({ mimeType: 'image/png', data: buffer }); | ||
} | ||
}, (err) => { | ||
if (err) { | ||
logger.log('failed to register protocol: icon'); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
register: register | ||
}; |
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,24 @@ | ||
'use strict'; | ||
|
||
const winston = require('winston'); | ||
const logger = new (winston.Logger)({ | ||
level: 'debug', | ||
transports: [ | ||
new (winston.transports.Console)({ timestamp: true, prettyPrint: true }), | ||
new (winston.transports.File)({ filename: 'debug.log', json: false, prettyPrint: true }) | ||
] | ||
}); | ||
|
||
class Logger { | ||
constructor(tag) { | ||
this.tag = tag; | ||
} | ||
|
||
log(msg) { | ||
logger.debug(this.tag, msg); | ||
} | ||
} | ||
|
||
module.exports = { | ||
create: (tag) => new Logger(tag) | ||
}; |
Oops, something went wrong.