2016-10-04 13 views
-1

誰も電子から自動更新機能を使用する方法を最初から説明することはできますか?正しいパッケージを使用して正しいCLIを書いて、Windowsで自動更新される単純なアプリケーションを作成する方法。電子自動更新Windows

多くのありがとうございます。

答えて

0

私は試しましたelectron-basic-updater, electron-asar-updater, electron-installer-windowsなどアプリのリリース/更新方法を試してみるまで、electron-packager(パッケージング用)、Squirrel(自動アップデート用)です。彼らには利点があります。

私は読者が電子アプリを使って作業するための基本的なノウハウを持っていると仮定しているため、私は基本的なことには進んでいません。

重要な注意: Windowsでパッケージ/インストーラを作成して動作するように自動アップデータのためのアプリをインストールする必要があります!

あなたのメインapp.jsでは、更新のシナリオを処理するためにIPCを追加します。

ipcMain.on('check-for-update', function(event, arg) { 

/* AUTO UPDATER */ 
const autoUpdater = electron.autoUpdater; 
const os = require('os'); 
const {dialog} = require('electron'); 

/* For Windows, PATH to DIRECTORY that has nupkg and RELEASES files (Windows alone) */ 
/* And add "Options Indexes" to htaccess if you want listing on that dir [email protected] */ 

var releaseDIR = config.webURL + '/releases/win' + (os.arch() === 'x64' ? '64' : '32'); 

autoUpdater.setFeedURL(releaseDIR); 

autoUpdater 
    .on('error', function(error){ 
     loggit(error); 
     return dialog.showMessageBox(mainWindow, { 
      type: 'info', 
      icon: basePath + "/assets/refico32.ico", 
      buttons: ['Dang!'], 
      title: appName + ": Update Error", 
      message: "Something's not right out there. Please try again later.", 
      detail: "Umm... \nIt's not you, it's the server" 
     }); 
    }) 
    .on('checking-for-update', function(e) { 
     loggit('Checking for update at ' + releaseDIR); 
    }) 
    .on('update-available', function(e) { 

     var downloadConfirmation = dialog.showMessageBox(mainWindow, { 
      type: 'info', 
      icon: basePath + "/assets/refico32.ico", 
      buttons: ['Proceed'], 
      title: appName + ": Update Available", 
      message: 'An update is available. The update will be downloaded in the background.', 
      detail: "Size: ~42 MB" 
     }); 

     loggit('Downloading update'); 

     if (downloadConfirmation === 0) { 
      return; 
     } 

    }) 
    .on('update-not-available', function(e) { 
     loggit('Update not available'); 
     return dialog.showMessageBox(mainWindow, { 
      type: 'info', 
      icon: basePath + "/assets/refico32.ico", 
      buttons: ['Cool'], 
      title: appName + ": No update available", 
      message: "It seems you're running the latest and greatest version", 
      detail: "Woot, woot! \nTalk about being tech-savvy" 
     }); 
    }) 
    .on('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) { 

     var index = dialog.showMessageBox(mainWindow, { 
      type: 'info', 
      icon: basePath + "/assets/refico32.ico", 
      buttons: ['Install Update','Later'], 
      title: appName + ": Latest version downloaded", 
      message: 'Please restart the app to apply the update', 
      detail: releaseName + "\n\n" + releaseNotes 
     }); 

     if (index === 1) return; 

     force_quit = true; 
     autoUpdater.quitAndInstall(); 
    }); 


autoUpdater.checkForUpdates(); 

event.returnValue = "Checking for updates: " + releaseDIR + " Install Path: " + appPath; 
}); 

追加メモ: 1]冒頭でリスのイベントを処理する必要がありますあなたのapp.js。 handleSquirrelEventのハンドラを書くことも、単純なif (require('electron-squirrel-startup')) return;のハンドラを書くこともできます。 2]これを書いている時点で、自動更新プロセスが開始されると、ユーザーが更新プロセスをキャンセルする方法はありません。

あなたのインストーラを作成するために、(npm install grunt, npm install grunt-cli後に)あなたのGruntfile.js現在

module.exports = function(grunt) { 
    grunt.loadNpmTasks('grunt-electron-installer'); 
    grunt.initConfig({ 
     'create-windows-installer': { 
     'ia32': { 
      appDirectory: "C:\\refreshie\\app\\build\\Refreshie-win32-ia32", 
      outputDirectory: "C:\\refreshie\\app\\build\\Distro\\Refreshie-Win-ia32", 
      loadingGif: "C:\\refreshie\\app\\assets\\images\\install.splash.gif", 
      iconUrl: "C:\\refreshie\\app\\assets\\refico.ico", 
      setupIcon: "C:\\refreshie\\app\\assets\\refico.ico", 
      signWithParams: "/a /f C:\\refreshie\\app\\build\\tools\\cert.signingkey.pfx /p F5", 
      noMsi: true 
     } 
    } 
    }); 
    grunt.registerTask('default', ['create-windows-installer']); 
}; 
0

のようなものである必要があり、電子自動更新を行うための最善の方法は、電子ビルダーを使用しています。電子builer -save-devの

NPMはデモ目的のために

-save電子アップデータをインストール

NPMをインストールし、GET HTTPサーバ、あなたのWebホストサーバとして。

NPMは、-save

ビルドパッケージは非常に簡単です - サーバーのhttpをインストールする2つのフォルダ "の構築" と "DIST" を作成し、その後、 はpackage.jsonスクリプトでこれを追加して実行

"scripts": { 
    "start": "set NODE_ENV=dev&& tsc && concurrently \"npm run tsc:w\" \"electron .\" ", 
    "tsc": "tsc", 
    "tsc:w": "tsc -w", 
    ; 
    "dist": "build -w --x64", 
    "wb": "http-server wwwroot/ -p 8080", 
     ; 
}, 

NPMの実行distの

としてフォルダwwwrootにを作成し、それはあなたのウェブホストサーバであると仮定し、あなたのウェブサイトを開始するには、自動アップデータについて:フォルダをwwwrootのためにdistのフォルダからverything

コピーをWB

NPMラン。

これを行った。

完全な詳細コード

ため hereを参照してください。
関連する問題