1/* 2* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3* Licensed under the Apache License, Version 2.0 (the "License"); 4* you may not use this file except in compliance with the License. 5* You may obtain a copy of the License at 6* 7* http://www.apache.org/licenses/LICENSE-2.0 8* 9* Unless required by applicable law or agreed to in writing, software 10* distributed under the License is distributed on an "AS IS" BASIS, 11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12* See the License for the specific language governing permissions and 13* limitations under the License. 14*/ 15import * as vscode from 'vscode'; 16import { H2hdfMod } from "../model/h2hdfmod"; 17import { IModel } from "../model/imodel"; 18import { IView } from "./iview"; 19import { 20 EVENT_ERROR, 21 EVENT_INFORMATION, 22 EVENT_PROGRESS, 23 EVENT_WARNING 24} from '../common/eventtype'; 25import { IController } from '../controller/icontroller'; 26import { doAsyncQuickPick, toastMsg } from '../common/widget'; 27import { SELECT_VERSION } from '../common/constants'; 28 29export class H2hdfView extends IView { 30 name: string; 31 model: IModel; 32 controller: IController | undefined; 33 progress: vscode.Progress<{ message?: string; increment?: number; }> | undefined = undefined; 34 constructor() { 35 super(); 36 this.name = 'h2hdfview'; 37 this.model = H2hdfMod.getInstance(); 38 } 39 40 init(controller: IController): void { 41 this.controller = controller; 42 43 this.model.onEvent(EVENT_PROGRESS, (percent, info) => { 44 if (this.progress) { 45 this.progress.report({ increment: percent, message: info }) 46 } 47 }) 48 this.model.onEvent(EVENT_ERROR, (errno, errmsg) => { 49 vscode.window.showErrorMessage(errmsg); 50 }) 51 this.model.onEvent(EVENT_WARNING, (errno, errmsg) => { 52 vscode.window.showWarningMessage(errmsg); 53 }) 54 } 55 56 doAsyncCB = async (version: string) => { 57 let versionTag = '4.1'; 58 if (version === 'OpenHarmony 4.1 release') { 59 versionTag = '4.1' 60 } 61 // generateHdf(this.uri.fsPath, versionTag); 62 vscode.window.withProgress({ 63 location: vscode.ProgressLocation.Notification, 64 title: 'Generating HDF...', 65 cancellable: false 66 }, async (progress) => { 67 this.progress = progress; 68 if (this.model) { 69 let hdfmode = this.model as H2hdfMod; 70 hdfmode.setVersionTag(versionTag); 71 } 72 73 if (this.controller) { 74 this.controller.start(); 75 } else { 76 let errmsg = this.name + " showProgress error: no controller"; 77 toastMsg(EVENT_ERROR, errmsg); 78 } 79 }) 80 } 81 82 showProgress(): void { 83 try { 84 doAsyncQuickPick( 85 ['OpenHarmony 4.1 release'], 86 { placeHolder: SELECT_VERSION }, 87 this.doAsyncCB 88 ) 89 } catch (error) { 90 let errmsg = this.name + " showProgress error: " + JSON.stringify(error); 91 toastMsg(EVENT_ERROR, errmsg); 92 } 93 } 94 95 showMsg(event: string, msg: string): void { 96 toastMsg(event, msg); 97 } 98} 99 100