-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #868
- Loading branch information
Showing
8 changed files
with
155 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
1. Install `electron-auto-updater` as app dependency. | ||
|
||
2. [Confugure publish](https://github.com/electron-userland/electron-builder/wiki/Options#buildpublish). | ||
|
||
3. Use `autoUpdater` from `electron-auto-updater` instead of `electron`, e.g. (ES 6): | ||
|
||
```js | ||
import {autoUpdater} from "electron-auto-updater" | ||
``` | ||
|
||
`electron-auto-updater` works in the same way as electron bundled, it allows you to avoid conditional statements and use the same API across platforms. | ||
|
||
4. Do not call `setFeedURL` on Windows. electron-builder automatically creates `app-update.yml` file for you on build in the `resources` (this file is internal, you don't need to be aware of it). But if need, you can — for example, to explicitly set `BintrayOptions`: | ||
```js | ||
{ | ||
provider: "bintray", | ||
owner: "actperepo", | ||
package: "no-versions", | ||
} | ||
``` | ||
Currently, `generic` (any HTTPS web server), `github` and `bintray` are supported. `latest.yml` will be generated in addition to installer for `generic` and `github` and must be uploaded also (in short: only `bintray` doesn't use `latest.yml` and this file must be not uploaded on Bintray). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Provider, FileInfo } from "./api" | ||
import { VersionInfo, GithubOptions, UpdateInfo } from "../../src/options/publishOptions" | ||
import { request, HttpError } from "../../src/publish/restApiRequest" | ||
import { validateUpdateInfo } from "./GenericProvider" | ||
import * as path from "path" | ||
|
||
export class GitHubProvider implements Provider<VersionInfo> { | ||
constructor(private readonly options: GithubOptions) { | ||
} | ||
|
||
async getLatestVersion(): Promise<UpdateInfo> { | ||
// do not use API to avoid limit | ||
const basePath = this.getBasePath() | ||
let version = (await request<Redirect>({hostname: "github.com", path: `${basePath}/latest`})).location | ||
const versionPosition = version.lastIndexOf("/") + 1 | ||
try { | ||
version = version.substring(version[versionPosition] === "v" ? versionPosition + 1 : versionPosition) | ||
} | ||
catch (e) { | ||
throw new Error(`Cannot parse extract version from location "${version}": ${e.stack || e.message}`) | ||
} | ||
|
||
let result: UpdateInfo | null = null | ||
try { | ||
result = await request<UpdateInfo>({hostname: "github.com", path: `https://github.com${basePath}/download/v${version}/latest.yml`}) | ||
} | ||
catch (e) { | ||
if (e instanceof HttpError && e.response.statusCode === 404) { | ||
throw new Error(`Cannot find latest.yml in the latest release artifacts: ${e.stack || e.message}`) | ||
} | ||
throw e | ||
} | ||
|
||
validateUpdateInfo(result) | ||
return result | ||
} | ||
|
||
private getBasePath() { | ||
return `/${this.options.owner}/${this.options.repo}/releases` | ||
} | ||
|
||
async getUpdateFile(versionInfo: UpdateInfo): Promise<FileInfo> { | ||
const basePath = this.getBasePath() | ||
// space is not supported on GitHub | ||
const name = path.posix.basename(versionInfo.path).replace(/ /g, "-") | ||
return { | ||
name: name, | ||
url: `https://github.com${basePath}/download/v${versionInfo.version}/${name}`, | ||
sha2: versionInfo.sha2, | ||
} | ||
} | ||
} | ||
|
||
interface Redirect { | ||
readonly location: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters