Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/client/hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const useAuth = () => {
const state = await serverFunctions.getAuthorizationState();
setAuthState(state as AuthState);
setAuthStatus('success');
await serverFunctions.refreshMenu();
} catch (error) {
console.log('Error getting auth data', error);
setAuthStatus('error');
Expand All @@ -41,7 +42,9 @@ const useAuth = () => {
analytics.trackLogout();
try {
await serverFunctions.resetOAuth();
setTimeout(getAuth, 500);
setTimeout(async () => {
await getAuth();
}, 500);
} catch (error) {
console.error('Error revoking OAuth:', error);
}
Expand Down
4 changes: 4 additions & 0 deletions src/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {
onOpen,
onInstall,
refreshMenu,
openCreateDiagramDialog,
openEditDiagramDialog,
openEditDiagramDialogWithUrl,
Expand Down Expand Up @@ -31,6 +33,8 @@ import {
// Public functions must be exported as named exports
export {
onOpen,
onInstall,
refreshMenu,
openCreateDiagramDialog,
openEditDiagramDialog,
openEditDiagramDialogWithUrl,
Expand Down
59 changes: 43 additions & 16 deletions src/server/ui.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
export function onOpen() {
const menu = DocumentApp.getUi()
.createAddonMenu()
.addItem('Start', 'openSidebar')
.addSeparator()
.addItem('New diagram', 'openCreateDiagramDialog')
.addItem('Browse diagrams', 'openSelectDiagramDialog')
.addItem('Edit selected diagram', 'openEditDiagramDialog')
.addSeparator()
.addItem('About', 'openAboutDialog')
.addItem('Help', 'openHelpDialog');

function buildMenu() {
const menu = DocumentApp.getUi().createAddonMenu();

menu.addItem('Start', 'openSidebar');

let authorized = false;

try {
const authState = getAuthorizationState();
authorized = authState && authState.authorized;
} catch (e) {
console.log('Error checking authorization state: ' + e);
Logger.log('Auth check failed: ' + e);
}

if (authorized) {
menu.addSeparator();
menu.addItem('New diagram', 'openCreateDiagramDialog');
menu.addItem('Browse diagrams', 'openSelectDiagramDialog');
menu.addItem('Edit selected diagram', 'openEditDiagramDialog');
}

menu.addSeparator();
menu.addItem('About', 'openAboutDialog');

menu.addToUi();
}

export function onOpen(e) {
buildMenu();
}

export function onInstall(e) {
onOpen(e);
}

export function refreshMenu() {
buildMenu();
}

export function setBaseUrl(url) {
try {
const scriptProperties = PropertiesService.getScriptProperties();
Expand Down Expand Up @@ -128,11 +153,12 @@ export function openAboutDialog() {
var ui = DocumentApp.getUi();

var text =
'PlantUML Gizmo was written for use in the OO Analysis and Design courses at École de technologie supérieure, and has been used by Google Engineers on Android and Google Pay.\n\n' +
'It uses JavaScript API Client Code described at http://plantuml.sourceforge.net/codejavascript.html as well as inflating routines at http://www.planttext.com/javascript/jquery-plantuml/plantuml.js\n\n' +
'Find me on twitter @thefuhrmanator. Version 15 (2019-11-22)';
'Mermaid for Google Docs \n\n' +
'Publisher: Mermaid Chart Inc\n' +
'Mermaid for Google Docs brings flexible, collaborative diagramming directly into your documents. Create, insert, and edit diagrams without leaving Google Docs—using Markdown syntax, the Visual Editor, or Mermaid AI\n\n' +
'For detailed information, reviews, and marketplace details, visit the Google Workspace Marketplace.';

ui.alert('About', text, ui.ButtonSet.OK);
ui.alert('Add-on Information', text, ui.ButtonSet.OK);
}

export function openHelpDialog() {
Expand All @@ -155,6 +181,7 @@ export function handleCallback(callbackRequest) {
var service = getOAuthService();
var authorized = service.handleCallback(callbackRequest);
if (authorized) {
refreshMenu();
return HtmlService.createHtmlOutput(
'<html><body>Success! You can close this window.<script>window.setTimeout(function() { google.script.host.close(); }, 1000);</script></body></html>'
);
Expand Down
Loading