mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-15 23:55:50 +00:00
img save as & notification
This commit is contained in:
68
node_modules/file.js
generated
vendored
68
node_modules/file.js
generated
vendored
@@ -1,5 +1,6 @@
|
||||
var db = require('db');
|
||||
var fs = require('fs');
|
||||
var needle = require('needle');
|
||||
var path = require('path');
|
||||
var Evt = require('evt');
|
||||
var User = require('user');
|
||||
@@ -310,12 +311,12 @@ var File = {
|
||||
if(!srcIsExists) {
|
||||
return callback(false, 'File Not Exists');
|
||||
}
|
||||
console.log(srcPath);
|
||||
console.log(toPath);
|
||||
// console.log(srcPath);
|
||||
// console.log(toPath);
|
||||
var toIsExists = fs.existsSync(toPath);
|
||||
function cp() {
|
||||
Common.copyFile(srcPath, toPath, function(ok) {
|
||||
callback(ok);
|
||||
callback && callback(ok);
|
||||
});
|
||||
}
|
||||
if(toIsExists) {
|
||||
@@ -323,7 +324,7 @@ var File = {
|
||||
if(!error) {
|
||||
cp();
|
||||
} else {
|
||||
callback(false, 'The Target File Cannot Overwrite');
|
||||
callback && callback(false, 'The Target File Cannot Overwrite');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -331,8 +332,6 @@ var File = {
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
// 附件操作
|
||||
addAttach: function(filePaths, noteId, callback) {
|
||||
if(!noteId || !filePaths) {
|
||||
@@ -400,7 +399,64 @@ var File = {
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 下载图片, 本地的, 或外站的
|
||||
downloadImg: function(src, callback) {
|
||||
var me = this;
|
||||
// 本地的
|
||||
if(src.indexOf('http://127.0.0.1') != -1) {
|
||||
var ret = /fileId=([a-zA-Z0-9]{24})/.exec(src);
|
||||
if(ret && ret.length == 2) {
|
||||
var fileId = ret[1];
|
||||
me.getImage(fileId, function(filePath) {
|
||||
callback(filePath);
|
||||
});
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
|
||||
} else {
|
||||
// 远程的图片
|
||||
needle.get(src, function(err, resp) {
|
||||
// console.log(resp);
|
||||
/*
|
||||
{ 'accept-ranges': 'bytes',
|
||||
'content-disposition': 'inline; filename="logo.png"',
|
||||
'content-length': '8583',
|
||||
'content-type': 'image/png',
|
||||
date: 'Mon, 19 Jan 2015 15:01:47 GMT',
|
||||
*/
|
||||
// log(resp.headers);
|
||||
if(err || !resp || resp.statusCode == 404) {
|
||||
callback(false);
|
||||
} else {
|
||||
// 当图片没有时候还是执行这一步
|
||||
|
||||
var typeStr = resp.headers['content-type'];
|
||||
var type = 'png';
|
||||
if(typeStr) {
|
||||
var typeArr = typeStr.split('/');
|
||||
if(typeStr.length > 1) {
|
||||
type = typeArr[1];
|
||||
}
|
||||
}
|
||||
|
||||
var filename = Common.uuid() + '.' + type;
|
||||
var imagePath = User.getCurUserImagesPath();
|
||||
var imagePathAll = imagePath + '/' + filename;
|
||||
fs.writeFile(imagePathAll, resp.body, function(err) {
|
||||
if(err) {
|
||||
callback(false);
|
||||
} else {
|
||||
callback(imagePathAll);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = File;
|
@@ -771,6 +771,8 @@ function log(o) {
|
||||
<!-- 为了上传图片 -->
|
||||
<input id="chooseImageInput" type="file" name="file" multiple style="display: none"/>
|
||||
|
||||
<input id="downloadImgInput" type="file" nwsaveas="" style=""/>
|
||||
|
||||
<!-- contextTips -->
|
||||
<div class="context-tips" id="conflictTips">
|
||||
<p>
|
||||
|
@@ -1578,6 +1578,9 @@ body {
|
||||
}
|
||||
}
|
||||
|
||||
#preview-contents {
|
||||
-webkit-user-select: text;
|
||||
}
|
||||
|
||||
#searchNoteInput,
|
||||
#searchNotebookForList,
|
||||
@@ -1750,5 +1753,10 @@ body {
|
||||
text-align: center; margin: 10px 0; opacity: 0.8;
|
||||
}
|
||||
|
||||
img::selection {
|
||||
background: transparent;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
@import '../traffic.less';
|
||||
@import '../ani.less';
|
||||
|
@@ -1424,6 +1424,9 @@ body.init .loading-footer {
|
||||
body.init #pageInner {
|
||||
display: none;
|
||||
}
|
||||
#preview-contents {
|
||||
-webkit-user-select: text;
|
||||
}
|
||||
#leftNotebook {
|
||||
overflow: hidden;
|
||||
border-radius: 5px 0 0 0;
|
||||
@@ -1544,6 +1547,10 @@ body.init #pageInner {
|
||||
margin: 10px 0;
|
||||
opacity: 0.8;
|
||||
}
|
||||
img::selection {
|
||||
background: transparent;
|
||||
color: #ffffff;
|
||||
}
|
||||
.win-tool {
|
||||
padding: 5px;
|
||||
position: absolute;
|
||||
|
@@ -73,6 +73,7 @@ function isMac() {
|
||||
// 窗口大小设置
|
||||
var win = gui.Window.get();
|
||||
|
||||
var downloadImgPath;
|
||||
$(function() {
|
||||
var isMacP = isMac();
|
||||
$('.tool-close, .tool-close-blur').click(function() {
|
||||
@@ -97,6 +98,26 @@ $(function() {
|
||||
// 全屏模式
|
||||
// win.toggleKioskMode();
|
||||
});
|
||||
|
||||
// 下载图片输入框
|
||||
$('#downloadImgInput').change(function() {
|
||||
var name = $(this).val();
|
||||
$(this).val(''); // 为防止重名不触发
|
||||
if(downloadImgPath) {
|
||||
FileService.download(downloadImgPath, name, function(ok, msg) {
|
||||
// console.log(ok + ' -=-');
|
||||
if(ok) {
|
||||
new window.Notification('Info', {
|
||||
body: 'Image saved successful!',
|
||||
});
|
||||
} else {
|
||||
new window.Notification('Warning', {
|
||||
body: msg || 'Image saved failure!',
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// bind close event
|
||||
@@ -125,6 +146,38 @@ function Menu() {
|
||||
document.execCommand('paste');
|
||||
}
|
||||
});
|
||||
|
||||
this.saveAs = new gui.MenuItem({
|
||||
label: 'Save as',
|
||||
click: function() {
|
||||
// document.execCommand("selectAll");
|
||||
// document.execCommand('paste');
|
||||
var src = $curTarget.attr('src');
|
||||
if(!src) {
|
||||
alert('error');
|
||||
}
|
||||
// 得到图片, 打开dialog
|
||||
FileService.downloadImg(src, function(curPath) {
|
||||
if(curPath) {
|
||||
var paths = curPath.split(/\/|\\/);
|
||||
var name = paths[paths.length-1];
|
||||
downloadImgPath = curPath;
|
||||
$('#downloadImgInput').attr('nwsaveas', name);
|
||||
$('#downloadImgInput').click();
|
||||
|
||||
} else {
|
||||
// alert会死?
|
||||
// alert('File not exists');
|
||||
// https://github.com/nwjs/nw.js/wiki/Notification
|
||||
var notification = new window.Notification('Warning', {
|
||||
body: 'File not exists',
|
||||
// icon: appIcon
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
this.openInBrowser = new gui.MenuItem({
|
||||
label: 'Open link in browser',
|
||||
click: function() {
|
||||
@@ -138,6 +191,8 @@ function Menu() {
|
||||
this.menu.append(this.copy);
|
||||
this.menu.append(this.paste);
|
||||
this.menu.append(new gui.MenuItem({ type: 'separator' }));
|
||||
this.menu.append(this.saveAs);
|
||||
this.menu.append(new gui.MenuItem({ type: 'separator' }));
|
||||
this.menu.append(this.openInBrowser);
|
||||
|
||||
// You can have submenu!
|
||||
@@ -156,6 +211,9 @@ Menu.prototype.canCopy = function(bool) {
|
||||
Menu.prototype.canPaste = function(bool) {
|
||||
this.paste.enabled = bool;
|
||||
};
|
||||
Menu.prototype.canSaveAs = function(bool) {
|
||||
this.saveAs.enabled = bool;
|
||||
};
|
||||
Menu.prototype.canOpenInBroswer = function(bool) {
|
||||
this.openInBrowser.enabled = bool;
|
||||
};
|
||||
@@ -167,9 +225,11 @@ var FS = require('fs');
|
||||
|
||||
// 右键菜单
|
||||
var winHref = '';
|
||||
$('#noteTitle, #searchNoteInput, #searchNotebookForList, #addTagInput, #wmd-input, #editorContent').on('contextmenu', function (e) {
|
||||
var $curTarget;
|
||||
$('#noteTitle, #searchNoteInput, #searchNotebookForList, #addTagInput, #wmd-input, #preview-contents, #editorContent').on('contextmenu', function (e) {
|
||||
e.preventDefault();
|
||||
var $target = $(e.target);
|
||||
$curTarget = $target;
|
||||
var text = $target.text();
|
||||
winHref = $target.attr('href');
|
||||
if(!winHref) {
|
||||
@@ -184,6 +244,7 @@ $('#noteTitle, #searchNoteInput, #searchNotebookForList, #addTagInput, #wmd-inpu
|
||||
}
|
||||
|
||||
menu.canOpenInBroswer(!!winHref);
|
||||
menu.canSaveAs($target.is('img') && $target.attr('src'));
|
||||
var selectionType = window.getSelection().type.toUpperCase();
|
||||
// var clipData = gui.Clipboard.get().get();
|
||||
// menu.canPaste(clipData.length > 0);
|
||||
|
Reference in New Issue
Block a user