diff --git a/updater/.gitlab/actions/release/action.yml b/updater/.gitlab/actions/release/action.yml new file mode 100644 index 0000000..1f361f6 --- /dev/null +++ b/updater/.gitlab/actions/release/action.yml @@ -0,0 +1,61 @@ +name: Electron Builder Action +author: Samuel Meuli +description: GitHub Action for building and releasing Electron apps + +inputs: + github_token: + description: GitHub authentication token + required: true + mac_certs: + description: Base64-encoded code signing certificate for macOS + required: false + mac_certs_password: + description: Password for decrypting `mac_certs` + required: false + release: + description: Whether the app should be released after a successful build + required: false + default: false + windows_certs: + description: Base64-encoded code signing certificate for Windows + required: false + windows_certs_password: + description: Password for decrypting `windows_certs` + required: false + package_root: + description: Directory where NPM/Yarn commands should be run + required: false + default: "." + build_script_name: + description: Name of the optional NPM build script which is executed before `electron-builder` + required: false + default: build + skip_build: + description: Whether the action should execute the NPM build script before running `electron-builder` + required: false + default: false + use_vue_cli: + description: Whether to run `electron-builder` using the Vue CLI plugin instead of calling the command directly + required: false + default: false + args: + description: Other arguments to pass to the `electron-builder` command, e.g. configuration overrides + required: false + default: "" + max_attempts: + description: Maximum number of attempts for completing the build and release step + required: false + default: "1" + + # Deprecated + app_root: + description: Directory where `electron-builder` commands should be run + required: false + +runs: + using: node12 + main: index.js + +branding: + icon: upload-cloud + color: blue \ No newline at end of file diff --git a/updater/.gitlab/actions/release/index.js b/updater/.gitlab/actions/release/index.js new file mode 100644 index 0000000..1e6f33e --- /dev/null +++ b/updater/.gitlab/actions/release/index.js @@ -0,0 +1,156 @@ +const { execSync } = require("child_process"); +const { existsSync, readFileSync } = require("fs"); +const { join } = require("path"); + +/** + * Logs to the console + */ +const log = (msg) => console.log(`\n${msg}`); // eslint-disable-line no-console + +/** + * Exits the current process with an error code and message + */ +const exit = (msg) => { + console.error(msg); + process.exit(1); +}; + +/** + * Executes the provided shell command and redirects stdout/stderr to the console + */ +const run = (cmd, cwd) => execSync(cmd, { encoding: "utf8", stdio: "inherit", cwd }); + +/** + * Determines the current operating system (one of ["mac", "windows", "linux"]) + */ +const getPlatform = () => { + switch (process.platform) { + case "darwin": + return "mac"; + case "win32": + return "windows"; + default: + return "linux"; + } +}; + +/** + * Returns the value for an environment variable (or `null` if it's not defined) + */ +const getEnv = (name) => process.env[name.toUpperCase()] || null; + +/** + * Sets the specified env variable if the value isn't empty + */ +const setEnv = (name, value) => { + if (value) { + process.env[name.toUpperCase()] = value.toString(); + } +}; + +/** + * Returns the value for an input variable (or `null` if it's not defined). If the variable is + * required and doesn't have a value, abort the action + */ +const getInput = (name, required) => { + const value = getEnv(`INPUT_${name}`); + if (required && !value) { + exit(`"${name}" input variable is not defined`); + } + return value; +}; + +/** + * Installs NPM dependencies and builds/releases the Electron app + */ +const runAction = () => { + const platform = getPlatform(); + const release = getInput("release", true) === "true"; + const pkgRoot = getInput("package_root", true); + const buildScriptName = getInput("build_script_name", true); + const skipBuild = getInput("skip_build") === "true"; + const useVueCli = getInput("use_vue_cli") === "true"; + const args = getInput("args") || ""; + const maxAttempts = Number(getInput("max_attempts") || "1"); + + // TODO: Deprecated option, remove in v2.0. `electron-builder` always requires a `package.json` in + // the same directory as the Electron app, so the `package_root` option should be used instead + const appRoot = getInput("app_root") || pkgRoot; + + const pkgJsonPath = join(pkgRoot, "package.json"); + const pkgLockPath = join(pkgRoot, "package-lock.json"); + + // Determine whether NPM should be used to run commands (instead of Yarn, which is the default) + const useNpm = existsSync(pkgLockPath); + log(`Will run ${useNpm ? "NPM" : "Yarn"} commands in directory "${pkgRoot}"`); + + // Make sure `package.json` file exists + if (!existsSync(pkgJsonPath)) { + exit(`\`package.json\` file not found at path "${pkgJsonPath}"`); + } + + // Copy "github_token" input variable to "GH_TOKEN" env variable (required by `electron-builder`) + setEnv("GH_TOKEN", getInput("github_token", true)); + + // Require code signing certificate and password if building for macOS. Export them to environment + // variables (required by `electron-builder`) + if (platform === "mac") { + const mac_certs = getInput("mac_certs"); + const mac_certs_password = getInput("mac_certs_password"); + if (mac_certs && mac_certs_password) { + setEnv("CSC_LINK", mac_certs); + setEnv("CSC_KEY_PASSWORD", mac_certs_password); + } else { + setEnv("CSC_IDENTITY_AUTO_DISCOVERY", "false"); + } + } else if (platform === "windows") { + setEnv("CSC_LINK", getInput("windows_certs")); + setEnv("CSC_KEY_PASSWORD", getInput("windows_certs_password")); + } + + // Disable console advertisements during install phase + setEnv("ADBLOCK", true); + + // log(`Installing dependencies using ${useNpm ? "NPM" : "Yarn"}…`); + // run(useNpm ? "npm install" : "yarn", pkgRoot); + + // Run NPM build script if it exists + if (skipBuild) { + log("Skipping build script because `skip_build` option is set"); + } else { + log("Running the build script…"); + if (useNpm) { + run(`npm run ${buildScriptName} --if-present`, pkgRoot); + } else { + // TODO: Use `yarn run ${buildScriptName} --if-present` once supported + // https://github.com/yarnpkg/yarn/issues/6894 + const pkgJson = JSON.parse(readFileSync(pkgJsonPath, "utf8")); + if (pkgJson.scripts && pkgJson.scripts[buildScriptName]) { + run(`yarn run ${buildScriptName}`, pkgRoot); + } + } + } + + log(`Building${release ? " and releasing" : ""} the Electron app…`); + const cmd = useVueCli ? "vue-cli-service electron:build" : `electron-builder`; + for (let i = 0; i < maxAttempts; i += 1) { + try { + run( + `${useNpm ? "npx --no-install" : "yarn run"} ${cmd} --${platform} ${ + release ? "--publish always" : "" + } ${args}`, + appRoot, + ); + break; + } catch (err) { + if (i < maxAttempts - 1) { + log(`Attempt ${i + 1} failed:`); + log(err); + } else { + throw err; + } + } + } +}; + +runAction(); \ No newline at end of file diff --git a/updater/.gitlab/workflows/build.yml b/updater/.gitlab/workflows/build.yml new file mode 100644 index 0000000..81eb449 --- /dev/null +++ b/updater/.gitlab/workflows/build.yml @@ -0,0 +1,38 @@ +name: Build/release + +on: push + +jobs: + release: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [macos-latest, ubuntu-latest, windows-latest] + + steps: + - name: Check out Git repository + uses: actions/checkout@v1 + + - name: Install Node.js, NPM and Yarn + uses: actions/setup-node@v1 + with: + node-version: 14 + + - name: Installing dependencies + run: yarn + + - name: Tsc + run: npx tsc + + - name: Build/release Electron app + uses: ./.github/actions/release + with: + skip_build: false + # GitHub token, automatically provided to the action + # (No need to define this secret in the repo settings) + github_token: ${{ secrets.DEPLOY_TOKEN }} + + # If the commit is tagged with a version (e.g. "v1.0.0"), + # release the app after building + release: ${{ startsWith(github.ref, 'refs/tags/v') }} \ No newline at end of file diff --git a/updater/package-lock.json b/updater/package-lock.json index 4b56972..dcab6b0 100644 --- a/updater/package-lock.json +++ b/updater/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "MIT", "dependencies": { + "@octokit/core": "^4.0.5", "decompress-zip": "^0.3.3", "electron-dl": "^3.3.1", "electron-squirrel-startup": "^1.0.0" @@ -623,6 +624,102 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/@octokit/auth-token": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-3.0.1.tgz", + "integrity": "sha512-/USkK4cioY209wXRpund6HZzHo9GmjakpV9ycOkpMcMxMk7QVcVFVyCMtzvXYiHsB2crgDgrtNYSELYFBXhhaA==", + "dependencies": { + "@octokit/types": "^7.0.0" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/@octokit/core": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/@octokit/core/-/core-4.0.5.tgz", + "integrity": "sha512-4R3HeHTYVHCfzSAi0C6pbGXV8UDI5Rk+k3G7kLVNckswN9mvpOzW9oENfjfH3nEmzg8y3AmKmzs8Sg6pLCeOCA==", + "dependencies": { + "@octokit/auth-token": "^3.0.0", + "@octokit/graphql": "^5.0.0", + "@octokit/request": "^6.0.0", + "@octokit/request-error": "^3.0.0", + "@octokit/types": "^7.0.0", + "before-after-hook": "^2.2.0", + "universal-user-agent": "^6.0.0" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/@octokit/endpoint": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-7.0.2.tgz", + "integrity": "sha512-8/AUACfE9vpRpehE6ZLfEtzkibe5nfsSwFZVMsG8qabqRt1M81qZYUFRZa1B8w8lP6cdfDJfRq9HWS+MbmR7tw==", + "dependencies": { + "@octokit/types": "^7.0.0", + "is-plain-object": "^5.0.0", + "universal-user-agent": "^6.0.0" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/@octokit/graphql": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-5.0.1.tgz", + "integrity": "sha512-sxmnewSwAixkP1TrLdE6yRG53eEhHhDTYUykUwdV9x8f91WcbhunIHk9x1PZLALdBZKRPUO2HRcm4kezZ79HoA==", + "dependencies": { + "@octokit/request": "^6.0.0", + "@octokit/types": "^7.0.0", + "universal-user-agent": "^6.0.0" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/@octokit/openapi-types": { + "version": "13.12.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-13.12.0.tgz", + "integrity": "sha512-1QYzZrwnn3rTQE7ZoSxXrO8lhu0aIbac1c+qIPOPEaVXBWSaUyLV1x9yt4uDQOwmu6u5ywVS8OJgs+ErDLf6vQ==" + }, + "node_modules/@octokit/request": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-6.2.1.tgz", + "integrity": "sha512-gYKRCia3cpajRzDSU+3pt1q2OcuC6PK8PmFIyxZDWCzRXRSIBH8jXjFJ8ZceoygBIm0KsEUg4x1+XcYBz7dHPQ==", + "dependencies": { + "@octokit/endpoint": "^7.0.0", + "@octokit/request-error": "^3.0.0", + "@octokit/types": "^7.0.0", + "is-plain-object": "^5.0.0", + "node-fetch": "^2.6.7", + "universal-user-agent": "^6.0.0" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/@octokit/request-error": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-3.0.1.tgz", + "integrity": "sha512-ym4Bp0HTP7F3VFssV88WD1ZyCIRoE8H35pXSKwLeMizcdZAYc/t6N9X9Yr9n6t3aG9IH75XDnZ6UeZph0vHMWQ==", + "dependencies": { + "@octokit/types": "^7.0.0", + "deprecation": "^2.0.0", + "once": "^1.4.0" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/@octokit/types": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-7.5.0.tgz", + "integrity": "sha512-aHm+olfIZjQpzoODpl+RCZzchKOrdSLJs+yfI7pMMcmB19Li6vidgx0DwUDO/Ic4Q3fq/lOjJORVCcLZefcrJw==", + "dependencies": { + "@octokit/openapi-types": "^13.11.0" + } + }, "node_modules/@sindresorhus/is": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz", @@ -912,6 +1009,11 @@ } ] }, + "node_modules/before-after-hook": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.2.tgz", + "integrity": "sha512-3pZEU3NT5BFUo/AD5ERPWOgQOCZITni6iavr5AUw5AUwQjMlI0kzu5btnyD39AF0gUEsDPwJT+oY1ORBJijPjQ==" + }, "node_modules/binary": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/binary/-/binary-0.3.0.tgz", @@ -1624,6 +1726,11 @@ "node": ">= 0.6" } }, + "node_modules/deprecation": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz", + "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==" + }, "node_modules/detect-libc": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.1.tgz", @@ -2734,7 +2841,6 @@ "version": "0.1.13", "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.13.tgz", "integrity": "sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==", - "dev": true, "optional": true, "dependencies": { "iconv-lite": "^0.6.2" @@ -2744,7 +2850,6 @@ "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", - "dev": true, "optional": true, "dependencies": { "safer-buffer": ">= 2.1.2 < 3.0.0" @@ -3828,6 +3933,14 @@ "node": ">=0.10.0" } }, + "node_modules/is-plain-object": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz", + "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/is-stream": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", @@ -4385,7 +4498,6 @@ "version": "2.6.7", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", - "dev": true, "dependencies": { "whatwg-url": "^5.0.0" }, @@ -4548,7 +4660,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", - "dev": true, "dependencies": { "wrappy": "1" } @@ -5355,7 +5466,7 @@ "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", - "dev": true + "devOptional": true }, "node_modules/semver": { "version": "7.3.7", @@ -5844,8 +5955,7 @@ "node_modules/tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", - "dev": true + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, "node_modules/traverse": { "version": "0.3.9", @@ -5919,6 +6029,11 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/universal-user-agent": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-6.0.0.tgz", + "integrity": "sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w==" + }, "node_modules/universalify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", @@ -5993,14 +6108,12 @@ "node_modules/webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", - "dev": true + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" }, "node_modules/whatwg-url": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", - "dev": true, "dependencies": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" @@ -6067,8 +6180,7 @@ "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", - "dev": true + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" }, "node_modules/xmlbuilder": { "version": "15.1.1", @@ -6746,6 +6858,84 @@ "rimraf": "^3.0.2" } }, + "@octokit/auth-token": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-3.0.1.tgz", + "integrity": "sha512-/USkK4cioY209wXRpund6HZzHo9GmjakpV9ycOkpMcMxMk7QVcVFVyCMtzvXYiHsB2crgDgrtNYSELYFBXhhaA==", + "requires": { + "@octokit/types": "^7.0.0" + } + }, + "@octokit/core": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/@octokit/core/-/core-4.0.5.tgz", + "integrity": "sha512-4R3HeHTYVHCfzSAi0C6pbGXV8UDI5Rk+k3G7kLVNckswN9mvpOzW9oENfjfH3nEmzg8y3AmKmzs8Sg6pLCeOCA==", + "requires": { + "@octokit/auth-token": "^3.0.0", + "@octokit/graphql": "^5.0.0", + "@octokit/request": "^6.0.0", + "@octokit/request-error": "^3.0.0", + "@octokit/types": "^7.0.0", + "before-after-hook": "^2.2.0", + "universal-user-agent": "^6.0.0" + } + }, + "@octokit/endpoint": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-7.0.2.tgz", + "integrity": "sha512-8/AUACfE9vpRpehE6ZLfEtzkibe5nfsSwFZVMsG8qabqRt1M81qZYUFRZa1B8w8lP6cdfDJfRq9HWS+MbmR7tw==", + "requires": { + "@octokit/types": "^7.0.0", + "is-plain-object": "^5.0.0", + "universal-user-agent": "^6.0.0" + } + }, + "@octokit/graphql": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-5.0.1.tgz", + "integrity": "sha512-sxmnewSwAixkP1TrLdE6yRG53eEhHhDTYUykUwdV9x8f91WcbhunIHk9x1PZLALdBZKRPUO2HRcm4kezZ79HoA==", + "requires": { + "@octokit/request": "^6.0.0", + "@octokit/types": "^7.0.0", + "universal-user-agent": "^6.0.0" + } + }, + "@octokit/openapi-types": { + "version": "13.12.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-13.12.0.tgz", + "integrity": "sha512-1QYzZrwnn3rTQE7ZoSxXrO8lhu0aIbac1c+qIPOPEaVXBWSaUyLV1x9yt4uDQOwmu6u5ywVS8OJgs+ErDLf6vQ==" + }, + "@octokit/request": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-6.2.1.tgz", + "integrity": "sha512-gYKRCia3cpajRzDSU+3pt1q2OcuC6PK8PmFIyxZDWCzRXRSIBH8jXjFJ8ZceoygBIm0KsEUg4x1+XcYBz7dHPQ==", + "requires": { + "@octokit/endpoint": "^7.0.0", + "@octokit/request-error": "^3.0.0", + "@octokit/types": "^7.0.0", + "is-plain-object": "^5.0.0", + "node-fetch": "^2.6.7", + "universal-user-agent": "^6.0.0" + } + }, + "@octokit/request-error": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-3.0.1.tgz", + "integrity": "sha512-ym4Bp0HTP7F3VFssV88WD1ZyCIRoE8H35pXSKwLeMizcdZAYc/t6N9X9Yr9n6t3aG9IH75XDnZ6UeZph0vHMWQ==", + "requires": { + "@octokit/types": "^7.0.0", + "deprecation": "^2.0.0", + "once": "^1.4.0" + } + }, + "@octokit/types": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-7.5.0.tgz", + "integrity": "sha512-aHm+olfIZjQpzoODpl+RCZzchKOrdSLJs+yfI7pMMcmB19Li6vidgx0DwUDO/Ic4Q3fq/lOjJORVCcLZefcrJw==", + "requires": { + "@octokit/openapi-types": "^13.11.0" + } + }, "@sindresorhus/is": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz", @@ -6967,6 +7157,11 @@ "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", "dev": true }, + "before-after-hook": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.2.tgz", + "integrity": "sha512-3pZEU3NT5BFUo/AD5ERPWOgQOCZITni6iavr5AUw5AUwQjMlI0kzu5btnyD39AF0gUEsDPwJT+oY1ORBJijPjQ==" + }, "binary": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/binary/-/binary-0.3.0.tgz", @@ -7495,6 +7690,11 @@ "integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==", "dev": true }, + "deprecation": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz", + "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==" + }, "detect-libc": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.1.tgz", @@ -8377,7 +8577,6 @@ "version": "0.1.13", "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.13.tgz", "integrity": "sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==", - "dev": true, "optional": true, "requires": { "iconv-lite": "^0.6.2" @@ -8387,7 +8586,6 @@ "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", - "dev": true, "optional": true, "requires": { "safer-buffer": ">= 2.1.2 < 3.0.0" @@ -9239,6 +9437,11 @@ "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz", "integrity": "sha512-yvkRyxmFKEOQ4pNXCmJG5AEQNlXJS5LaONXo5/cLdTZdWvsZ1ioJEonLGAosKlMWE8lwUy/bJzMjcw8az73+Fg==" }, + "is-plain-object": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz", + "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==" + }, "is-stream": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", @@ -9672,7 +9875,6 @@ "version": "2.6.7", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", - "dev": true, "requires": { "whatwg-url": "^5.0.0" } @@ -9787,7 +9989,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", - "dev": true, "requires": { "wrappy": "1" } @@ -10348,7 +10549,7 @@ "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", - "dev": true + "devOptional": true }, "semver": { "version": "7.3.7", @@ -10737,8 +10938,7 @@ "tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", - "dev": true + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, "traverse": { "version": "0.3.9", @@ -10791,6 +10991,11 @@ "imurmurhash": "^0.1.4" } }, + "universal-user-agent": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-6.0.0.tgz", + "integrity": "sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w==" + }, "universalify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", @@ -10853,14 +11058,12 @@ "webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", - "dev": true + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" }, "whatwg-url": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", - "dev": true, "requires": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" @@ -10912,8 +11115,7 @@ "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", - "dev": true + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" }, "xmlbuilder": { "version": "15.1.1", diff --git a/updater/package.json b/updater/package.json index c82f4fe..3fe1459 100644 --- a/updater/package.json +++ b/updater/package.json @@ -45,6 +45,7 @@ } }, "dependencies": { + "@octokit/core": "^4.0.5", "decompress-zip": "^0.3.3", "electron-dl": "^3.3.1", "electron-squirrel-startup": "^1.0.0" diff --git a/updater/src/index.html b/updater/src/index.html index e36b5d8..f529525 100644 --- a/updater/src/index.html +++ b/updater/src/index.html @@ -19,5 +19,7 @@

