From 82583f45ba3ba990e4e2a6b473cd4dca5e47efab Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Fri, 18 Jan 2019 17:22:37 -0700 Subject: [PATCH] Add tray to NW.js version --- www/img/logo_64.png | Bin 0 -> 839 bytes www/js/home.js | 7 ++++ www/js/platform.js | 76 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 www/img/logo_64.png diff --git a/www/img/logo_64.png b/www/img/logo_64.png new file mode 100644 index 0000000000000000000000000000000000000000..dc1cb42fa631f35211e40c5d04f8ca937004fccd GIT binary patch literal 839 zcmV-N1GxN&P)nu~K~#9!?b}aJ({LQe@!tUg&jQ2;A@K<)>I2ZL2VzW&2bOq( z1Vqv3iRhdV6YqwL@hH*oZ;lCW5b#f;Cb;gun`CsbuI<~yMuJFTBeW~+?~{B_-J#!C z)~s9i5#o>loxo*a0$2i)fR1~k*UxbYcn(|wIz_Vq+JSx`#pzEDxC3-Fx_l3?iuV!+ z&K$M;`MQ`_lLLCKmhT3#ct3gI>_ON3D*j0fXx|HP3;*TD-jBMp4*^m@hXAfvy~0pc z)Mykn9JX&F5%glQRS10om^|o+sq19M#!v;7&6;^k9S~BS@z{*N102E<$Z*LbsdSnD`V*^an72h3%)e*Y@O4HK-%p_(B#zKrQ zKe25>@kwIY_@M%h18glUkSHY>4v#uAcR$=mt*Y(b>)0VIF~kN^@u z0!RP}AOR%6NdcsWhR6ql9)R5VIA*0%|LLd<=9Z1K z13!k=71`c?m^+I&2tUZmjJx~HRBEdH4*{slLO1|8KcO&5_Sf2Pq^ZNT6l#+71M`LaTup<&c0!RP}AOR$R1dsr}2GD&BpbKgp8@~c11n}{A z01=0u3)u39_C-OhUDbSyA{4JXv;1ZNFzf&b3ToA|Y;xQ$wQI_ZJMv%u~DuK5NbI)FYP1VjM^_t)nYV6lGA7dfIe{ug!|H}~Z% REz' @@ -40,7 +41,12 @@ function loadCards(callback) { + '
' + note.html + '
' + '' + ''); + trayitems.push({ + title: note.title, + id: note.noteid + }); } + console.log(trayitems); var noteElements = document.getElementsByClassName("notecard-col"); window.shuffleInstance.add(noteElements); window.shuffleInstance.sort({ @@ -49,6 +55,7 @@ function loadCards(callback) { return el.getAttribute("data-favorite"); } }); + setTrayMenu(trayitems); if (typeof callback == 'function') { callback(); } diff --git a/www/js/platform.js b/www/js/platform.js index d188a42..b99dd32 100644 --- a/www/js/platform.js +++ b/www/js/platform.js @@ -6,10 +6,16 @@ var platform_type = ""; +var nw_tray = null; + var openBrowser = function (url) { } +var setTrayMenu = function (items) { + +} + function initCordova() { platform_type = "cordova"; @@ -66,6 +72,76 @@ function initNW() { browserwin.menu = browsermenu; }); } + + nw_tray = new nw.Tray({ + title: 'NotePost', + icon: 'www/img/logo_64.png' + }); + + setTrayMenu = function (items) { + var menu = new nw.Menu(); + menu.append(new nw.MenuItem({ + type: 'normal', + label: 'Open NotePost', + click: function () { + nw.Window.get().show(); + } + })); + menu.append(new nw.MenuItem({ + type: 'normal', + label: 'New Note', + click: function () { + router.navigate("/editnote"); + nw.Window.get().show(); + } + })); + menu.append(new nw.MenuItem({ + type: 'separator' + })); + + if (items.length > 0) { + for (i in items) { + console.log(items[i]); + var label_max = 50; + var label = items[i].title; + if (label.length > label_max) { + label = label.substring(0, label_max) + "..."; + } + menu.append(new nw.MenuItem({ + type: 'normal', + label: label, + click: function (id) { + return function () { + editNote(id); + nw.Window.get().show(); + } + }(items[i].id) + })); + ; + } + menu.append(new nw.MenuItem({ + type: 'separator' + })); + } + + menu.append(new nw.MenuItem({ + type: 'normal', + label: 'Exit NotePost', + click: function () { + nw.App.quit(); + } + })); + nw_tray.menu = menu; + } + + nw.Window.get().on('minimize', function () { + nw.Window.get().hide(); + }); + nw_tray.on('click', function () { + nw.Window.get().show(); + }); + + setTrayMenu([]); } function initPlatform() {