<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # node-webkit教程(7)Platform Service之APP > 作者:玄魂 > 來源:[node-webkit教程(7)Platform Service之APP](http://www.cnblogs.com/xuanhun/p/3670906.html) 從本篇文章開始,為您介紹Platform Services些列的API,本系列由以下類別: + App – 每個應用運行時全局api + Clipboard – 剪貼板 + Tray – 狀態欄圖標,消息通知 + File dialogs-文件選擇對話框 + Shell – 桌面相關 + Handling files and arguments-處理文件和相關參數 ## 7.1 APP 概述 APP類別的API 是針對當前正在運行的應用程序實例的,換個說法是進程級別的(這樣說還不準確,node-webkit每一個窗口在單獨進程中,應用本身是多進程的)。這些API和程序的啟動、關閉關系最密切。但是從目前文檔中的API來看,APP類別的API顯得不是很豐富。 新建appDemo.html和package.json文件。 package.json內容如下: ``` { "name": "app-demo", "main": "appDemo.html", "nodejs":true, "window": { "title": "appDemo", "toolbar": true, "width": 800, "height": 600, "resizable":true, "show_in_taskbar":true, "frame":true, "kiosk":false, "icon": "2655716405282662783.png", }, "webkit":{ "plugin":true } } ``` appDemo.html內容如下: ``` <html> <head> <title>appDemo</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body > <h1>app api 測試</h1> <script> // Load native UI library var gui = require('nw.gui'); var win = gui.Window.get(); </script> </body> </html> ``` ## 7.1 獲取APP對象 通過如下方式獲得APP對象: ``` // Load native UI library var gui = require('nw.gui'); var app = gui.App; ``` ## 7.2 獲取命令行參數 很多時候,我們啟動程序需要從命令行輸入參數,可以通過argv、fullArgv和filteredArgv獲取輸入參數。關于三者的區別參考:[https://github.com/rogerwang/node-webkit/wiki/App#fullargv](https://github.com/rogerwang/node-webkit/wiki/App#fullargv)。我的測試結果和文檔還是有出入的。 修改appDemo.html如下: ``` <html> <head> <title>appDemo</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body > <h1>app api 測試</h1> <script> // Load native UI library var gui = require('nw.gui'); var app = gui.App; apendText(app.argv); apendText(app.fullArgv); apendText(app.filteredArgv); function apendText(text) { var element = document.createElement('div'); element.appendChild(document.createTextNode(text)); document.body.appendChild(element); } </script> </body> </html> ``` 在命令行啟動程序: ![](img/171535035886773.jpg) 運行結果如下: ![](img/171535093534811.png) ## 7.3 dataPath 應用的數據存儲目錄,在不同的操作系統上路徑不同, + Windows: `%LOCALAPPDATA%/<name>` + Linux: `~/.config/<name>`; + OSX:`~/Library/Application Support/<name>` 這里的`<name>`是在package.json中定義的name字段的值,所以需要在定義name值的時候保證全局唯一。 ## 7.4 獲取manifest 使用manifest屬性,可以獲取package.json中的json對象。修改appDemo。html的腳本內容如下: ``` <script> // Load native UI library var gui = require('nw.gui'); var app = gui.App; var manifest = app.manifest; apendText(manifest.name); function apendText(text) { var element = document.createElement('div'); element.appendChild(document.createTextNode(text)); document.body.appendChild(element); } </script> ``` 結果如下: ![](img/171535157918178.png) ## 7.5 清除緩存 可以調用clearCache()方法,清除應用在內存和磁盤上的緩存。 ## 7.6 關閉程序 關閉程序有兩個函數可以調用,分別為closeAllWindows()和quit()方法,兩者的區別在于closeAllWindows()方法會發送窗口的關閉消息,我們可以監聽close事件(參考:[http://www.xuanhun521.com/Blog/2014/4/14/node-webkit%E5%AD%A6%E4%B9%A04native-ui-api-%E4%B9%8Bwindow](http://www.xuanhun521.com/Blog/2014/4/14/node-webkit%E5%AD%A6%E4%B9%A04native-ui-api-%E4%B9%8Bwindow)),阻止窗口關閉或者做其他日志等工作。quit()方法不會發送任何消息,直接退出程序。 ## 7.7 Crash dump 從node-webkit 0.8.0版本開始,如果應用崩潰,一個`minidump` 文件會被保存到磁盤,用以調試和尋找程序崩潰的原因。默認情況下,dump文件保存在系統的臨時文件夾中,我們也可以通過api來設置dump文件的存放目錄。以下是個版本系統的臨時目錄: + Linux: `/tmp` + Windows: [System temporary directory](http://msdn.microsoft.com/en-us/library/windows/desktop/aa364992%28v=vs.85%29.aspx) + Mac: `~/Library/Breakpad/product name` (product name is defined in .plist file in the application bundle) 為了方便測試,node-webkit提供了App.crashBrowser()和App.crashRenderer()兩個api,分別保存browser 進程和render進程的數據。下面我們通過實例演示將dump文件保存到本地磁盤D。 ``` <script> // Load native UI library var gui = require('nw.gui'); var app = gui.App; app.setCrashDumpDir('d:\\');//設置轉儲目錄 app.crashBrowser(); app.crashRenderer(); function apendText(text) { var element = document.createElement('div'); element.appendChild(document.createTextNode(text)); document.body.appendChild(element); } </script> ``` 運行程序,應用啟動后會崩潰退出,在D盤會看到轉儲文件: ![](img/171535226199258.png) 如何查看轉儲文件,這里就不詳細介紹了,會在專門的文章中講解,讀者現在可以參考文檔中的鏈接: ### Decoding the stack trace To extract the stack trace from the minidump file, you need the `minidump_stackwalk` tool, symbols file of node-webkit binary and the minidump (.dmp) file generated from the crash. See [http://www.chromium.org/developers/decoding-crash-dumps](http://www.chromium.org/developers/decoding-crash-dumps) [http://code.google.com/p/google-breakpad/wiki/GettingStartedWithBreakpad](http://code.google.com/p/google-breakpad/wiki/GettingStartedWithBreakpad) Symbols file of official node-webkit binary is provided staring from 0.8.0\. It can be downloaded from: ### Resources **Linux symbol files of breakpad** [https://s3.amazonaws.com/node-webkit/v0.8.0/nw.breakpad.ia32.gz](https://s3.amazonaws.com/node-webkit/v0.8.0/nw.breakpad.ia32.gz) [https://s3.amazonaws.com/node-webkit/v0.8.0/nw.breakpad.x64.gz](https://s3.amazonaws.com/node-webkit/v0.8.0/nw.breakpad.x64.gz) **windows pdb file** [https://s3.amazonaws.com/node-webkit/v0.8.0/nw.exe.pdb.zip](https://s3.amazonaws.com/node-webkit/v0.8.0/nw.exe.pdb.zip) **mac dSYM files** [https://s3.amazonaws.com/node-webkit/v0.8.0/node-webkit-osx-dsym-v0.8.0.tar.gz](https://s3.amazonaws.com/node-webkit/v0.8.0/node-webkit-osx-dsym-v0.8.0.tar.gz) ## 7.8 獲取代理 使用getProxyForURL(url),可以獲得加載該url時使用的代理信息。返回值使用PAC格式(參考:[http://en.wikipedia.org/wiki/Proxy_auto-config](http://en.wikipedia.org/wiki/Proxy_auto-config))。 ## 7.9 小結 本文內容主要參考node-webkit的官方英文文檔,做了適當的調整([https://github.com/rogerwang/node-webkit/wiki/App](https://github.com/rogerwang/node-webkit/wiki/App), [https://github.com/rogerwang/node-webkit/wiki/Crash-dump](https://github.com/rogerwang/node-webkit/wiki/Crash-dump))。 下一篇文章,介紹Clipboard。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看