Unverified Commit b7121adb authored by Aleksana's avatar Aleksana Committed by GitHub
Browse files

qq: add versionConfigScript to disable auto update (#467729)

parents 3dd2cb87 82fae800
Loading
Loading
Loading
Loading
+95 −37
Original line number Diff line number Diff line
@@ -24,9 +24,11 @@
  vips,
  at-spi2-core,
  autoPatchelfHook,
  writeShellScript,
  makeShellWrapper,
  wrapGAppsHook3,
  commandLineArgs ? "",
  disableAutoUpdate ? true,
}:

let
@@ -121,7 +123,59 @@ else
      libkrb5
    ];

    installPhase = ''
    installPhase =
      let
        versionConfigScript = writeShellScript "qq-version-config.sh" ''
          set -e

          if [[ -z "$INTERNAL_VERSION" ]]; then
            echo "INTERNAL_VERSION is not set, skipping version config management"
            exit 0
          fi

          CONFIG_PATH="$HOME/.config/QQ/versions/config.json"
          CONFIG_DIR="$(dirname "$CONFIG_PATH")"

          if [[ ! -f "$CONFIG_PATH" ]]; then
            if [[ ! -d "$CONFIG_DIR" ]]; then
              echo "Creating QQ version config directory at $CONFIG_DIR"
              mkdir -p "$CONFIG_DIR"
            fi
          else
            baseVersion=$(sed -n 's/.*"baseVersion"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$CONFIG_PATH")
            currentVersion=$(sed -n 's/.*"curVersion"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$CONFIG_PATH")

            # Here we assert that the buildId is the same as baseVersion's buildId and skip checking it separately
            if [[ "$baseVersion" == "$INTERNAL_VERSION" && "$currentVersion" == "$INTERNAL_VERSION" ]]; then
              echo "Version config file already up to date"

              if [[ -w "$CONFIG_PATH" ]]; then
                echo "Making existing version config file read-only"
                chmod u-w "$CONFIG_PATH"
              fi

              exit 0
            fi

            if [[ ! -w "$CONFIG_PATH" ]]; then
              echo "Making existing version config file writable temporarily"
              chmod u+w "$CONFIG_PATH"
            fi
          fi

          cat > "$CONFIG_PATH" << EOF
          {
            "_comment": "This file is managed by the qq-version-config.sh to disable auto updates, do not edit it manually. Set the `disableAutoUpdate` option to false to disable this behavior.",
            "baseVersion": "$INTERNAL_VERSION",
            "curVersion": "$INTERNAL_VERSION",
            "buildId": "''${INTERNAL_VERSION##*-}"
          }
          EOF

          chmod u-w "$CONFIG_PATH"
        '';
      in
      ''
        runHook preInstall

        mkdir -p $out/bin
@@ -141,7 +195,11 @@ else
          }" \
          --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true --wayland-text-input-version=3}}" \
          --add-flags ${lib.escapeShellArg commandLineArgs} \
        "''${gappsWrapperArgs[@]}"
          "''${gappsWrapperArgs[@]}" ${lib.optionalString disableAutoUpdate ''
            \
            --set INTERNAL_VERSION "$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' $out/opt/QQ/resources/app/package.json)" \
            --run '${versionConfigScript} || true'
          ''}

        # Remove bundled libraries
        rm -r $out/opt/QQ/resources/app/sharp-lib