From 8cf44780ceec054c61b7e36cd460d8d20eb232af Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 20 Jul 2019 12:17:59 +0200 Subject: [PATCH] release scripts + check of version compatibility --- bin/release-chrome.sh | 25 +++++++++++++++++ bin/{build-firefox.sh => release-firefox.sh} | 4 +-- bin/release.sh | 12 ++++++-- manifest.json | 2 +- popup/popup.js | 6 ++++ trilium_server_facade.js | 29 ++++++++++++++++++-- 6 files changed, 69 insertions(+), 9 deletions(-) create mode 100755 bin/release-chrome.sh rename bin/{build-firefox.sh => release-firefox.sh} (80%) diff --git a/bin/release-chrome.sh b/bin/release-chrome.sh new file mode 100755 index 000000000..1ca4c7592 --- /dev/null +++ b/bin/release-chrome.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +VERSION=$(jq -r ".version" manifest.json) +CHROME_EXTENSION_ID=dfhgmnfclbebfobmblelddiejjcijbjm + +BUILD_DIR=trilium-web-clipper-chrome + +rm -rf dist +mkdir -p "dist/$BUILD_DIR" + +cp -r icons lib options popup *.js manifest.json "dist/$BUILD_DIR" + +cd dist/"${BUILD_DIR}" || exit + +jq '.name = "Trilium Web Clipper"' manifest.json | sponge manifest.json +jq 'del(.browser_specific_settings)' manifest.json | sponge manifest.json + +EXT_FILE_NAME=trilium_web_clipper-${VERSION}-chrome.crx + +zip -r ../${EXT_FILE_NAME} * + +cd .. +rm -r "${BUILD_DIR}" + +webstore upload --source ${EXT_FILE_NAME} --auto-publish --extension-id "${CHROME_EXTENSION_ID}" --client-id "${CHROME_CLIENT_ID}" --client-secret "${CHROME_CLIENT_SECRET}" --refresh-token "${CHROME_REFRESH_TOKEN}" \ No newline at end of file diff --git a/bin/build-firefox.sh b/bin/release-firefox.sh similarity index 80% rename from bin/build-firefox.sh rename to bin/release-firefox.sh index c459fe978..daa1c30b2 100755 --- a/bin/build-firefox.sh +++ b/bin/release-firefox.sh @@ -2,8 +2,6 @@ WEB_EXT_ID="{1410742d-b377-40e7-a9db-63dc9c6ec99c}" -VERSION=$(jq -r ".version" manifest.json) - ARTIFACT_NAME=trilium-web-clipper-firefox BUILD_DIR=dist/$ARTIFACT_NAME @@ -16,7 +14,7 @@ cd dist/"${ARTIFACT_NAME}" || exit jq '.name = "Trilium Web Clipper"' manifest.json | sponge manifest.json -web-ext sign --id ${WEB_EXT_ID} --artifacts-dir ../ +web-ext sign --id ${WEB_EXT_ID} --artifacts-dir ../ --channel=listed cd .. rm -r "${ARTIFACT_NAME}" \ No newline at end of file diff --git a/bin/release.sh b/bin/release.sh index 176df3b8f..83bd8b0bb 100755 --- a/bin/release.sh +++ b/bin/release.sh @@ -42,9 +42,10 @@ echo "Tagging commit with $TAG" git tag "$TAG" git push origin "$TAG" -bin/build-firefox.sh +bin/release-firefox.sh FIREFOX_BUILD=trilium_web_clipper-$VERSION-an+fx.xpi +CHROME_BUILD=trilium_web_clipper-${VERSION}-chrome.crx echo "Creating release in GitHub" @@ -52,11 +53,18 @@ github-release release \ --tag "$TAG" \ --name "$TAG release" -echo "Uploading build package" +echo "Uploading firefox build package" github-release upload \ --tag "$TAG" \ --name "$FIREFOX_BUILD" \ --file "dist/$FIREFOX_BUILD" +echo "Uploading chrome build package" + +github-release upload \ + --tag "$TAG" \ + --name "$CHROME_BUILD" \ + --file "dist/$CHROME_BUILD" + echo "Release finished!" \ No newline at end of file diff --git a/manifest.json b/manifest.json index 174e2648d..f233d2aff 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Trilium Web Clipper (dev)", - "version": "0.1.0", + "version": "0.0.1", "description": "Save web clippings to Trilium Notes.", "homepage_url": "https://github.com/zadam/trilium-web-clipper", "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'", diff --git a/popup/popup.js b/popup/popup.js index bb0cdd5d6..ff61ca423 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -105,6 +105,12 @@ browser.runtime.onMessage.addListener(request => { statusText = `Not found`; isConnected = false; } + else if (triliumSearch.status === 'version-mismatch') { + const whatToUpgrade = triliumSearch.extensionMajor > triliumSearch.triliumMajor ? "Trilium Notes" : "this extension"; + + statusText = `Trilium instance found, but it is not compatible with this extension version. Please update ${whatToUpgrade} to the latest version.`; + isConnected = true; + } else if (triliumSearch.status === 'found-desktop') { statusText = `Connected on port ${triliumSearch.port}`; isConnected = true; diff --git a/trilium_server_facade.js b/trilium_server_facade.js index 8228e76e9..1205544c2 100644 --- a/trilium_server_facade.js +++ b/trilium_server_facade.js @@ -1,3 +1,5 @@ +const PROTOCOL_VERSION_MAJOR = 2; + function isDevEnv() { const manifest = browser.runtime.getManifest(); @@ -28,11 +30,31 @@ class TriliumServerFacade { this.sendTriliumSearchStatusToPopup(); } + setTriliumSearchWithVersionCheck(json, resp) { + const [major, minor] = json.protocolVersion + .split(".") + .map(chunk => parseInt(chunk)); + + // minor version is intended to be used to dynamically limit features provided by extension + // if some specific Trilium API is not supported. So far not needed. + + if (major !== PROTOCOL_VERSION_MAJOR) { + this.setTriliumSearch({ + status: 'version-mismatch', + extensionMajor: PROTOCOL_VERSION_MAJOR, + triliumMajor: major + }); + } + else { + this.setTriliumSearch(resp); + } + } + async triggerSearchForTrilium() { this.setTriliumSearch({ status: 'searching' }); const startingPort = await this.getStartingPort(); - + for (let testedPort = startingPort; testedPort < startingPort + 10; testedPort++) { try { console.debug('Trying port ' + testedPort); @@ -46,7 +68,7 @@ class TriliumServerFacade { const json = JSON.parse(text); if (json.appName === 'trilium') { - this.setTriliumSearch({ + this.setTriliumSearchWithVersionCheck(json, { status: 'found-desktop', port: testedPort, url: 'http://127.0.0.1:' + testedPort @@ -78,11 +100,12 @@ class TriliumServerFacade { const json = JSON.parse(text); if (json.appName === 'trilium') { - this.setTriliumSearch({ + this.setTriliumSearchWithVersionCheck(json, { status: 'found-server', url: triliumServerUrl, token: authToken }); + return; } }