109 lines
4.2 KiB
Plaintext
109 lines
4.2 KiB
Plaintext
import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit';
|
|
import { hilog } from '@kit.PerformanceAnalysisKit';
|
|
import { window, display, AppStorageV2 } from '@kit.ArkUI';
|
|
import { IBestInit } from "@ibestservices/ibest-ui-v2"
|
|
import {ExtractDir,CheckExistDir,HilogSadboxFontDirFile} from "../pages/ExtractDir/ExtractDir"
|
|
import {MainWindowStageInfo,InitGlobalDisplayWindowInfo,mwInfo}from '../pages/DispWinInfo/DispWinInfo'
|
|
const DOMAIN = 0x0000;
|
|
|
|
export default class EntryAbility extends UIAbility {
|
|
private mainWindow: window.Window | undefined;
|
|
|
|
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
|
|
let sbFontsDir=this.context?.filesDir + '/fonts/';
|
|
let sbExampleDir=this.context?.filesDir + '/example/';
|
|
try {
|
|
if(!CheckExistDir(this.context,sbFontsDir)||!CheckExistDir(this.context,sbExampleDir)){
|
|
console.info(`first run app check dir exist`);
|
|
console.info(`extract dir file to sandbox dir`);
|
|
const fontsCopied = ExtractDir(this.context, 'fonts');
|
|
const exampleCopied = ExtractDir(this.context, 'example');
|
|
console.info(`restart app`);
|
|
if(fontsCopied&&exampleCopied){
|
|
let wantInfo: Want = {
|
|
deviceId: '',
|
|
bundleName: 'com.example.opencax',
|
|
abilityName: 'EntryAbility',
|
|
};
|
|
this.context.startAbility(wantInfo).then(() => {
|
|
this.context.terminateSelf();
|
|
})
|
|
}
|
|
}else{
|
|
HilogSadboxFontDirFile(this.context,'fonts');
|
|
HilogSadboxFontDirFile(this.context,'example');
|
|
}
|
|
this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET);
|
|
} catch (err) {
|
|
hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err));
|
|
}
|
|
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate');
|
|
}
|
|
|
|
onDestroy(): void {
|
|
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy');
|
|
}
|
|
|
|
onWindowStageCreate(windowStage: window.WindowStage): void {
|
|
//InitFont->Copy Res/resfile/font to sandbox
|
|
|
|
InitGlobalDisplayWindowInfo(windowStage);
|
|
//Get Main Window
|
|
windowStage.getMainWindow((err, data) => {
|
|
if (err.code) {
|
|
console.error(`Failed to obtain the main window. Code: ${err.code}, message: ${err.message}`);
|
|
return;
|
|
}
|
|
this.mainWindow = data;
|
|
mwInfo.id = this.mainWindow.getWindowProperties().id;
|
|
//moveWindowTo
|
|
this.mainWindow.moveWindowTo(50, 50)
|
|
//resize mainWindow Size
|
|
this.mainWindow.resize(mwInfo.width, mwInfo.height, (err) => {
|
|
if (err.code) {
|
|
console.error(`Failed to resize the window. Code: ${err.code}, message: ${err.message}`);
|
|
return;
|
|
}
|
|
console.info(`Succeeded in resizing the window to ${mwInfo.width}x${mwInfo.height}.`);
|
|
});
|
|
|
|
// windowSizeChangeListener to Change mainWindowWidth&&mainWindowHeight in AppStorage
|
|
this.mainWindow.on('windowSizeChange', (ChangeData) => {
|
|
// if Size Change save to AppStorage
|
|
mwInfo.width = ChangeData.width;
|
|
mwInfo.height = ChangeData.height;
|
|
console.info('Succeeded in enabling the listener for window size changes. Data:' + ChangeData.width,
|
|
ChangeData.height);
|
|
});
|
|
});
|
|
|
|
//Load page
|
|
windowStage.loadContent('pages/Index', (err) => {
|
|
if (err.code) {
|
|
hilog.error(DOMAIN, 'Tag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err));
|
|
return;
|
|
}
|
|
IBestInit(windowStage, this.context);
|
|
hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.');
|
|
});
|
|
}
|
|
|
|
onWindowStageDestroy(): void {
|
|
AppStorageV2.remove<MainWindowStageInfo>(MainWindowStageInfo);
|
|
if (this.mainWindow) {
|
|
this.mainWindow = undefined;
|
|
}
|
|
// Main window is destroyed, release UI related resources
|
|
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
|
|
}
|
|
|
|
onForeground(): void {
|
|
// Ability has brought to foreground
|
|
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground');
|
|
}
|
|
|
|
onBackground(): void {
|
|
// Ability has back to background
|
|
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground');
|
|
}
|
|
} |