aboutToDisappear(): void {
let windowClass: window.Window | undefined = undefined;
window.getLastWindow(getContext(this)).then((win) => {
this.window = win
})
window.getLastWindow(getContext(this), (err: BusinessError, data) => {
const errCode: number = err.code;
if (errCode) {
console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));
return;
}
windowClass = data;
console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
setWindowPrivacyMode(windowClass, true)
});
}
export function setWindowPrivacyMode(windowClass: window.Window, isPrivacyMode: boolean) {
// try {
windowClass.setWindowPrivacyMode(isPrivacyMode
/*, (err: BusinessError) => {
if (err) {
console.error('Failed to set the window to the privacy mode. Cause:'+ JSON.stringify(err));
return;
}
console.info('Succeeded in setting the window to the privacy mode.');
}*/
);
console.info(`setWindowPrivacyMode 已执行`);
// } catch (exception) {
// console.error('Failed to set the window to the privacy mode. Cause:'+ JSON.stringify(exception));
// }
}
参考demo: