"use strict";(function(){var e=0;var n=0;"use strict";var i=require("path");var t=require("fs");var r=require("util");var o=require("winreg");var u=require("./jsUtil");var a=require("./Logger").getLogger("appinfo.js");function s(e){var n=this;n.gui=e;n.mainWin=e.Window.get();n.mainWin=f(n.mainWin);n.wins={}}function f(e){if(!u.isValidVar(e)){return null}e._winIsShow=true;e.winShow=function(e){var n=this;if(e){if(n._winIsShow){return}n.show();n.focus();n._winIsShow=true}else{if(!n._winIsShow){return}n.hide();n._winIsShow=false}};e.winSetMinSize=function(e,n){var i=this;i._oldX=i.x;i._oldY=i.y;i._oldWidth=i.width;i._oldHeight=i.height;i.on("resize",function(t,r){if(t<e||r<n){i.moveTo(i._oldX,i._oldY);i.resizeTo(i._oldWidth,i._oldHeight)}i._oldX=i.x;i._oldY=i.y;i._oldWidth=i.width;i._oldHeight=i.height})};return e}s.prototype.getPkgInfo=function(){var e=this;return e.gui.App.manifest};s.prototype.addToTray=function(e,n,t,r,o){var u=this;var a=new u.gui.MenuItem({label:"显示程序",click:function d(){u.showWin(true)}});var s=new u.gui.MenuItem({label:"退出",click:function c(){u.gui.App.quit()}});var f=new u.gui.Menu;f.append(a);f.append(s);n=i.resolve(__dirname,n);var l=new u.gui.Tray({title:e,icon:n,tooltip:t});l.menu=f;l.on("click",function(){u.showWin(!u.mainWin.winIsShow)});if(r){u.mainWin.on("minimize",function(){u.showWin(!u.mainWin.winIsShow)})}if(o){u.mainWin.on("close",function(){u.showWin(!u.mainWin.winIsShow)})}};s.prototype.newWindow=function(e,n,t){var r=this;if(!u.isValidVar(e)||!u.isValidVar(n)||!u.isValidVar(t)){return null}if(r.wins[e]!==undefined){return r.wins[e]}var o=i.resolve(__dirname,n);if(!u.fsExistsSync(o)){return null}var a=r.gui.Window.open("file:///"+o,t);a=f(a);a.on("document-end",function(){a.focus()});a.on("closed",function(){delete r.wins[e]});r.wins[e]=a;return a};s.prototype.showWin=function(e,n){var i=this;if(n===undefined){n=i.mainWin}n.winShow(e)};s.prototype.setWinMinSize=function(e,n,i){var t=this;if(i===undefined){i=t.mainWin}i.winSetMinSize(e,n)};s.prototype.reload=function(e){var n=this;if(e===undefined){e=n.mainWin}e.reload()};s.prototype.closeWindow=function(e){var n=this;if(!u.isValidVar(e)){return false}var i=n.wins[e];if(i===undefined){return false}i.close();return true};s.prototype.onClose=function(e){var n=this;if(!u.isValidVar(e)){return}n.mainWin.on("close",e)};s.prototype.enableAutoRun=function(e,n){var i=this;if(i.key==undefined){var t=i._initRegInfo();if(!t){return false}}if(e){i.key.set(i.keyName,o.REG_SZ,i.keyValue,function(e){n(e)})}else{i.key.remove(i.keyName,function(e){n(e)})}return true};s.prototype.isAutoRun=function(e){var n=this;if(n.key==undefined){var i=n._initRegInfo();if(!i){return false}}n.key.get(n.keyName,function(n,i){e(n)});return true};s.prototype._initRegInfo=function(){var n=this;var t=u.getPkgInfo();if(t==null||t.name==undefined){return false}n.keyName=t.name;n.keyValue=i.join(i.dirname(process.execPath),"run.exe");if(!u.fsExistsSync(n.keyValue)){return false}if(e){n.keyValue=r.format('"%s" /runas %s',n.keyValue,n.keyName)}else{n.keyValue=r.format('"%s" %s',n.keyValue,n.keyName)}var a="\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";n.key=new o({hive:o.HKLM,key:a});return true};exports.AppInfo=s;if(0){var l=require("../../common/js/appinfo");var d=new l.AppInfo(require("nw.gui"));d.addToTray("tray","../../common/image/logo_measure_32x32.png","tray");d.showWin(true);d.setWinMinSize(1024,768);var c="../../tool/sample/about.html";var w={toolbar:false,resizable:false,show:true,height:120,width:350,focus:true};d.newWindow("about",c,w)}exports.nouse=function(){var e=function a(){gui.App.quit()};var n=new gui.MenuItem({label:"Exit",click:e,key:"e",modifiers:"ctrl+alt"});var i=new gui.Menu;i.append(n);var t=function s(){var e={toolbar:false,resizable:false,show:true,height:120,width:350,focus:true};var n=gui.Window.open("about.html",e);n.on("document-end",function(){n.focus();$(n.window.document).find("a").bind("click",function(e){e.preventDefault();gui.Shell.openExternal(this.href)})})};var r=new gui.MenuItem({label:"About",click:t,key:"h",modifiers:"ctrl+alt"});var o=new gui.Menu;o.append(r);var u=new gui.Menu({type:"menubar"});u.append(new gui.MenuItem({label:"File",submenu:i}));u.append(new gui.MenuItem({label:"Help",submenu:o}));win.menu=u;win.on("dragover",function(e){e.preventDefault();e.originalEvent.dataTransfer.dropEffect="none"});win.on("drop",function(e){e.preventDefault()})}})();