Skip to content

Commit

Permalink
增加剪贴板上传(文件picker还没做好)
Browse files Browse the repository at this point in the history
  • Loading branch information
mzvast committed Mar 18, 2017
1 parent 176a6cb commit 001fdf0
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Picorz是一个七牛云图床,开发的目的是为个人写markdown博客使

# 效果图
## 主界面
![](http://ogscovhkh.bkt.clouddn.com/Picorz-snipaste_20170318_092052.png-)
![](http://ogscovhkh.bkt.clouddn.com/Picorz-clipboard--2017-03-18T22:45:16+08:00)

## 设置界面
![](http://ogscovhkh.bkt.clouddn.com/bbq-111.png-bbq-2017-03-17T23:47:08+08:00)
Expand Down
8 changes: 8 additions & 0 deletions app/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ body{
color: white;
background-color: greenyellow;
}
.markdown{
padding: 0.5em 0 0.5em 0;
left: 25vw;
bottom: 25vh;
width: 50vw;
border-radius: 0.5em;
}

.clip{
left: 10vw;
}
Expand Down
11 changes: 9 additions & 2 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@
<div class="my-pad"></div>
<div class="my-text">Drag&Drop</div>


<div class="checkbox my-btn markdown text-center">
<label>
<input class="markdowncheck" type="checkbox" value="">
Markdown
</label>
</div>

<button type="button" class="btn btn-large btn-block my-btn clip">Clipboard</button>
<button type="button" class="btn btn-large btn-block my-btn picker">OpenFile</button>
<button type="button" class="btn btn-large btn-block my-btn clip">Paste</button>
<button type="button" class="btn btn-large btn-block my-btn picker" disabled>OpenFile</button>


</div>
Expand Down
14 changes: 13 additions & 1 deletion app/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ const configuration = require('../configuration.js');
const { ipcRenderer,clipboard } = require('electron')
const { dialog } = require('electron').remote
const container = document.getElementById('container')
const markdownEle = document.querySelector('.markdowncheck');
const clipEle = document.querySelector('.clip');
const pickerEle = document.querySelector('.picker');

markdownEle.checked = configuration.readSettings('markdown');

container.ondragover = () => {
return false;
}
Expand Down Expand Up @@ -35,4 +39,12 @@ container.ondrop = (e) => {
clipEle.onclick = (e)=>{
e.preventDefault();
ipcRenderer.send('get-clipboard')
}
}

markdownEle.onclick = (e) => {
toggleMarkdown ();
};

function toggleMarkdown () {
configuration.saveSettings('markdown',markdownEle.checked)
}
3 changes: 3 additions & 0 deletions configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ function initConfig() {
if (!readSettings('timefix')) {
saveSettings('timefix', true);
}
if (!readSettings('markdown')) {
saveSettings('markdown', true);
}
}

module.exports = {
Expand Down
50 changes: 20 additions & 30 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const url = require('url')
const moment = require('moment')
const configuration = require('./configuration.js')
var qn = require('qn');
require('electron-debug')({ showDevTools: true });
// require('electron-debug')({ showDevTools: true });

/**
* Temp dep
Expand Down Expand Up @@ -54,17 +54,8 @@ ipcMain.on('upload', (event,arg) => {
console.log(filepath, key);
// doUpload(filename,key);
let client = getClient();
client.uploadFile(filepath, { key: key }, function (err, result) {
console.log(result);
dialog.showMessageBox(null, {
type: "info",
buttons: ['Ok'],
message: 'markdown格式图片URL已经复制到剪贴板',
title: '上传成功'
}, () => {
clipboard.writeText("![](" + result.url + ")");
});
});

doUpload(filepath,key);
})

function doUpload(filepath,key){
Expand All @@ -74,10 +65,17 @@ function doUpload(filepath,key){
dialog.showMessageBox(null, {
type: "info",
buttons: ['Ok'],
message: 'markdown格式图片URL已经复制到剪贴板',
message: '已经复制到剪贴板',
title: '上传成功'
}, () => {
clipboard.writeText("![](" + result.url + ")");
let markdownOn = configuration.readSettings('markdown');
let finalClip;
if(markdownOn){
finalClip = "![](" + result.url + ")"
}else{
finalClip = result.url;
}
clipboard.writeText(finalClip);
});
});
}
Expand Down Expand Up @@ -170,8 +168,6 @@ function removeDomain(domain_name) {
configuration.removeSettings('domains', domain_name);
}
function getClipboard() {
//path.join(__dirname, '/app/index.html')
// Process the data (note: error handling omitted)
let img = clipboard.readImage();
console.log(img.getSize());

Expand All @@ -184,17 +180,11 @@ function getClipboard() {
})
}
})
// temp.mkdir('picorztmp', function(err, dirPath) {
// var inputPath = path.join(dirPath, 'clipboard.png')
// fs.writeFile(inputPath, img, function(err) {
// if (err) throw err;
// console.log(">>>>inputPath=",inputPath);
// doUpload(inputPath,'clipboard.png');
// });
// });

console.log(app.getAppPath())
}


ipcMain.on('close-settings-window', closeSettingsWindow)
ipcMain.on('open-settings-window', openSettingsWindow)
ipcMain.on('add-bucket', addBucket)
Expand All @@ -205,29 +195,29 @@ ipcMain.on('get-clipboard',getClipboard)

const template = [
{
label: '工具',
label: 'Tools',
submenu: [
{
label: '账号设置',
label: 'Account',
click() {
openSettingsWindow();
}
}
]
},
{
label: '关于',
label: 'About',
submenu: [
{
label: '技术支持',
label: 'Support',
click() { require('electron').shell.openExternal('https://github.com/mzvast/Picorz') }
},
{
label: '检查更新',
label: 'Update',
click() { require('electron').shell.openExternal('https://github.com/mzvast/Picorz/releases') }
},
{
label: '版本' + app.getVersion()
label: 'v' + app.getVersion()
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Picorz",
"version": "0.2.3",
"version": "0.2.4",
"main": "main.js",
"scripts": {
"start": "electron .",
Expand Down

0 comments on commit 001fdf0

Please sign in to comment.