Merge pull request #3404 from Rummskartoffel/windows-update

Windows: Fix native updating
This commit is contained in:
Oliver Blanthorn 2021-02-28 13:15:26 +00:00 committed by GitHub
commit ac2b061093
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 10 deletions

View file

@ -92,6 +92,7 @@ import * as TTS from "@src/lib/text_to_speech"
import * as excmd_parser from "@src/parsers/exmode"
import * as escape from "@src/lib/escape"
import * as R from "ramda"
import * as semverCompare from "semver-compare"
/**
* This is used to drive some excmd handling in `composite`.
@ -832,16 +833,29 @@ export async function source_quiet(...args: string[]) {
*/
//#background
export async function updatenative(interactive = true) {
const tag = TRI_VERSION.includes("pre") ? "master" : TRI_VERSION
if (await Native.nativegate("0", interactive)) {
if ((await browser.runtime.getPlatformInfo()).os === "mac") {
if (interactive) logger.error("Updating the native messenger on OSX is broken. Please use `:nativeinstall` instead.")
return
}
await Native.run((await config.get("nativeinstallcmd")).replace("%TAG", tag))
if (interactive) native()
if (!(await Native.nativegate("0", interactive))) {
return
} else if ((await browser.runtime.getPlatformInfo()).os === "mac") {
if (interactive) logger.error("Updating the native messenger on OSX is broken. Please use `:nativeinstall` instead.")
return
}
const tag = TRI_VERSION.includes("pre") ? "master" : TRI_VERSION
const update_command = (await config.get("nativeinstallcmd")).replace("%TAG", tag)
const native_version = await Native.getNativeMessengerVersion()
if (semverCompare(native_version, "0.2.0") < 0) {
await Native.run(update_command)
} else if (semverCompare(native_version, "0.3.1") < 0) {
if (interactive) {
throw new Error("Updating is broken on this version of the native messenger. Please use `:nativeinstall` instead.")
}
return
} else {
await Native.runAsync(update_command)
}
if (interactive) native()
}
/**

View file

@ -1151,7 +1151,11 @@ const platform_defaults = {
"<C-6>": "buffer #",
} as unknown,
nativeinstallcmd: `powershell -NoProfile -Command "(New-Object System.Net.WebClient).DownloadFile('https://raw.githubusercontent.com/tridactyl/native_messenger/master/installers/windows.ps1', """$env:temp/tridactyl_installnative.ps1""")" & powershell -NoProfile -File %temp%\\tridactyl_installnative.ps1 -Tag %TAG & del %temp%\\tridactyl_installnative.ps1`,
nativeinstallcmd: `powershell -NoProfile -Command "\
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12;\
(New-Object System.Net.WebClient).DownloadFile('https://raw.githubusercontent.com/tridactyl/native_messenger/master/installers/windows.ps1', '%TEMP%/tridactyl_installnative.ps1');\
& '%TEMP%/tridactyl_installnative.ps1' -Tag %TAG;\
Remove-Item '%TEMP%/tridactyl_installnative.ps1'"`,
},
linux: {
nmaps: {

View file

@ -13,6 +13,7 @@ const NATIVE_NAME = "tridactyl"
type MessageCommand =
| "version"
| "run"
| "run_async"
| "read"
| "write"
| "writerc"
@ -383,6 +384,16 @@ export async function run(command: string, content = "") {
return msg
}
export async function runAsync(command: string) {
const required_version = "0.3.1"
if (!await nativegate(required_version, false)) {
throw new Error(
`runAsync needs native messenger version >= ${required_version}.`,
)
}
logger.info(await sendNativeMsg("run_async", { command }))
}
/** Evaluates a string in the native messenger. This has to be python code. If
* you want to run shell strings, use run() instead.
*