Skip to content

Commit

Permalink
v0.1.0 Update
Browse files Browse the repository at this point in the history
+ Image history support
+ Local sync
+ Performance optimize
  • Loading branch information
shyrz committed Apr 19, 2017
1 parent 7e3c897 commit 124bd57
Show file tree
Hide file tree
Showing 15 changed files with 228 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ app/dist/renderer.js
app/dist/styles.css
builds/*
coverage
dist/
node_modules/
npm-debug.log
npm-debug.log.*
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Phantr4x

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 0 additions & 1 deletion _config.yml

This file was deleted.

Binary file removed app/dist/imgs/[email protected]
Binary file not shown.
Binary file removed app/dist/imgs/[email protected]
Binary file not shown.
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clipaste",
"version": "0.0.0",
"version": "0.1.0",
"description": "Clipboard enhanced tool.",
"main": "./dist/main.js",
"dependencies": {
Expand Down
75 changes: 63 additions & 12 deletions app/src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ import {
Tray,
screen,
ipcMain,
ipcRenderer,
clipboard,
nativeImage
} from 'electron';
import fs from 'fs';
import path from 'path';
// import crypto from 'crypto';

global.settings = require('../settings.json');
global.paths = {
home: app.getPath('home'),
appData: app.getPath('appData'),
temp: app.getPath('temp'),
downloads: app.getPath('downloads'),
};

const winURL = process.env.NODE_ENV === 'development' ?
`http://localhost:${require('../../../config').port}` :
Expand All @@ -22,7 +28,6 @@ const winURL = process.env.NODE_ENV === 'development' ?
let mainWindow;
let trayMenu;

// 主窗口构造器
const mainWindowConstructor = () => {
mainWindow = new BrowserWindow({
height: 576,
Expand All @@ -47,10 +52,10 @@ const mainWindowConstructor = () => {
console.log('MainWindow Start');
};

// 托盘构造器
const trayMenuConstructor = () => {
trayMenu = new Tray(`${__dirname}/imgs/[email protected]`);
trayMenu.setPressedImage(`${__dirname}/imgs/[email protected]`);
trayMenu = new Tray(`${__dirname}/icons/[email protected]`);
trayMenu.setPressedImage(`${__dirname}/icons/[email protected]`);
// trayMenu = new Tray(`${__dirname}/../../dist/icons/[email protected]`);
let times = 0;
trayMenu.on('click', () => {
if (times++ === 0) {
Expand All @@ -64,9 +69,7 @@ const trayMenuConstructor = () => {
console.log('TrayMenu Start');
};

// 快捷键注册器
const shortcutRegister = () => {
// 注册快捷键 => 展示剪贴板
if (!globalShortcut.isRegistered(global.settings.shortcuts.show_clipboard)) {
globalShortcut.register(global.settings.shortcuts.show_clipboard, () => {
mainWindow.show();
Expand All @@ -77,22 +80,70 @@ const shortcutRegister = () => {
}
};

// let clipWatcher;
const sourceGenerator = () => {
const appDataPath = `${global.paths.appData}/Clipaste`;

if (!fs.existsSync(appDataPath)) {
fs.mkdirSync(appDataPath, (err) => {
if (err) throw err;
});
}

if (!fs.existsSync(`${appDataPath}/temp`)) {
fs.mkdirSync(`${appDataPath}/temp`, (err) => {
if (err) throw err;
});
}

if (!fs.existsSync(`${appDataPath}/source.json`)) {
fs.writeFileSync(`${appDataPath}/source.json`, '[]', (err) => {
if (err) throw err;
});
}
};

app.on('ready', () => {
// 初始化 窗口&托盘
app.dock.hide();
mainWindowConstructor();
trayMenuConstructor();
// 注册 全局快捷键
shortcutRegister();
// 变更 Vue.js开发工具版本
sourceGenerator();

global.history = fs.readFileSync(`${global.paths.appData}/Clipaste/source.json`, 'utf-8');

// BrowserWindow.removeDevToolsExtension('Vue.js devtools');
// BrowserWindow.addDevToolsExtension('/Users/Phantr4x/Workspace/vue-devtools/shells/chrome');

ipcMain.on('image-append', (event, fileName, img) => {
fs.writeFile(`${global.paths.appData}/Clipaste/temp/${fileName}.png`, img, (err) => {
if (err) throw err;
console.log(`[APPEND] ${global.paths.appData}/Clipaste/temp/${fileName}.png`);
});
});

ipcMain.on('image-delete', (event, fileName) => {
fs.unlink(`${global.paths.appData}/Clipaste/temp/${fileName}.png`, (err) => {
if (err) throw err;
console.log(`[DELETE] ${global.paths.appData}/Clipaste/temp/${fileName}.png`);
});
});

ipcMain.on('content-sync', (event, storage) => {
fs.writeFile(`${global.paths.appData}/Clipaste/source.json`, storage, (err) => {
if (err) throw err;
console.log(`[SYNC] ${global.paths.appData}/Clipaste/source.json`);
});
});

// ipcMain.on('checksum', (event, buffer, type = 'md5') => {
// const hash = crypto.createHash(type);
// event.returnValue = hash.update(buffer).digest('hex');
// });
});

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

app.on('will-quit', () => {
Expand Down
67 changes: 55 additions & 12 deletions app/src/renderer/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
</template>

<script>
// import fs from 'fs';
// import { remote, clipboard } from 'electron';
/* eslint-disable */
import { remote, ipcRenderer, nativeImage } from 'electron';
import fs from 'fs';
import Panel from 'renderer/components/Panel';
import Panel from 'components/Panel';
import clipocher from 'renderer/clipocher';
import store from 'renderer/vuex/store';
export default {
Expand All @@ -22,29 +24,68 @@
};
},
mounted() {
console.time('[ImportData]');
console.log(remote.getGlobal('history'));
this.$store.commit('IMPORT_DATA', remote.getGlobal('history'));
console.timeEnd('[ImportData]');
clipocher({
delay: 300,
ontextchange: (txt) => {
console.time('[TextChange]');
const timestamp = new Date().getTime();
let hasText = false;
let exist = false;
this.$store.state.source.storage.forEach((el) => {
if (el.text === txt) {
if (el.text && el.text === txt) {
this.$store.commit('UPDATE_TEXT_CONTENT', {
text: txt,
updateId: timestamp,
});
hasText = true;
exist = true;
}
});
if (!hasText) {
if (!exist) {
this.$store.commit('APPEND_TEXT_CONTENT', {
id: timestamp,
text: txt,
star: false,
});
}
console.timeEnd('[TextChange]');
console.time('[ContentSync]');
ipcRenderer.send('content-sync', JSON.stringify(this.$store.state.source.storage));
console.timeEnd('[ContentSync]');
},
onimagechange: (img) => {
console.time('[ImageChange]');
console.time('Convert');
img = img.toPNG();
console.timeEnd('Convert');
const timestamp = new Date().getTime();
let exist = false;
console.time('Save');
ipcRenderer.send('image-append', timestamp, img);
console.timeEnd('Save');
console.time('Commit');
if (!exist) {
this.$store.commit('APPEND_IMAGE_CONTENT', {
id: timestamp,
image: `${remote.getGlobal('paths').appData}/Clipaste/temp/${timestamp}.png`,
star: false,
});
}
console.timeEnd('Commit');
console.timeEnd('[ImageChange]');
console.time('[ContentSync]');
ipcRenderer.send('content-sync', JSON.stringify(this.$store.state.source.storage));
console.timeEnd('[ContentSync]');
},
});
},
Expand All @@ -54,18 +95,20 @@

<style>
@import url(https://fonts.googleapis.com/icon?family=Material+Icons);
/*@import url(https://fonts.googleapis.com/css?family=Lato:300);*/
* { margin: 0; padding: 0; outline: 0; -webkit-user-select: none; cursor: default; }
input { cursor: text; }
ol, ul { list-style: none; }
html,
body {
width: 100%;
}
body {
font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Source Han Sans", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #1F2D3D;
}
input { cursor: text; }
ol,
ul { list-style: none; }
</style>
Loading

0 comments on commit 124bd57

Please sign in to comment.