From ea3f00b808a306ab8d98188cce550e30199a25b7 Mon Sep 17 00:00:00 2001 From: Son NK Date: Tue, 8 Nov 2022 18:18:30 +0100 Subject: [PATCH] add MAC variant for build --- .github/workflows/release.yaml | 10 +++++++- README.md | 6 +++++ package.json | 4 +++- src/manifest.json | 1 - src/popup/components/AppSettings.vue | 12 ++++------ src/popup/components/Main.vue | 34 ++++++++++++---------------- webpack.config.js | 16 +++++++++++++ 7 files changed, 54 insertions(+), 29 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 121c127..21acceb 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -78,7 +78,7 @@ jobs: strategy: max-parallel: 4 matrix: - variant: ['full', 'lite'] + variant: ['full', 'lite', 'mac'] steps: - name: Build info @@ -136,6 +136,14 @@ jobs: npm run build npm run build-zip + - name: Build Mac version + if: matrix.variant == 'mac' + shell: bash + run: | + npm install + npm run build:mac + npm run build-zip + - name: Package extension run: | ZIP_NAME=$(find dist-zip -type f -name '*.zip' | head -n 1) diff --git a/README.md b/README.md index 33fe78f..4e25b00 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,12 @@ In order to build the extension yourself, please follow these steps: - (Optional, only useful for beta build) Build beta version: change `betaRev` in `package.json`, then generate zip file using +## How to build a version for Mac + +For the development, you can run `npm run start:mac` for the Mac app. + +For the production release, `npm run build:mac` + ```bash npm run build:beta && npm run build-zip ``` \ No newline at end of file diff --git a/package.json b/package.json index ef03020..eb37417 100644 --- a/package.json +++ b/package.json @@ -13,11 +13,13 @@ "build:lite": "cross-env NODE_ENV=production LITE=1 webpack", "build:beta": "cross-env NODE_ENV=production BETA=1 webpack", "build:dev": "cross-env NODE_ENV=development BETA=1 webpack", + "build:mac": "cross-env NODE_ENV=production MAC=1 webpack", "build-zip": "node scripts/build-zip.js", "generate:buildconfig": "node scripts/generateBuildConfig.js", "watch": "npm run build -- --watch", "watch:dev": "cross-env HMR=true npm run build:dev -- --watch", - "start": "cross-env HMR=true npm run build:dev -- --watch" + "start": "cross-env HMR=true npm run build:dev -- --watch", + "start:mac": "cross-env HMR=true MAC=1 npm run build:dev -- --watch" }, "dependencies": { "@fortawesome/fontawesome-svg-core": "^1.2.36", diff --git a/src/manifest.json b/src/manifest.json index 466d06d..fa48112 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -15,7 +15,6 @@ "activeTab", "storage", "contextMenus", - "nativeMessaging", "https://*.simplelogin.io/*", "http://*/*", "https://*/*" diff --git a/src/popup/components/AppSettings.vue b/src/popup/components/AppSettings.vue index c9ece7f..a12c006 100644 --- a/src/popup/components/AppSettings.vue +++ b/src/popup/components/AppSettings.vue @@ -186,16 +186,14 @@ export default { EventManager.broadcast(EventManager.EVENT.SETTINGS_CHANGED); Navigation.clearHistoryAndNavigateTo(Navigation.PATH.LOGIN); - try { + if (process.env.MAC) { console.log("send log out event to host app"); - let r = await browser.runtime.sendNativeMessage( + await browser.runtime.sendNativeMessage( "application.id", JSON.stringify({ logged_out: {}, }) ); - } catch (error) { - console.info("can't send data to native app", error); } }, @@ -208,15 +206,15 @@ export default { this.reportURISLButton = `mailto:extension@simplelogin.io?subject=${subject}&body=${body}`; }, async upgrade() { - try { + if (process.env.MAC) { console.log("send upgrade event to host app"); - let r = await browser.runtime.sendNativeMessage( + await browser.runtime.sendNativeMessage( "application.id", JSON.stringify({ upgrade: {}, }) ); - } catch (error) { + } else { console.info("can't send data to native app", error); let apiUrl = await SLStorage.get(SLStorage.SETTINGS.API_URL); let upgradeURL = apiUrl + "/dashboard/pricing"; diff --git a/src/popup/components/Main.vue b/src/popup/components/Main.vue index fcf84cc..3757036 100644 --- a/src/popup/components/Main.vue +++ b/src/popup/components/Main.vue @@ -262,23 +262,19 @@ export default { this.apiUrl = await SLStorage.get(SLStorage.SETTINGS.API_URL); this.apiKey = await SLStorage.get(SLStorage.SETTINGS.API_KEY); - if (this.apiKey) { - try { - console.log("send api key to host app"); - let r = await browser.runtime.sendNativeMessage( - "application.id", - JSON.stringify({ - logged_in: { - data: { - api_key: this.apiKey, - api_url: this.apiUrl, - }, + if (this.apiKey && process.env.MAC) { + console.log("send api key to host app"); + await browser.runtime.sendNativeMessage( + "application.id", + JSON.stringify({ + logged_in: { + data: { + api_key: this.apiKey, + api_url: this.apiUrl, }, - }) - ); - } catch (error) { - console.info("can't send data to native app", error); - } + }, + }) + ); } this.contentElem = document.querySelector(".app > .content"); @@ -528,15 +524,15 @@ export default { }, async upgrade() { - try { + if (process.env.MAC) { console.log("send upgrade event to host app"); - let r = await browser.runtime.sendNativeMessage( + await browser.runtime.sendNativeMessage( "application.id", JSON.stringify({ upgrade: {}, }) ); - } catch (error) { + } else { console.info("can't send data to native app", error); let upgradeURL = this.apiUrl + "/dashboard/pricing"; browser.tabs.create({ url: upgradeURL }); diff --git a/webpack.config.js b/webpack.config.js index d3d1249..13717a8 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -138,6 +138,14 @@ const config = { jsonContent.short_name = "SimpleLogin Without SL icon"; } + if (process.env.MAC) { + jsonContent.permissions.push("nativeMessaging"); + + // Change metadata + jsonContent.name = "SimpleLogin Mac App"; + jsonContent.short_name = "SimpleLogin Mac App"; + } + return JSON.stringify(jsonContent, null, 2); }, }, @@ -155,6 +163,14 @@ if (config.mode === 'development') { ]); } +if (process.env.MAC){ + config.plugins = (config.plugins || []).concat([ + new webpack.DefinePlugin({ + 'process.env.MAC': JSON.stringify(!!process.env.MAC), + }), + ]); +} + if (config.mode === 'production') { config.plugins = (config.plugins || []).concat([ new webpack.DefinePlugin({