tutanota/make.js
ivk 439260efbb [desktop] Fix opening files & directories on Linux
Electron uses xdg-open to open files. On GNOME it will try to use gio
open which reads user configs from a few files. To detect those config
files it uses `XDG_CURRENT_DESKTOP` env variable.

Electron overwrites `XDG_CURRENT_DESKTOP` to enable some compatibility
functions in Chromium. This breaks gio because it can't locate the
config files for default apps. It can be reproduced on Ubuntu with
GNOME. There is a fix in Electron to restore the env for opening files,
but it doesn't work.

We worked around that by invoking xdg-open directly with correct env.

Additionally, we fixed opening the directories having the same issue and
getting stuck by using showItemInFolder instead. This also has an
additional benefit of highlighting the file in the file manager.

Close #9696

Co-authored-by: hrb-hub <hrb-hub@users.noreply.github.com>
Co-authored-by: wrd <wrd@tutao.de>
Co-authored-by: paw <paw-hub@users.noreply.github.com>
2025-09-26 12:18:38 +02:00

64 lines
2.5 KiB
JavaScript

import { Argument, Option, program } from "commander"
import { runDevBuild } from "./buildSrc/DevBuild.js"
import { spawn } from "node:child_process"
import { chalk } from "zx"
await program
.usage("[options] [test|prod|local|host <url>]")
.addArgument(new Argument("stage").choices(["test", "prod", "local", "localSecure", "host"]).default("local").argOptional())
.addArgument(new Argument("host").argOptional())
.addOption(new Option("-a, --app <type>", "app to build").choices(["mail", "calendar"]).default("mail"))
.option("-c, --clean", "Clean build directory")
.option("-d, --start-desktop", "Assemble & start desktop client")
.option("--desktop-build-only", "Assemble desktop client without starting")
.option("-v, --verbose", "activate verbose logging in desktop client")
.option("-s, --serve", "Start a local server to serve the website")
.option("--network-debugging", "activate network debugging, sending attributeNames and attributeIds in the json request/response payloads", false)
.option("-D, --dev-tools", "Start the desktop client with DevTools open")
.action(async (stage, host, options) => {
if ((stage === "host" && host == null) || (stage !== "host" && host != null)) {
program.outputHelp()
process.exit(1)
}
if (stage === "localSecure") {
stage = "host"
host = "https://app.local.tuta.com:9000"
}
const { clean, watch, serve, startDesktop, desktopBuildOnly, app, networkDebugging, devTools } = options
if (serve) {
console.error("--serve is currently disabled, point any server to ./build directory instead or build desktop")
}
try {
await runDevBuild({
stage: stage ?? "local",
host,
clean,
watch,
serve,
desktop: startDesktop || desktopBuildOnly,
networkDebugging,
app,
})
if (startDesktop) {
const buildDir = app === "calendar" ? "build-calendar-app" : "build"
const env = Object.assign({}, process.env, { ELECTRON_ENABLE_SECURITY_WARNINGS: "TRUE", ELECTRON_START_WITH_DEV_TOOLS: devTools })
// we don't want to quit here because we want to keep piping output to our stdout.
spawn("node_modules/.bin/electron", ["--inspect=5858", `./${buildDir}/`], {
stdio: "inherit",
env: options.verbose ? Object.assign({}, env, { ELECTRON_ENABLE_LOGGING: 1 }) : env,
})
} else if (!watch) {
// Don't wait for spawned child processes to exit (because they never will)
process.exit(0)
}
} catch (e) {
console.error(chalk.red.underline("Build failed:"), e)
process.exit(1)
}
})
.parseAsync(process.argv)