Skip to content

Commit

Permalink
Refactoring & redesigned the application.
Browse files Browse the repository at this point in the history
  • Loading branch information
shyrz committed Apr 5, 2017
1 parent d5208bb commit cbb308d
Show file tree
Hide file tree
Showing 46 changed files with 594 additions and 1,226 deletions.
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
## Features

- Clipboard history manage
- File types recognize
- Code highlight
- ……

## Documentation

- [Requirement Analysis]()
- [Prototype Design]()
- [UI&UX Design]()
Expand All @@ -23,7 +22,6 @@
- [electron](https://github.com/electron/electron)
- [vue](https://github.com/vuejs/vue)
- [vuex](https://github.com/vuejs/vuex/)
- [vue-router](https://github.com/vuejs/vue-router/)
- [electron-vue](https://github.com/SimulatedGREG/electron-vue)

## License
Expand Down
4 changes: 1 addition & 3 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
## 特性

- 剪贴板历史管理
- 文件类型识别
- 代码高亮
- ……

## 文档

- [需求分析]()
- [原型设计]()
- [UI&UX 设计]()
Expand All @@ -23,7 +22,6 @@
- [electron](https://github.com/electron/electron)
- [vue](https://github.com/vuejs/vue)
- [vuex](https://github.com/vuejs/vuex/)
- [vue-router](https://github.com/vuejs/vue-router/)
- [electron-vue](https://github.com/SimulatedGREG/electron-vue)

## 协议
Expand Down
File renamed without changes
File renamed without changes
Binary file added app/icons/icon_512x512.icns
Binary file not shown.
2 changes: 1 addition & 1 deletion app/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<title>clipaste</title>
<title>clipaste</title>
<% if (htmlWebpackPlugin.options.appModules) { %>
<!-- Add `app/node_modules` to global paths so `require` works properly in development -->
<script>
Expand Down
13 changes: 4 additions & 9 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
{
"name": "clipaste",
"version": "0.0.0",
"description": "Clipboard enhanced tool",
"description": "Clipboard enhanced tool.",
"main": "./dist/main.js",
"dependencies": {
"babel-runtime": "^6.23.0",
"js-yaml": "^3.8.2",
"sqlite3": "^3.1.8",
"vue": "^2.1.10",
"vue-electron": "^1.0.6",
"vue-resource": "^1.0.3",
"vue-router": "^2.1.2",
"vuex": "^2.1.1"
"fuse.js": "^2.6.2",
"vue": "^2.2.5",
"vuex": "^2.2.1"
},
"devDependencies": {},
"author": "Phantr4x <[email protected]>"
Expand Down
179 changes: 54 additions & 125 deletions app/src/main/index.js
Original file line number Diff line number Diff line change
@@ -1,142 +1,39 @@
import fs from 'fs';
/* eslint-disable */
import {
app,
ipcMain,
BrowserWindow,
globalShortcut,
Menu,
Tray,
screen,
ipcMain,
ipcRenderer,
clipboard,
ipcRenderer
nativeImage
} from 'electron';
import yaml from 'js-yaml';
const sqlite3 = require('sqlite3').verbose();

import doob from '../modules/doob';
import clipocher from '../modules/clipocher';
import clippingsHandler from '../modules/clippings-handler';

const winURL = process.env.NODE_ENV === 'development'
? `http://localhost:${require('../../../config').port}`
: `file://${__dirname}/index.html`;

// 加载配置文件
let SETTINGS;
try {
SETTINGS = yaml.safeLoad(
fs.readFileSync(`${__dirname}/../settings.yml`, 'utf8')
);
// console.log(SETTINGS);
} catch (e) {
console.log(e);
}

// 创建数据库
const db = new sqlite3.Database(`${__dirname}/../clipaste.db`);
db.serialize(() => {
// db.run('DROP TABLE clipboard;');
db.run('CREATE TABLE IF NOT EXISTS clipboard (id integer PRIMARY KEY NOT NULL, clipping text, is_image boolean NOT NULL DEFAULT(0), is_pinned boolean NOT NULL DEFAULT(0));');
db.run('DELETE FROM clipboard;');
db.all(`SELECT * FROM clipboard`, (err, rows) => {
if (err) throw err;
fs.writeFile(`${__dirname}/../temp.json`, JSON.stringify(rows), (err) => {
if (err) throw err;
});
});
});

let output;
let clipboardWatcher, sqliteWatcher;
app.on('ready', () => {
app.dock.hide();

// 初始化窗口和托盘
mainWindowConstructor();
trayMenuConstructor();

// 全局注册快捷键
shortcutRegister();

// 轮询系统剪贴板
let timestamp;
clipboardWatcher = clipocher({
delay: 120,
ontextchange: (text) => {
timestamp = new Date().getTime();
console.time('TextChange');
// 判断文本大小
text.length <= SETTINGS.GENERAL.MAX_SIZE * 1048576
// 插入数据 [文本]
? doob.insert(db, 'clipboard', timestamp, clippingsHandler(timestamp, text), false, false)
: console.log(`Text is larger than ${SETTINGS.GENERAL.MAX_SIZE}MB!`);
console.timeEnd('TextChange');
import fs from 'fs';
import path from 'path';

// 写入JSON
db.all(`SELECT * FROM clipboard`, (err, rows) => {
if (err) throw err;
fs.writeFile(`${__dirname}/../temp.json`, JSON.stringify(rows), (err) => {
if (err) throw err;
// console.log(`temp.json saved.`);
});
});
},
onimagechange: (image) => {
timestamp = new Date().getTime();
console.time('ImageChange');
const imgDataURL = image.toDataURL();
// 判断图像大小
imgDataURL.length <= SETTINGS.GENERAL.MAX_SIZE * 1048576
// 插入数据 [图片绝对路径]
? doob.insert(db, 'clipboard', timestamp, clippingsHandler(timestamp, imgDataURL), true, false)
: console.log(`Image is larger than ${SETTINGS.GENERAL.MAX_SIZE}MB!`);
console.timeEnd('ImageChange');
global.settings = require('../settings.json');

// 写入JSON
db.all(`SELECT * FROM clipboard`, (err, rows) => {
if (err) throw err;
fs.writeFile(`${__dirname}/../temp.json`, JSON.stringify(rows), (err) => {
if (err) throw err;
// console.log(`temp.json saved.`);
});
});
},
});
});

app.on('activate', () => {
if (mainWindow === null) {
mainWindowConstructor();
}
});

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});

app.on('will-quit', () => {
// global.clearInterval(poller);
db.close();
clipboardWatcher.stop();
clearInterval(sqliteWatcher);
// ipcMain.removeAllListeners();
globalShortcut.unregisterAll();
});
const winURL = process.env.NODE_ENV === 'development' ?
`http://localhost:${require('../../../config').port}` :
`file://${__dirname}/index.html`;

let mainWindow;
let trayMenu;

// 主窗口构造器
const mainWindowConstructor = () => {
mainWindow = new BrowserWindow({
height: 576,
width: 360,
// resizable: false,
resizable: false,
movable: false,
alwaysOnTop: true,
skipTaskBar: true,
show: false,
frame: false,
backgroundColor: '#FFFFFF',
backgroundColor: "#272527",
transparent: false,
});
mainWindow.loadURL(winURL);
Expand All @@ -146,13 +43,14 @@ const mainWindowConstructor = () => {
mainWindow.on('closed', () => {
mainWindow = null;
});
// eslint-disable-next-line no-console
console.log('MainWindow Start');
};

let trayMenu;
// 托盘构造器
const trayMenuConstructor = () => {
trayMenu = new Tray(`${__dirname}/../../icons/trays/[email protected]`);
trayMenu.setPressedImage(`${__dirname}/../../icons/trays/[email protected]`);
trayMenu = new Tray(`${__dirname}/imgs/[email protected]`);
trayMenu.setPressedImage(`${__dirname}/imgs/[email protected]`);
let times = 0;
trayMenu.on('click', () => {
if (times++ === 0) {
Expand All @@ -162,16 +60,47 @@ const trayMenuConstructor = () => {
mainWindow.focus();
});
trayMenu.setToolTip('Clipaste');
// eslint-disable-next-line no-console
console.log('TrayMenu Start');
};

// 快捷键注册器
const shortcutRegister = () => {
// Show clipboard
if (!globalShortcut.isRegistered(SETTINGS.SHORTCUTS.SHOW_CLIPBOARD)) {
globalShortcut.register(SETTINGS.SHORTCUTS.SHOW_CLIPBOARD, () => {
// 注册快捷键 => 展示剪贴板
if (!globalShortcut.isRegistered(global.settings.shortcuts.show_clipboard)) {
globalShortcut.register(global.settings.shortcuts.show_clipboard, () => {
mainWindow.show();
});
} else {
console.log(`Registration for ${SETTINGS.SHORTCUTS.SHOW_CLIPBOARD} failed!`);
// eslint-disable-next-line no-console
console.log(`Registration for ${global.settings.shortcuts.show_clipboard} failed!`);
}
};

// let clipWatcher;
app.on('ready', () => {
// 初始化 窗口&托盘
app.dock.hide();
mainWindowConstructor();
trayMenuConstructor();
// 注册 全局快捷键
shortcutRegister();
// 变更 Vue.js开发工具版本
// BrowserWindow.removeDevToolsExtension('Vue.js devtools');
// BrowserWindow.addDevToolsExtension('/Users/Phantr4x/Workspace/vue-devtools/shells/chrome');
});

app.on('activate', () => {
if (mainWindow === null) mainWindowConstructor();
if (trayMenu === null) trayMenuConstructor();
});

app.on('will-quit', () => {
globalShortcut.unregisterAll();
});

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
23 changes: 0 additions & 23 deletions app/src/modules/clippings-handler.js

This file was deleted.

Loading

0 comments on commit cbb308d

Please sign in to comment.