1 个回答

参考demo:

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));
  // }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进