删除冗余代码
对字体和示例释放不再输出错误的日志 不再初始化中初始化子窗口,采用实时拉起
This commit is contained in:
parent
cc770e9f40
commit
9e3f93daf9
@ -10,11 +10,6 @@ const DOMAIN = 0x0000;
|
||||
export default class EntryAbility extends UIAbility {
|
||||
|
||||
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
|
||||
try {
|
||||
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');
|
||||
}
|
||||
|
||||
@ -26,46 +21,46 @@ export default class EntryAbility extends UIAbility {
|
||||
if(!InitHub(windowStage.getMainWindowSync(),windowStage,this.context)){
|
||||
console.log("InitHub Failed!")
|
||||
this.context.getApplicationContext().killAllProcesses();
|
||||
}
|
||||
//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;
|
||||
}
|
||||
mdwInfo.win = data;
|
||||
mdwInfo.winId =data.getWindowProperties().id;
|
||||
//moveWindowTo
|
||||
data?.moveWindowTo(50, 50)
|
||||
//resize mainWindow Size
|
||||
data?.resize(mdwInfo.winWidth, mdwInfo.winHeight, (err) => {
|
||||
}else{
|
||||
//Get Main Window
|
||||
windowStage.getMainWindow((err, data) => {
|
||||
if (err.code) {
|
||||
console.error(`Failed to resize the window. Code: ${err.code}, message: ${err.message}`);
|
||||
console.error(`Failed to obtain the main window. Code: ${err.code}, message: ${err.message}`);
|
||||
return;
|
||||
}
|
||||
console.info(`Succeeded in resizing the window to ${mdwInfo.winWidth}x${mdwInfo.winHeight}.`);
|
||||
});
|
||||
mdwInfo.win = data;
|
||||
mdwInfo.winId =data.getWindowProperties().id;
|
||||
//moveWindowTo
|
||||
data?.moveWindowTo(50, 50)
|
||||
//resize mainWindow Size
|
||||
data?.resize(mdwInfo.winWidth, mdwInfo.winHeight, (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 ${mdwInfo.winWidth}x${mdwInfo.winHeight}.`);
|
||||
});
|
||||
|
||||
// windowSizeChangeListener to Change mainWindowWidth&&mainWindowHeight in AppStorage
|
||||
data?.on('windowSizeChange', (ChangeData) => {
|
||||
// if Size Change save to AppStorage
|
||||
mdwInfo.winWidth = ChangeData.width;
|
||||
mdwInfo.winHeight = ChangeData.height;
|
||||
console.info('Succeeded in enabling the listener for window size changes. Data:' + ChangeData.width,
|
||||
ChangeData.height);
|
||||
// windowSizeChangeListener to Change mainWindowWidth&&mainWindowHeight in AppStorage
|
||||
data?.on('windowSizeChange', (ChangeData) => {
|
||||
// if Size Change save to AppStorage
|
||||
mdwInfo.winWidth = ChangeData.width;
|
||||
mdwInfo.winHeight = 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.');
|
||||
});
|
||||
//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<DisplayWindowInfo>(DisplayWindowInfo);
|
||||
if (mdwInfo.win) {
|
||||
|
||||
@ -4,7 +4,7 @@ import {
|
||||
CheckExistDir,
|
||||
ExtractDir,
|
||||
HilogSadboxFontDirFile
|
||||
} from "../pages/extractdir/ExtractDir";
|
||||
} from "./ExtractDir";
|
||||
import UIAbility from "@ohos.app.ability.UIAbility";
|
||||
|
||||
export function InitFonts(uac:common.UIAbilityContext):boolean{
|
||||
@ -25,8 +25,10 @@ export function InitFonts(uac:common.UIAbilityContext):boolean{
|
||||
uac.startAbility(wantInfo).then(() => {
|
||||
uac.terminateSelf();
|
||||
})
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}else{
|
||||
HilogSadboxFontDirFile(uac,'fonts');
|
||||
HilogSadboxFontDirFile(uac,'example');
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { window } from "@kit.ArkUI";
|
||||
import { InitFonts } from "./InitFonts";
|
||||
import { InitEnv } from "./InitEnv";
|
||||
import { InitSubAbility } from "./InitSubAbility";
|
||||
import { InitGlobalDWI } from "./InitGlobalDWI";
|
||||
import { common } from "@kit.AbilityKit";
|
||||
|
||||
@ -18,10 +17,6 @@ export function InitHub(win:window.Window,ws:window.WindowStage,uac:common.UIAbi
|
||||
console.log("InitGlobalDWI Failed!")
|
||||
return false;
|
||||
}
|
||||
// if(!InitSubAbility(uac)){
|
||||
// console.log("InitSubAbility Failed!")
|
||||
// return false;
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ import { window } from '@kit.ArkUI';
|
||||
import { common, StartOptions,Want } from "@kit.AbilityKit";
|
||||
import { picker } from '@kit.CoreFileKit';
|
||||
import NativeOpenCAX from 'libopencax.so';
|
||||
import {EventSubAbility} from './EventSubAbility'
|
||||
|
||||
import {
|
||||
TitleButton,
|
||||
@ -40,6 +41,7 @@ export class UIMode{
|
||||
|
||||
//窗体保存容器
|
||||
export let subWins:Map<string,SubWinInfo>=new Map<string,SubWinInfo>;
|
||||
export let subStage:Array<string>=[];
|
||||
export let uiMode:UIMode=new UIMode(true);
|
||||
//随机ID
|
||||
export function RndId(): string {
|
||||
@ -138,54 +140,6 @@ export function EventPage(event:TitleButton){
|
||||
|
||||
}
|
||||
|
||||
async function EventCreateWin(): Promise<boolean>{
|
||||
let want: Want = {
|
||||
bundleName: 'com.example.opencax',
|
||||
abilityName: 'SubWinAbility'
|
||||
};
|
||||
try {
|
||||
let ctx = mdwInfo.win?.getUIContext().getHostContext() as common.UIAbilityContext;
|
||||
|
||||
if (!ctx) {
|
||||
console.error("Failed to get UIAbilityContext");
|
||||
return false;
|
||||
}
|
||||
// 监听来自 SubWinAbility 的初始化完成事件
|
||||
const initializationPromise = new Promise<boolean>((resolve) => {
|
||||
|
||||
let appCtx =mdwInfo.win?.getUIContext().getHostContext()?.getApplicationContext();
|
||||
|
||||
appCtx?.eventHub.on('SubWinInitialized', (data: Object) => {
|
||||
console.info("Received SubWinInitialized event:", data);
|
||||
// 可以根据 data 中的信息判断是否成功
|
||||
if (data && data !== undefined) {
|
||||
resolve(data as boolean);
|
||||
} else {
|
||||
resolve(false);
|
||||
}
|
||||
appCtx?.eventHub.off('SubWinInitialized');
|
||||
});
|
||||
});
|
||||
//启动参
|
||||
let options: StartOptions = {
|
||||
withAnimation:false,
|
||||
hideStartWindow:true
|
||||
};
|
||||
// 发起启动 Ability 的请求
|
||||
console.info("Attempting to start SubWinAbility...");
|
||||
await ctx.startAbility(want,options);
|
||||
console.info("StartAbility request sent.");
|
||||
// --- 等待初始化完成事件 ---
|
||||
console.info("Waiting for SubWinInitialized event...");
|
||||
const initResult = await initializationPromise;
|
||||
console.info("SubWin initialization result:", initResult);
|
||||
return initResult;
|
||||
} catch (error) {
|
||||
console.error("Failed to start ability:", error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//事件类型:子窗体
|
||||
export function EventWin(event:TitleButton){
|
||||
let winInfo: SubWinInfo=new SubWinInfo;
|
||||
@ -200,14 +154,16 @@ export function EventWin(event:TitleButton){
|
||||
}else if(event?.btnEvent.command=='Page_Options'){
|
||||
winInfo=new SubWinInfo(event.btnName,event.btnEvent.page,mdwInfo.winWidth*0.6,mdwInfo.winHeight*0.8);
|
||||
}
|
||||
EventCreateWin().then((result) => {
|
||||
//执行订阅命令,加载Sub Window参数
|
||||
if(result){
|
||||
let context =mdwInfo.win?.getUIContext().getHostContext()?.getApplicationContext();
|
||||
context?.eventHub.emit('InitSubWindow',winInfo);
|
||||
}
|
||||
});
|
||||
|
||||
if(subStage.indexOf(event.btnName)===-1){
|
||||
let ctx = mdwInfo.win?.getUIContext().getHostContext() as common.UIAbilityContext;
|
||||
EventSubAbility(ctx).then((result) => {
|
||||
if(result){
|
||||
let context =mdwInfo.win?.getUIContext().getHostContext()?.getApplicationContext();
|
||||
context?.eventHub.emit('InitSubWindow',winInfo);
|
||||
}
|
||||
});
|
||||
subStage.push(event.btnName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
import { window } from '@kit.ArkUI';
|
||||
import { common, StartOptions, UIAbility,Want } from "@kit.AbilityKit";
|
||||
export function InitSubAbility(uac:common.UIAbilityContext): boolean{
|
||||
import { common, StartOptions,Want } from "@kit.AbilityKit";
|
||||
import { util } from '@kit.ArkTS';
|
||||
|
||||
export async function EventSubAbility(uac:common.UIAbilityContext): Promise<boolean>{
|
||||
let want: Want = {
|
||||
bundleName: 'com.example.opencax',
|
||||
abilityName: 'SubWinAbility'
|
||||
abilityName: 'SubAbility',
|
||||
};
|
||||
try {
|
||||
if (!uac) {
|
||||
@ -12,9 +13,7 @@ export function InitSubAbility(uac:common.UIAbilityContext): boolean{
|
||||
}
|
||||
// 监听来自 SubWinAbility 的初始化完成事件
|
||||
const initializationPromise = new Promise<boolean>((resolve) => {
|
||||
|
||||
let appCtx =uac.getApplicationContext();
|
||||
|
||||
appCtx?.eventHub.on('SubWinInitialized', (data: Object) => {
|
||||
console.info("Received SubWinInitialized event:", data);
|
||||
// 可以根据 data 中的信息判断是否成功
|
||||
@ -30,16 +29,14 @@ export function InitSubAbility(uac:common.UIAbilityContext): boolean{
|
||||
let options: StartOptions = {
|
||||
withAnimation:false,
|
||||
hideStartWindow:true
|
||||
|
||||
};
|
||||
let initResult:boolean=true;
|
||||
// 发起启动 Ability 的请求
|
||||
console.info("Attempting to start SubWinAbility...");
|
||||
uac.startAbility(want,options).then((result) => {})
|
||||
await uac.startAbility(want,options);
|
||||
console.info("StartAbility request sent.");
|
||||
// --- 等待初始化完成事件 ---
|
||||
console.info("Waiting for SubWinInitialized event...");
|
||||
initializationPromise.then((_initResult) => {initResult=_initResult})
|
||||
const initResult = await initializationPromise;
|
||||
console.info("SubWin initialization result:", initResult);
|
||||
return initResult;
|
||||
} catch (error) {
|
||||
@ -20,10 +20,10 @@ export class PromptAction {
|
||||
PromptAction.options = options;
|
||||
}
|
||||
|
||||
static async openDialog() {
|
||||
static openDialog() {
|
||||
if (PromptAction.contentNode !== null) {
|
||||
try{
|
||||
await PromptAction.ctx.getPromptAction().openCustomDialog(PromptAction.contentNode, PromptAction.options);
|
||||
PromptAction.ctx.getPromptAction().openCustomDialog(PromptAction.contentNode, PromptAction.options);
|
||||
}catch(error){
|
||||
let message = (error as BusinessError).message;
|
||||
let code = (error as BusinessError).code;
|
||||
@ -32,10 +32,10 @@ export class PromptAction {
|
||||
}
|
||||
}
|
||||
|
||||
static async closeDialog() {
|
||||
static closeDialog() {
|
||||
if (PromptAction.contentNode !== null) {
|
||||
try{
|
||||
await PromptAction.ctx.getPromptAction().closeCustomDialog(PromptAction.contentNode);
|
||||
PromptAction.ctx.getPromptAction().closeCustomDialog(PromptAction.contentNode);
|
||||
}catch(error){
|
||||
let message = (error as BusinessError).message;
|
||||
let code = (error as BusinessError).code;
|
||||
|
||||
@ -4,7 +4,7 @@ import { window, display, AppStorageV2, ColorMetrics } from '@kit.ArkUI';
|
||||
import {SubWinInfo} from '../pages/eventhub/EventBase'
|
||||
const DOMAIN = 0x0000;
|
||||
|
||||
export default class SubWinAbility extends UIAbility {
|
||||
export default class SubAbility extends UIAbility {
|
||||
private subWin?:window.Window=undefined;
|
||||
private subWinStage?: window.WindowStage=undefined;
|
||||
//注册订阅事件
|
||||
@ -20,6 +20,7 @@ export default class SubWinAbility extends UIAbility {
|
||||
}
|
||||
//执行窗口参数
|
||||
InitWindowParam(winInfo:SubWinInfo){
|
||||
///window.shiftAppWindowFocus
|
||||
//Load page
|
||||
this.subWinStage?.loadContent(winInfo.page, (err) => {
|
||||
if (err.code) {
|
||||
@ -46,25 +47,23 @@ export default class SubWinAbility extends UIAbility {
|
||||
});
|
||||
}
|
||||
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
|
||||
try {
|
||||
//订阅事件
|
||||
this.onWinEventHub();
|
||||
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');
|
||||
this.onWinEventHub();
|
||||
}
|
||||
onAcceptWant(want: Want): string {
|
||||
|
||||
return 'SubAbility';
|
||||
}
|
||||
onDestroy(): void {
|
||||
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy');
|
||||
}
|
||||
|
||||
async onWindowStageCreate(windowStage: window.WindowStage): Promise<void> {
|
||||
this.subWinStage=windowStage;
|
||||
this.subWin = await windowStage.getMainWindow();
|
||||
let ctx =this.context.getApplicationContext()
|
||||
ctx.eventHub.emit('SubWinInitialized',true);
|
||||
onWindowStageCreate(windowStage: window.WindowStage): void {
|
||||
if(this.subWinStage==undefined&&this.subWin==undefined){
|
||||
this.subWinStage=windowStage;
|
||||
this.subWin = windowStage.getMainWindowSync();
|
||||
let ctx =this.context.getApplicationContext()
|
||||
ctx.eventHub.emit('SubWinInitialized',true);
|
||||
}
|
||||
}
|
||||
|
||||
onWindowStageDestroy(): void {
|
||||
@ -44,15 +44,15 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "SubWinAbility",
|
||||
"srcEntry": "./ets/subwinability/SubWinAbility.ets",
|
||||
"name": "SubAbility",
|
||||
"srcEntry": "./ets/subability/SubAbility.ets",
|
||||
"description": "$string:EntryAbility_desc",
|
||||
"icon": "$media:base_opencax_logo",
|
||||
"label": "$string:EntryAbility_label",
|
||||
"startWindowIcon": "$media:base_sub_background",
|
||||
"startWindowBackground": "$color:start_window_background",
|
||||
"exported": true,
|
||||
"launchType":"multiton",
|
||||
"launchType":"specified",
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
|
||||
Loading…
Reference in New Issue
Block a user