aboutsummaryrefslogtreecommitdiffstats
path: root/qt-qml/src/commands/download-qmlls.ts
blob: 1f0d6e04de4a0c22a00929a82349942338b217fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only

import * as vscode from 'vscode';

import { telemetry } from 'qt-lib';
import { EXTENSION_ID } from '@/constants';
import { DecisionCode, fetchAssetAndDecide, Qmlls } from '@/qmlls';

export function registerDownloadQmllsCommand() {
  return vscode.commands.registerCommand(
    `${EXTENSION_ID}.downloadQmlls`,
    async () => {
      telemetry.sendAction('downloadQmlls');
      const decision = await fetchAssetAndDecide({ doNotAsk: true });

      switch (decision.code) {
        case DecisionCode.NeedToUpdate:
        case DecisionCode.AlreadyUpToDate:
          if (decision.asset) {
            await Qmlls.install(decision.asset, { restart: true });
          }
          break;

        default:
          break;
      }
    }
  );
}