Hello World!

Welcome to your Electron application.

+ + diff --git a/updater/src/index.js b/updater/src/index.js index 2d1f6f8..a6d24b4 100644 --- a/updater/src/index.js +++ b/updater/src/index.js @@ -1,6 +1,6 @@ -const { app, BrowserWindow, Menu, ipcMain, nativeTheme } = require('electron'); +const { app, BrowserWindow, Menu, dialog, ipcMain, nativeTheme } = require('electron'); const path = require('path'); -Menu.setApplicationMenu(false); +//Menu.setApplicationMenu(false); // Handle creating/removing shortcuts on Windows when installing/uninstalling. // eslint-disable-next-line global-require @@ -14,9 +14,11 @@ const createWindow = () => { width: 800, height: 600, webPreferences: { + preload: path.join(__dirname, 'preload.js'), nodeIntegration: true, }, }); + mainWindow.loadFile(path.join(__dirname, 'index.html')); }; @@ -46,7 +48,12 @@ app.on('activate', () => { - +ipcMain.on('select-dirs', async(event, arg) => { + const result = await dialog.showOpenDialog(mainWindow, { + properties: ['openDirectory'] + }) + console.log('directories selected', result.filePaths) +}) diff --git a/updater/src/preload.js b/updater/src/preload.js new file mode 100644 index 0000000..731bcdf --- /dev/null +++ b/updater/src/preload.js @@ -0,0 +1,9 @@ +const { ipcRenderer } = require('electron') + +process.once('loaded', () => { + window.addEventListener('message', evt => { + if (evt.data.type === 'select-dirs') { + ipcRenderer.send('select-dirs') + } + }) +}) \ No newline at end of file diff --git a/updater/src/renderer.js b/updater/src/renderer.js index 9c22b24..fb16117 100644 --- a/updater/src/renderer.js +++ b/updater/src/renderer.js @@ -6,6 +6,7 @@ const stopUnzip = document.querySelector('stopUnzip'); const selectVersionBtn = document.querySelector('selectVersion'); const selectPathBtn = document.querySelector('selectPathBtn'); +var directoryPath = "C:"; const { remote } = require('electron'); const { Menu } = remote; @@ -59,8 +60,8 @@ async function downloadVersion(e) { ipcRenderer.send("download", { - url: "URL is here", - properties: { directory: "Directory is here" } + url: "https://dms.pabr.de/s/SpBiQYADTNak7R5/download", + properties: { directory: directoryPath } }); const { ipcRenderer } = require("electron"); @@ -73,4 +74,19 @@ ipcRenderer.on("download progress", (event, progress) => { console.log(progress); // Progress in fraction, between 0 and 1 const progressInPercentages = progress * 100; // With decimal point and a bunch of numbers const cleanProgressInPercentages = Math.floor(progress * 100); // Without decimal point -}); \ No newline at end of file +}); + + +// Select Folder +document.getElementById('dirs').addEventListener('click', (evt) => { + evt.preventDefault() + window.postMessage({ + type: 'select-dirs', + }) +}) + + + + + +// Get releases from Gitlab \ No newline at end of file diff --git a/updater/yarn.lock b/updater/yarn.lock index c7cc3fc..7c3d0b1 100644 --- a/updater/yarn.lock +++ b/updater/yarn.lock @@ -377,6 +377,77 @@ "mkdirp" "^1.0.4" "rimraf" "^3.0.2" +"@octokit/auth-token@^3.0.0": + "integrity" "sha512-/USkK4cioY209wXRpund6HZzHo9GmjakpV9ycOkpMcMxMk7QVcVFVyCMtzvXYiHsB2crgDgrtNYSELYFBXhhaA==" + "resolved" "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-3.0.1.tgz" + "version" "3.0.1" + dependencies: + "@octokit/types" "^7.0.0" + +"@octokit/core@^4.0.5": + "integrity" "sha512-4R3HeHTYVHCfzSAi0C6pbGXV8UDI5Rk+k3G7kLVNckswN9mvpOzW9oENfjfH3nEmzg8y3AmKmzs8Sg6pLCeOCA==" + "resolved" "https://registry.npmjs.org/@octokit/core/-/core-4.0.5.tgz" + "version" "4.0.5" + dependencies: + "@octokit/auth-token" "^3.0.0" + "@octokit/graphql" "^5.0.0" + "@octokit/request" "^6.0.0" + "@octokit/request-error" "^3.0.0" + "@octokit/types" "^7.0.0" + "before-after-hook" "^2.2.0" + "universal-user-agent" "^6.0.0" + +"@octokit/endpoint@^7.0.0": + "integrity" "sha512-8/AUACfE9vpRpehE6ZLfEtzkibe5nfsSwFZVMsG8qabqRt1M81qZYUFRZa1B8w8lP6cdfDJfRq9HWS+MbmR7tw==" + "resolved" "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-7.0.2.tgz" + "version" "7.0.2" + dependencies: + "@octokit/types" "^7.0.0" + "is-plain-object" "^5.0.0" + "universal-user-agent" "^6.0.0" + +"@octokit/graphql@^5.0.0": + "integrity" "sha512-sxmnewSwAixkP1TrLdE6yRG53eEhHhDTYUykUwdV9x8f91WcbhunIHk9x1PZLALdBZKRPUO2HRcm4kezZ79HoA==" + "resolved" "https://registry.npmjs.org/@octokit/graphql/-/graphql-5.0.1.tgz" + "version" "5.0.1" + dependencies: + "@octokit/request" "^6.0.0" + "@octokit/types" "^7.0.0" + "universal-user-agent" "^6.0.0" + +"@octokit/openapi-types@^13.11.0": + "integrity" "sha512-1QYzZrwnn3rTQE7ZoSxXrO8lhu0aIbac1c+qIPOPEaVXBWSaUyLV1x9yt4uDQOwmu6u5ywVS8OJgs+ErDLf6vQ==" + "resolved" "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-13.12.0.tgz" + "version" "13.12.0" + +"@octokit/request-error@^3.0.0": + "integrity" "sha512-ym4Bp0HTP7F3VFssV88WD1ZyCIRoE8H35pXSKwLeMizcdZAYc/t6N9X9Yr9n6t3aG9IH75XDnZ6UeZph0vHMWQ==" + "resolved" "https://registry.npmjs.org/@octokit/request-error/-/request-error-3.0.1.tgz" + "version" "3.0.1" + dependencies: + "@octokit/types" "^7.0.0" + "deprecation" "^2.0.0" + "once" "^1.4.0" + +"@octokit/request@^6.0.0": + "integrity" "sha512-gYKRCia3cpajRzDSU+3pt1q2OcuC6PK8PmFIyxZDWCzRXRSIBH8jXjFJ8ZceoygBIm0KsEUg4x1+XcYBz7dHPQ==" + "resolved" "https://registry.npmjs.org/@octokit/request/-/request-6.2.1.tgz" + "version" "6.2.1" + dependencies: + "@octokit/endpoint" "^7.0.0" + "@octokit/request-error" "^3.0.0" + "@octokit/types" "^7.0.0" + "is-plain-object" "^5.0.0" + "node-fetch" "^2.6.7" + "universal-user-agent" "^6.0.0" + +"@octokit/types@^7.0.0": + "integrity" "sha512-aHm+olfIZjQpzoODpl+RCZzchKOrdSLJs+yfI7pMMcmB19Li6vidgx0DwUDO/Ic4Q3fq/lOjJORVCcLZefcrJw==" + "resolved" "https://registry.npmjs.org/@octokit/types/-/types-7.5.0.tgz" + "version" "7.5.0" + dependencies: + "@octokit/openapi-types" "^13.11.0" + "@sindresorhus/is@^0.14.0": "integrity" "sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ==" "resolved" "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz" @@ -575,6 +646,11 @@ "resolved" "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz" "version" "1.5.1" +"before-after-hook@^2.2.0": + "integrity" "sha512-3pZEU3NT5BFUo/AD5ERPWOgQOCZITni6iavr5AUw5AUwQjMlI0kzu5btnyD39AF0gUEsDPwJT+oY1ORBJijPjQ==" + "resolved" "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.2.tgz" + "version" "2.2.2" + "binary@^0.3.0": "integrity" "sha512-D4H1y5KYwpJgK8wk1Cue5LLPgmwHKYSChkbspQg5JtVuR5ulGckxfR62H3AE9UDkdMC8yyXlqYihuz3Aqg2XZg==" "resolved" "https://registry.npmjs.org/binary/-/binary-0.3.0.tgz" @@ -1015,6 +1091,11 @@ "resolved" "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz" "version" "1.1.2" +"deprecation@^2.0.0": + "integrity" "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==" + "resolved" "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz" + "version" "2.3.1" + "detect-libc@^2.0.1": "integrity" "sha512-463v3ZeIrcWtdgIg6vI6XUncguvr2TnGl4SzDXinkt9mSLpBJKXT3mW6xT3VQdDN11+WVs29pgvivTc4Lp8v+w==" "resolved" "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.1.tgz" @@ -1836,6 +1917,11 @@ "resolved" "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz" "version" "1.1.0" +"is-plain-object@^5.0.0": + "integrity" "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==" + "resolved" "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz" + "version" "5.0.0" + "is-stream@^1.1.0": "integrity" "sha512-uQPm8kcs47jx38atAcWTVxyltQYoPT68y9aWYdV6yWXSyW8mzSat0TL6CiWdZeCdF3KrAvpVtnHbTv4RN+rqdQ==" "resolved" "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz" @@ -3173,6 +3259,11 @@ dependencies: "imurmurhash" "^0.1.4" +"universal-user-agent@^6.0.0": + "integrity" "sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w==" + "resolved" "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-6.0.0.tgz" + "version" "6.0.0" + "universalify@^0.1.0": "integrity" "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==" "resolved" "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz"