<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## 使用 Electron 打開外部鏈接或文件管理器 Electron 中的 shell 模塊允許您訪問某些本地元素, 如文件管理器和默認 Web 瀏覽器. 此模塊在主進程和渲染器進程中都可以工作. 在瀏覽器中查看 完整 [API 文檔](http://electron.atom.io/docs/api/shell) ### 在文件管理器中打開路徑 `支持: Win, macOS, Linux | 進程: Both` 當前示例使用 shell 模塊在特定位置打開系統文件管理器. 單擊示例按鈕將在根目錄中打開文件管理器. ![](https://img.kancloud.cn/6c/fb/6cfb528b43d678d52fca39f981946a41_1020x632.png) 渲染器進程 ``` openFileManager () { const {shell} = require('electron') const os = require('os') shell.showItemInFolder(os.homedir()) }, ``` ### 打開外部鏈接 `支持: Win, macOS, Linux | 進程: Both` 如果您不希望在當前應用程序中打開網站鏈接, 可以使用 shell 模塊在外部打開. 當點擊鏈接之后將在用戶的默認瀏覽器中打開. 當點擊示例按鈕時, 將在您的瀏覽器中打開 Electron 的網站. ![](https://img.kancloud.cn/31/75/317568ebba8feb80e9e0075faab63758_954x545.png) 渲染器進程 ``` openExLink () { const {shell} = require('electron') shell.openExternal('http://electron.atom.io') } ``` ## 使用 Electron 調用系統對話框 Electron 中的 dialog 模塊允許您使用本地系統對話框打開文件或目錄, 保存文件或顯示信息性消息. 這是一個主進程模塊, 因為這個進程對于本地實用程序更有效, 它允許調用的同時而不會中斷頁面渲染器進程中的可見元素. 在瀏覽器中查看 完整 [API 文檔](http://electron.atom.io/docs/api/dialog/) ### 打開文件或目錄 `支持: Win, macOS, Linux | 進程: Main` 在本示例中, ipc 模塊用于從渲染器進程發送一條消息, 指示主進程啟動打開的文件(或目錄)對話框. 如果選擇了文件, 主進程可以將該信息發送回渲染器進程. ![](https://img.kancloud.cn/d2/d7/d2d7eb703162a37d6c633e21f7b223fe_1051x623.png) ![](https://img.kancloud.cn/45/e4/45e42a433e8a1a0eec236071550b2c7d_702x291.png) 渲染器進程 ``` openFileDir () { const {ipcRenderer} = require('electron') ipcRenderer.send('open-file-dialog') ipcRenderer.on('selected-directory', (event, path) => { this.checkedPath = `你已選擇: ${path}` }) }, ``` 主進程 ``` const {ipcMain, dialog} = require('electron') ipcMain.on('open-file-dialog', (event) => { dialog.showOpenDialog({ properties: ['openFile', 'openDirectory'] }, (files) => { if (files) { event.sender.send('selected-directory', files) } }) }) ``` ### 錯誤對話框 `支持: Win, macOS, Linux | 進程: Main` 在本示例中, ipc 模塊用于從渲染器進程發送一條消息, 指示主進程啟動錯誤對話框. 您可以在應用程序的 ready 事件之前使用錯誤對話框, 這對于在啟動時顯示錯誤很有用. ![](https://img.kancloud.cn/3d/d4/3dd44600751411861a05ce5c5453cf3f_740x366.png) 渲染器進程 ``` errorDialog () { const {ipcRenderer} = require('electron') ipcRenderer.send('open-error-dialog') }, ``` 主進程 ``` const {ipcMain, dialog} = require('electron') ipcMain.on('open-error-dialog', (event) => { dialog.showErrorBox('一條錯誤信息', '錯誤消息演示.') }) ``` ### 信息對話框 `支持: Win, macOS, Linux | 進程: Main` 在本示例中, ipc 模塊用于從渲染器進程發送一條消息, 指示主進程啟動信息對話框. 可以提供用于響應的選項, 響應會被返回到渲染器進程中. 一個信息對話框可以包含圖標, 選擇的按鈕, 標題和消息. ![](https://img.kancloud.cn/e5/c4/e5c4074941ac1d94e804e3677fd14e7e_775x352.png) ![](https://img.kancloud.cn/3f/51/3f51b3c6ad86f041c2cac17d20cbae0b_679x324.png) 渲染器進程 ``` infoDialog () { const {ipcRenderer} = require('electron') ipcRenderer.send('open-information-dialog') ipcRenderer.on('information-dialog-selection', (event, index) => { this.message = '你已選擇 ' if (index === 0) this.message += '是.' else this.message += '否.' }) }, ``` 主進程 ``` const {ipcMain, dialog} = require('electron') ipcMain.on('open-information-dialog', (event) => { const options = { type: 'info', title: '信息', message: "這是一個信息對話框. 很不錯吧?", buttons: ['是', '否'] } dialog.showMessageBox(options, (index) => { event.sender.send('information-dialog-selection', index) }) }) ``` ### 保存對話框 `支持: Win, macOS, Linux | 進程: Main` 在本示例中, ipc 模塊用于從渲染器進程發送一條消息, 指示主進程啟動保存對話框. 它返回由用戶選擇的路徑, 并可以將其路由回渲染器進程. ![](https://img.kancloud.cn/93/5e/935e16e9fc74a1841a74cf9e20714db8_1012x520.png) ![](https://img.kancloud.cn/db/7a/db7a9403312b67094fb18b5f626cd80b_750x289.png) 渲染器進程 ``` saveDialog () { const {ipcRenderer} = require('electron') ipcRenderer.send('save-dialog') ipcRenderer.on('saved-file', (event, path) => { if (!path) this.savedPath = '無路徑' this.savedPath = `已選擇的路徑: ${path}` }) } ``` 主進程 ``` const {ipcMain, dialog} = require('electron') ipcMain.on('save-dialog', (event) => { const options = { title: '保存圖像', filters: [ { name: 'Images', extensions: ['jpg', 'png', 'gif'] } ] } dialog.showSaveDialog(options, (filename) => { event.sender.send('saved-file', filename) }) }) ``` ## 使用 Electron 將應用程序放入托盤 使用 tray 模塊允許您在操作系統的通知區域中創建圖標. 此圖標還可以附加上下文菜單. 在瀏覽器中查看 完整 [API 文檔](http://electron.atom.io/docs/api/tray). ### 托盤 `支持: Win, macOS, Linux | 進程: Main` 示例按鈕使用 ipc 模塊向主進程發送消息. 在主進程中, 應用程序會被告知在托盤中放置一個帶有上下文菜單的圖標. 在此示例中, 可以通過單擊托盤圖標上下文菜單中的 "移除" 或再次點擊示例按鈕來刪除托盤圖標. ![](https://img.kancloud.cn/9c/1f/9c1f60e5d20ae477d28a665454c0125e_1058x675.png) ![](https://img.kancloud.cn/44/95/4495bffa36d6a19ea2ac0c78c57958f9_276x166.png) 渲染器進程 ``` putInTray () { const {ipcRenderer} = require('electron') if (this.trayOn) { this.trayOn = false this.message = '' ipcRenderer.send('remove-tray') } else { this.trayOn = true this.message = '再次點擊示例按鈕移除托盤.' ipcRenderer.send('put-in-tray') } // 從圖標上下文菜單中刪除托盤 ipcRenderer.on('tray-removed', function () { this.trayOn = false this.message = '' ipcRenderer.send('remove-tray') }) } ``` 主進程 ``` const path = require('path') const {ipcMain, app, Menu, Tray} = require('electron') let appIcon = null ipcMain.on('put-in-tray', (event) => { const iconName = process.platform === 'win32' ? 'windows-icon.png' : 'iconTemplate.png' const iconPath = `${__static}/` + iconName appIcon = new Tray(iconPath) const contextMenu = Menu.buildFromTemplate([{ label: '移除', click: () => { event.sender.send('tray-removed') } }]) appIcon.setToolTip('在托盤中的 Electron 示例.') appIcon.setContextMenu(contextMenu) }) ipcMain.on('remove-tray', () => { appIcon.destroy() }) app.on('window-all-closed', () => { if (appIcon) appIcon.destroy() }) ``` ## 使用 Electron 調用基本或附帶圖像的通知 使用 Electron 中的 notification 模塊可以允許你增加基本的桌面通知. Electron 允許開發者使用 HTML5 Notification API 發送通知, 并使用當前操作系統的原生通知 API 來顯示. 注意: 由于這是一個 HTML5 API, 它只能在渲染器進程中使用. 在瀏覽器中查看 完整 ?[API 文檔](https://electron.atom.io/docs/all/#notifications-windows-linux-macos) ### 基本通知 `支持: Win 7+, macOS, Linux (支持 libnotify) | 進程: 渲染器` 此示例演示了一個基本的通知. 只含有文字. ![](https://img.kancloud.cn/f6/38/f63877816155141dccb217cfefe3b4a1_1047x648.png) 渲染器進程 ``` notification () { const myNotification = new Notification('標題', { body: '通知正文內容' }) myNotification.onclick = () => { console.log('通知被點擊') } }, ``` ### 附帶圖像的通知 `支持: Win 7+, macOS, Linux (支持 libnotify) | 進程: 渲染器` 此示例演示了一個基本的通知. 同時含有文字和圖像. ![](https://img.kancloud.cn/69/12/6912a2db1ab72cd7a27eeac74c6787f8_1057x660.png) 渲染器進程 ``` noticeWithImage () { const myNotification = new Notification('附帶圖像的通知', { body: '短消息附帶自定義圖片', icon: require('../../assets/programming.png') }) myNotification.onclick = () => { console.log('通知被點擊') } } ``` ## 拖放文件 Electron 支持將文件和內容從 Web拖放到操作系統中. 在瀏覽器中查看完整 [API 文檔](https://www.electronjs.org/docs/tutorial/native-file-drag-drop) ### 拖動文件 `支持: Win, macOS, Linux | 進程: Both` 在這個示例中,webContents.startDrag() API 被調用以響應 ondragstart 事件. ![](https://img.kancloud.cn/c5/03/c503030567c5472dfa0440d17fce5859_591x581.png) 渲染器進程 ``` processDrag (event) { const {ipcRenderer} = require('electron') event.preventDefault() ipcRenderer.send('ondragstart', 'programming.png') } ``` 主進程 ``` const {ipcMain} = require('electron') const path = require('path') ipcMain.on('ondragstart', (event, filepath) => { const iconName = 'codeIcon.png' const iconPath = `${__static}/` + iconName event.sender.startDrag({ file: `${__static}/` + filepath, icon: iconPath }) }) ```
                  <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>

                              哎呀哎呀视频在线观看