Browse Source

Merge 61a018aa50 into 930cb9ab96

pull/17976/merge
Isaiah Inuwa 7 hours ago committed by GitHub
parent
commit
eb63dc960d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 123
      apps/desktop/cross-build.ps1
  2. 111
      apps/desktop/custom-appx-manifest.xml
  3. 27
      apps/desktop/desktop_native/build.js
  4. 14
      apps/desktop/electron-builder.beta.json
  5. 14
      apps/desktop/electron-builder.json
  6. 2
      apps/desktop/package.json

123
apps/desktop/cross-build.ps1

@ -0,0 +1,123 @@ @@ -0,0 +1,123 @@
#!/usr/bin/env pwsh
param(
[Parameter(Mandatory=$true)]
[System.Runtime.InteropServices.Architecture]$Architecture,
$CertificatePath,
$CertificatePassword,
$ElectronConfigFile="electron-builder.json",
[Switch]$Release=$false
)
$ErrorActionPreference = "Stop"
$PSNativeCommandUseErrorActionPreference = $true
$startTime = Get-Date
$originalLocation = Get-Location
try {
cd $PSScriptRoot
$builderConfig = Get-Content $ElectronConfigFile | ConvertFrom-Json
$packageConfig = Get-Content package.json | ConvertFrom-Json
$manifestTemplate = Get-Content $builderConfig.appx.customManifestPath
$srcDir = Get-Location
$assetsDir = Get-Item $builderConfig.directories.buildResources
$buildDir = Get-Item $builderConfig.directories.app
$outDir = Join-Path (Get-Location) ($builderConfig.directories.output ?? "dist")
if ($Release) {
$buildConfiguration = "--release"
}
$arch = "$Architecture".ToLower()
$ext = "appx"
$version = Get-Date -Format "yyyy.M.d.1HHmm"
$productName = $builderConfig.productName
$artifactName = "${productName}-$($packageConfig.version)-${arch}.$ext"
Write-Host "Building native code"
$rustTarget = switch ($Architecture) {
X64 { "x86_64-pc-windows-msvc" }
ARM64 { "aarch64-pc-windows-msvc" }
default {
Write-Error "Unsupported architecture: $Architecture. Supported architectures are x64 and arm64"
Exit(1)
}
}
npm run build-native -- cross-platform $buildConfiguration "--target=$rustTarget"
Write-Host "Building Javascript code"
if ($target -eq "release") {
npm run build
}
else {
npm run build:dev
}
Write-Host "Cleaning output folder"
Remove-Item -Recurse -Force $outDir -ErrorAction Ignore
Write-Host "Packaging Electron executable"
& npx electron-builder --config $ElectronConfigFile --publish never --dir --win --$arch
cd $outDir
New-Item -Type Directory (Join-Path $outDir "appx")
Write-Host "Building Appx directory structure"
$appxDir = (Join-Path $outDir appx/app)
if ($arch -eq "x64") {
Move-Item (Join-Path $outDir "win-unpacked") $appxDir
}
else {
Move-Item (Join-Path $outDir "win-${arch}-unpacked") $appxDir
}
Write-Host "Copying Assets"
New-Item -Type Directory (Join-Path $outDir appx/assets)
Copy-Item $srcDir/resources/appx/* $outDir/appx/assets/
Write-Host "Building Appx manifest"
$translationMap = @{
'arch' = $arch
'applicationId' = $builderConfig.appx.applicationId
'displayName' = $productName
'executable' = "app\${productName}.exe"
'publisher' = $builderConfig.appx.publisher
'publisherDisplayName' = $builderConfig.appx.publisherDisplayName
'version' = $version
}
$manifest = $manifestTemplate
$translationMap.Keys | ForEach-Object {
$manifest = $manifest.Replace("`${$_}", $translationMap[$_])
}
$manifest | Out-File appx/AppxManifest.xml
$unsignedArtifactpath = [System.IO.Path]::GetFileNameWithoutExtension($artifactName) + "-unsigned.$ext"
Write-Host "Creating unsigned Appx"
makemsix pack -d appx -p $unsignedArtifactpath
$outfile = Join-Path $outDir $unsignedArtifactPath
if ($null -eq $CertificatePath || $null -eq $CertificatePassword) {
Write-Warning "No Certificate specified. Not signing Appx."
}
else {
$cert = (Get-Item $CertificatePath).FullName
$pw = $CertificatePassword
$unsigned = $outfile
$outfile = (Join-Path $outDir $artifactName)
Write-Host "Signing $artifactName with $cert"
osslsigncode sign `
-pkcs12 "$cert" `
-pass "$pw" `
-in $unsigned `
-out $outfile
Remove-Item $unsigned
}
$endTime = Get-Date
$elapsed = $endTime - $startTime
Write-Host "Successfully packaged $(Get-Item $outfile)"
Write-Host ("Finished at $($endTime.ToString('HH:mm:ss')) in $($elapsed.ToString('mm')) minutes and $($elapsed.ToString('ss')).$($elapsed.ToString('fff')) seconds")
}
finally {
Set-Location -Path $originalLocation
}

111
apps/desktop/custom-appx-manifest.xml

@ -0,0 +1,111 @@ @@ -0,0 +1,111 @@
<?xml version="1.0" encoding="utf-8"?>
<!--suppress XmlUnusedNamespaceDeclaration -->
<!-- <Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"> -->
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
xmlns:com="http://schemas.microsoft.com/appx/manifest/com/windows10"
xmlns:uap10="http://schemas.microsoft.com/appx/manifest/uap/windows10/10"
IgnorableNamespaces="uap rescap com uap10 build"
xmlns:build="http://schemas.microsoft.com/developer/appx/2015/build">
<!-- use single quotes to avoid double quotes escaping in the publisher value -->
<Identity Name="${applicationId}"
ProcessorArchitecture="${arch}"
Publisher='${publisher}'
Version="${version}" />
<Properties>
<DisplayName>${displayName}</DisplayName>
<PublisherDisplayName>${publisherDisplayName}</PublisherDisplayName>
<Description>A secure and free password manager for all of your devices.</Description>
<Logo>assets\StoreLogo.png</Logo>
</Properties>
<Resources>
<Resource Language="en-US" />
<Resource Language="af" />
<Resource Language="ar" />
<Resource Language="az-latn" />
<Resource Language="be" />
<Resource Language="bg" />
<Resource Language="bn" />
<Resource Language="bs" />
<Resource Language="ca" />
<Resource Language="cs" />
<Resource Language="cy" />
<Resource Language="da" />
<Resource Language="de" />
<Resource Language="el" />
<Resource Language="en-gb" />
<Resource Language="en-in" />
<Resource Language="es" />
<Resource Language="et" />
<Resource Language="eu" />
<Resource Language="fa" />
<Resource Language="fi" />
<Resource Language="fil" />
<Resource Language="fr" />
<Resource Language="gl" />
<Resource Language="he" />
<Resource Language="hi" />
<Resource Language="hr" />
<Resource Language="hu" />
<Resource Language="id" />
<Resource Language="it" />
<Resource Language="ja" />
<Resource Language="ka" />
<Resource Language="km" />
<Resource Language="kn" />
<Resource Language="ko" />
<Resource Language="lt" />
<Resource Language="lv" />
<Resource Language="ml" />
<Resource Language="mr" />
<Resource Language="nb" />
<Resource Language="ne" />
<Resource Language="nl" />
<Resource Language="nn" />
<Resource Language="or" />
<Resource Language="pl" />
<Resource Language="pt-br" />
<Resource Language="pt-pt" />
<Resource Language="ro" />
<Resource Language="ru" />
<Resource Language="si" />
<Resource Language="sk" />
<Resource Language="sl" />
<Resource Language="sr-cyrl" />
<Resource Language="sv" />
<Resource Language="te" />
<Resource Language="th" />
<Resource Language="tr" />
<Resource Language="uk" />
<Resource Language="vi" />
<Resource Language="zh-cn" />
<Resource Language="zh-tw" />
</Resources>
<Dependencies>
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.26200.7019"
MaxVersionTested="10.0.26200.7171" />
</Dependencies>
<Capabilities>
<rescap:Capability Name="runFullTrust" />
</Capabilities>
<Applications>
<Application Id="bitwardendesktop" Executable="${executable}"
EntryPoint="Windows.FullTrustApplication">
<uap:VisualElements
BackgroundColor="#175DDC"
DisplayName="${displayName}"
Square150x150Logo="assets\Square150x150Logo.png"
Square44x44Logo="assets\Square44x44Logo.png"
Description="A secure and free password manager for all of your devices.">
<uap:LockScreen Notification="badgeAndTileText" BadgeLogo="assets\BadgeLogo.png" />
<uap:DefaultTile Wide310x150Logo="assets\Wide310x150Logo.png" />
<uap:SplashScreen Image="assets\SplashScreen.png" />
</uap:VisualElements>
</Application>
</Applications>
</Package>

27
apps/desktop/desktop_native/build.js

@ -20,28 +20,31 @@ fs.mkdirSync(path.join(__dirname, "dist"), { recursive: true }); @@ -20,28 +20,31 @@ fs.mkdirSync(path.join(__dirname, "dist"), { recursive: true });
const args = process.argv.slice(2); // Get arguments passed to the script
const mode = args.includes("--release") ? "release" : "debug";
const isRelease = mode === "release";
const targetArg = args.find(arg => arg.startsWith("--target="));
const target = targetArg ? targetArg.split("=")[1] : null;
let crossPlatform = process.argv.length > 2 && process.argv[2] === "cross-platform";
function buildNapiModule(target, release = true) {
const targetArg = target ? `--target ${target}` : "";
const targetArg = target ? `--target=${target}` : "";
const releaseArg = release ? "--release" : "";
child_process.execSync(`npm run build -- ${releaseArg} ${targetArg}`, { stdio: 'inherit', cwd: path.join(__dirname, "napi") });
const crossCompileArg = target ? "--cross-compile" : "";
child_process.execSync(`npm run build -- ${crossCompileArg} ${releaseArg} ${targetArg}`, { stdio: 'inherit', cwd: path.join(__dirname, "napi") });
}
function buildProxyBin(target, release = true) {
const targetArg = target ? `--target ${target}` : "";
const releaseArg = release ? "--release" : "";
child_process.execSync(`cargo build --bin desktop_proxy ${releaseArg} ${targetArg}`, {stdio: 'inherit', cwd: path.join(__dirname, "proxy")});
const xwin = target && target.includes('windows') && process.platform !== "win32" ? "xwin" : "";
child_process.execSync(`cargo ${xwin} build --bin desktop_proxy ${releaseArg} ${targetArg}`, {stdio: 'inherit', cwd: path.join(__dirname, "proxy")});
if (target) {
// Copy the resulting binary to the dist folder
const targetFolder = release ? "release" : "debug";
const ext = process.platform === "win32" ? ".exe" : "";
const nodeArch = rustTargetsMap[target].nodeArch;
fs.copyFileSync(path.join(__dirname, "target", target, targetFolder, `desktop_proxy${ext}`), path.join(__dirname, "dist", `desktop_proxy.${process.platform}-${nodeArch}${ext}`));
const { nodeArch, platform } = rustTargetsMap[target];
const ext = platform === "win32" ? ".exe" : "";
fs.copyFileSync(path.join(__dirname, "target", target, targetFolder, `desktop_proxy${ext}`), path.join(__dirname, "dist", `desktop_proxy.${platform}-${nodeArch}${ext}`));
}
}
@ -94,9 +97,9 @@ if (!crossPlatform && !target) { @@ -94,9 +97,9 @@ if (!crossPlatform && !target) {
if (target) {
console.log(`Building for target: ${target} in ${mode} mode`);
installTarget(target);
buildNapiModule(target, mode === "release");
buildProxyBin(target, mode === "release");
buildImporterBinaries(false, mode === "release");
buildNapiModule(target, isRelease);
buildProxyBin(target, isRelease);
buildImporterBinaries(false, isRelease);
buildProcessIsolation();
return;
}
@ -113,8 +116,8 @@ if (process.platform === "linux") { @@ -113,8 +116,8 @@ if (process.platform === "linux") {
platformTargets.forEach(([target, _]) => {
installTarget(target);
buildNapiModule(target, mode === "release");
buildProxyBin(target, mode === "release");
buildImporterBinaries(target, mode === "release");
buildNapiModule(target, isRelease);
buildProxyBin(target, isRelease);
buildImporterBinaries(target, isRelease);
buildProcessIsolation();
});

14
apps/desktop/electron-builder.beta.json

@ -13,12 +13,11 @@ @@ -13,12 +13,11 @@
},
"afterSign": "scripts/after-sign.js",
"afterPack": "scripts/after-pack.js",
"asarUnpack": ["**/*.node"],
"files": [
"**/*",
"!**/node_modules/@bitwarden/desktop-napi/**/*",
"**/node_modules/@bitwarden/desktop-napi/index.js",
"**/node_modules/@bitwarden/desktop-napi/desktop_napi.${platform}-${arch}*.node"
"!node_modules/@bitwarden/desktop-napi/src",
"!node_modules/@bitwarden/desktop-napi/Cargo.toml",
"!node_modules/@bitwarden/desktop-napi/build.rs",
"!node_modules/@bitwarden/desktop-napi/package.json"
],
"electronVersion": "36.8.1",
"generateUpdatesFilesForAllChannels": true,
@ -34,11 +33,11 @@ @@ -34,11 +33,11 @@
},
"extraFiles": [
{
"from": "desktop_native/dist/desktop_proxy.${platform}-${arch}.exe",
"from": "desktop_native/dist/desktop_proxy.win32-${arch}.exe",
"to": "desktop_proxy.exe"
},
{
"from": "desktop_native/dist/bitwarden_chromium_import_helper.${platform}-${arch}.exe",
"from": "desktop_native/dist/bitwarden_chromium_import_helper.win32-${arch}.exe",
"to": "bitwarden_chromium_import_helper.exe"
}
]
@ -58,6 +57,7 @@ @@ -58,6 +57,7 @@
"appx": {
"artifactName": "Bitwarden-Beta-${version}-${arch}.${ext}",
"backgroundColor": "#175DDC",
"customManifestPath": "./custom-appx-manifest.xml",
"applicationId": "BitwardenBeta",
"identityName": "8bitSolutionsLLC.BitwardenBeta",
"publisher": "CN=14D52771-DE3C-4886-B8BF-825BA7690418",

14
apps/desktop/electron-builder.json

@ -13,12 +13,11 @@ @@ -13,12 +13,11 @@
},
"afterSign": "scripts/after-sign.js",
"afterPack": "scripts/after-pack.js",
"asarUnpack": ["**/*.node"],
"files": [
"**/*",
"!**/node_modules/@bitwarden/desktop-napi/**/*",
"**/node_modules/@bitwarden/desktop-napi/index.js",
"**/node_modules/@bitwarden/desktop-napi/desktop_napi.${platform}-${arch}*.node"
"!node_modules/@bitwarden/desktop-napi/src",
"!node_modules/@bitwarden/desktop-napi/Cargo.toml",
"!node_modules/@bitwarden/desktop-napi/build.rs",
"!node_modules/@bitwarden/desktop-napi/package.json"
],
"electronVersion": "37.7.0",
"generateUpdatesFilesForAllChannels": true,
@ -94,11 +93,11 @@ @@ -94,11 +93,11 @@
},
"extraFiles": [
{
"from": "desktop_native/dist/desktop_proxy.${platform}-${arch}.exe",
"from": "desktop_native/dist/desktop_proxy.win32-${arch}.exe",
"to": "desktop_proxy.exe"
},
{
"from": "desktop_native/dist/bitwarden_chromium_import_helper.${platform}-${arch}.exe",
"from": "desktop_native/dist/bitwarden_chromium_import_helper.win32-${arch}.exe",
"to": "bitwarden_chromium_import_helper.exe"
}
]
@ -172,6 +171,7 @@ @@ -172,6 +171,7 @@
"appx": {
"artifactName": "${productName}-${version}-${arch}.${ext}",
"backgroundColor": "#175DDC",
"customManifestPath": "./custom-appx-manifest.xml",
"applicationId": "bitwardendesktop",
"identityName": "8bitSolutionsLLC.bitwardendesktop",
"publisher": "CN=14D52771-DE3C-4886-B8BF-825BA7690418",

2
apps/desktop/package.json

@ -29,7 +29,7 @@ @@ -29,7 +29,7 @@
"build:macos-extension:mas": "./desktop_native/macos_provider/build.sh && node scripts/build-macos-extension.js mas",
"build:macos-extension:masdev": "./desktop_native/macos_provider/build.sh && node scripts/build-macos-extension.js mas-dev",
"build:main": "cross-env NODE_ENV=production webpack --config webpack.config.js --config-name main",
"build:main:dev": "npm run build-native && cross-env NODE_ENV=development webpack --config webpack.config.js --config-name main",
"build:main:dev": "cross-env NODE_ENV=development webpack --config webpack.config.js --config-name main",
"build:main:watch": "npm run build-native && cross-env NODE_ENV=development webpack --config webpack.config.js --config-name main --watch",
"build:renderer": "cross-env NODE_ENV=production webpack --config webpack.config.js --config-name renderer",
"build:renderer:dev": "cross-env NODE_ENV=development webpack --config webpack.config.js --config-name renderer",

Loading…
Cancel
Save