注销后清除导航堆栈-Gmail加载项

时间:2019-11-26 15:04:57

标签: google-apps-script google-apps gmail-addons google-apps-script-addon

我有一个带CardAction的gmail插件-注销:

enter image description here

如果在堆栈导航中只有几张卡片,并且用户进行“注销”-出现“后退箭头”:

enter image description here

这是我的logoutAction,可以正常工作,但是您有任何想法如何禁用此后退箭头吗?

function logoutAction(e) {

  var service = getOAuthService();
  service.reset();

  return CardService.newAuthorizationException()
  .setAuthorizationUrl(service.getAuthorizationUrl())
  .setResourceDisplayName("MY_PROJECT")
  .throwException();
}

这是我的简单Card,我可以在其中使用logoutAction:

function afterImportScreenBuild() {

    var action = CardService.newAction().setFunctionName('logoutAction');

    var cardHeader = CardService.newCardHeader()
        .setTitle("MY_HEADER");

    var viewButton = CardService.newTextButton()
        .setText("BTN")
        .setOpenLink(CardService.newOpenLink()
            .setUrl("https://test.com/"));

    var card = CardService.newCardBuilder()
        .setHeader(cardHeader);

    var section = CardService.newCardSection();

    var textKeyValue = CardService.newKeyValue()
        .setContent("MY_TIMELINE")
        .setButton(viewButton);

    card.addCardAction(CardService.newCardAction().setText('Logout').setOnClickAction(action));
    section.addWidget(textKeyValue);
    card.addSection(section);

    return card.build();
}

如果我的logoutAction返回ActionResponseBuilder,我可以使用popToRoot()

CardService.newActionResponseBuilder().setNavigation( CardService.newNavigation().popToRoot() ).build()

但是在logoutAction中,我需要返回newAuthorizationException(),但我不知道如何清除导航堆栈。

1 个答案:

答案 0 :(得分:0)

我不确定,但请允许我说几句话

function logoutAction(e) {

  var service = getOAuthService();
  service.reset();

}

使用此功能,您完成了注销过程,因此,我的问题是:

您真的需要在那儿退货吗?

否则,我们就完成了。

如果我们确实需要退货,我们可以随时在newAuthorizationException()上使用setCustomUiCallback(callback)并在那里拨打popToRoot(),显示您想要的卡片,并避免使用返回箭头