diff --git a/main.js b/main.js index d52b28d3..99bfdb00 100644 --- a/main.js +++ b/main.js @@ -1,7 +1,11 @@ // var app = require('electron').app; // Module to control application life. const {app, BrowserWindow, crashReporter} = require('electron'); var ipc = require('electron').ipcMain; +const electron = require('electron'); +const Menu = electron.Menu +const Tray = electron.Tray var pdfMain = require('pdf_main'); +var appIcon; // Report crashes to our server. crashReporter.start({ @@ -11,6 +15,7 @@ crashReporter.start({ autoSubmit: true }); + // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the javascript object is GCed. var mainWindow = null; @@ -94,7 +99,6 @@ function openIt() { var leanoteProtocol = require('leanote_protocol'); leanoteProtocol.init(); - // Create the browser window. mainWindow = new BrowserWindow({ width: 1050, @@ -129,13 +133,27 @@ function openIt() { if(mainWindow && mainWindow.webContents) mainWindow.webContents.send('blurWindow'); }); + + function close (e, force) { + console.log('close:', force); + mainWindow.hide(); + e && e.preventDefault(); + mainWindow.webContents.send('closeWindow'); + } + // 以前的关闭是真关闭, 现是是假关闭了 // 关闭,先保存数据 mainWindow.on('close', function(e) { - console.log('close'); - mainWindow.hide(); - e.preventDefault(); - mainWindow.webContents.send('closeWindow'); + // windows支持tray, 点close就是隐藏 + if (process.platform.toLowerCase().indexOf('win') === 0) { // win32 + mainWindow.hide(); + e.preventDefault(); + return; + } + + // mac 在docker下quit; + // linux直接点x linux不支持Tray + close(e, false); }); // 前端发来可以关闭了 @@ -146,4 +164,51 @@ function openIt() { }); pdfMain.init(); + + function show () { + mainWindow.show(); + mainWindow.restore(); + mainWindow.focus(); + mainWindow.webContents.send('focusWindow'); + } + + var trayShowed = false; + ipc.on('show-tray', function(event, arg) { + if (trayShowed) { + return; + } + trayShowed = true; + + if (process.platform == 'linux') { + return; + } + + // 打开一次就自动关了 + appIcon = new Tray(__dirname + '/public/images/tray/' + ( process.platform == 'darwin' ? 'trayTemplate.png' : 'tray.png')) + var contextMenu = Menu.buildFromTemplate([ + { + label: arg.Open, click: function () { + show(); + } + }, + { + label: arg.Close, click: function () { + close(null, true); + } + }, + ]); + appIcon.setToolTip('Leanote'); + // appIcon.setTitle('Leanote'); + // appIcon.setContextMenu(contextMenu); + + appIcon.on('click', function (e) { + show(); + e.preventDefault(); + }); + appIcon.on('right-click', function () { + appIcon.popUpContextMenu(contextMenu); + }); + + }); + } diff --git a/public/config.js b/public/config.js index 56aef93e..7184a02f 100644 --- a/public/config.js +++ b/public/config.js @@ -33,7 +33,7 @@ var Config = { "name": "日本語" } ], - "lang": "en-us", + "lang": "zh-cn", "theme": "", "view": "summary" }; \ No newline at end of file diff --git a/public/images/tray/tray.png b/public/images/tray/tray.png new file mode 100644 index 00000000..4a51f2c1 Binary files /dev/null and b/public/images/tray/tray.png differ diff --git a/public/images/tray/tray@2x.png b/public/images/tray/tray@2x.png new file mode 100644 index 00000000..57bd6bc8 Binary files /dev/null and b/public/images/tray/tray@2x.png differ diff --git a/public/images/tray/trayTemplate.png b/public/images/tray/trayTemplate.png new file mode 100644 index 00000000..2bed45b3 Binary files /dev/null and b/public/images/tray/trayTemplate.png differ diff --git a/public/images/tray/trayTemplate@2x.png b/public/images/tray/trayTemplate@2x.png new file mode 100644 index 00000000..03128643 Binary files /dev/null and b/public/images/tray/trayTemplate@2x.png differ diff --git a/public/js/app/api.js b/public/js/app/api.js index 85ea3ea4..6f6adc13 100644 --- a/public/js/app/api.js +++ b/public/js/app/api.js @@ -18,6 +18,7 @@ var Api = { userService: UserService, dbService: db, ipc: nodeRequire('electron').ipcRenderer, + projectPath: projectPath, // 打开本地目录 // mac和windows下不同 diff --git a/public/js/app/native.js b/public/js/app/native.js index 35c6878d..537f78c1 100644 --- a/public/js/app/native.js +++ b/public/js/app/native.js @@ -21,28 +21,13 @@ $(function() { var isMacP = isMac(); + // mac上才会自己控制 $('.tool-close, .tool-close-blur').click(function() { onClose(function() { gui.win.hide(); }); }); - // 从login.html -> note.html过来就没有reopen事件了? - // note.html -> login.html -> note.html, 使得两次bind - /* - if(gui.App._events) { - gui.App._events.reopen = function() { - win.show(); - win.focus(); - } - } else { - gui.App.on('reopen', function() { - win.show(); - win.focus(); - }); - } - */ - $('.tool-min, .tool-min-blur').click(function() { gui.win.minimize(); }); @@ -56,6 +41,29 @@ $(function() { } }); + // Tray + /* + + var electron = nodeRequire('electron'); + var Menu = electron.remote.Menu; + var Tray = electron.remote.Tray; + var appIcon = new Tray(projectPath + '/public/images/logo/tray.png') + var contextMenu = Menu.buildFromTemplate([ + { + label: '打开', click: function () { + alert(3); + } + }, + { + label: '关闭', click: function () { + alert(3); + } + }, + ]); + appIcon.setToolTip('This is my application.') + appIcon.setContextMenu(contextMenu) + */ + }); // bind close event @@ -73,6 +81,7 @@ function Menu() { document.execCommand('cut'); } else { /* + // 不知道什么原因, 可能是Chrome的原因 We don't execute document.execCommand() this time, because it is called recursively. console.log('tinymce中没用'); setTimeout(function() { diff --git a/public/js/app/page.js b/public/js/app/page.js index 3f21c506..c3255fb7 100644 --- a/public/js/app/page.js +++ b/public/js/app/page.js @@ -1450,6 +1450,11 @@ function initPage(initedCallback) { }); }); + ipc.send('show-tray', { + Open: getMsg('Open'), + Close: getMsg('Close') + }); + // 注入前端变量# WebService.set(Notebook, Note, Attach, Tag); diff --git a/public/js/app/service.js b/public/js/app/service.js index bc6c9c26..7fe51a6d 100644 --- a/public/js/app/service.js +++ b/public/js/app/service.js @@ -39,3 +39,5 @@ var NodeFs = require('fs'); Service.dispatch = function() {}; var gui = require('gui'); // var remote = require('remote'); + +var projectPath = __dirname; diff --git a/public/langs/zh-cn.js b/public/langs/zh-cn.js index 2373260f..141f1adf 100644 --- a/public/langs/zh-cn.js +++ b/public/langs/zh-cn.js @@ -310,5 +310,8 @@ "localAccountTips": "你好, 您使用的是本地离线帐户, 您的数据只存在本地, 不会同步到Leanote服务器, 如果您不小心删除了数据或硬盘损坏, 您的数据将永久丢失.
所以我们推荐您使用Leanote帐户来使用该客户端, 这样您的数据将会存储到云端, 以避免失误造成的数据丢失.
Leanote桌面端不再支持创建本地帐户, 但您之前创建的本地帐户还是可以继续使用.", "Don't Show Anymore": "不再提示", - "ctrl/cmd+e Toggle Modify with Readonly": "ctrl/cmd+e 切换编辑与只读" + "ctrl/cmd+e Toggle Modify with Readonly": "ctrl/cmd+e 切换编辑与只读", + + "Open": "打开", + "Close": "关闭" } \ No newline at end of file