in plugin/src/software/aws/toolkits/eclipse/amazonq/providers/assets/ToolkitLoginWebViewAssetProvider.java [76:145]
private Optional<String> resolveContent() {
try {
URL jsFile = PluginUtils.getResource("webview/build/assets/js/getStart.js");
String decodedPath = URLDecoder.decode(jsFile.getPath(), StandardCharsets.UTF_8);
// Remove leading slash for Windows paths
decodedPath = decodedPath.replaceFirst("^/([A-Za-z]:)", "$1");
Path jsParent = Paths.get(decodedPath).getParent();
String jsDirectoryPath = jsParent.normalize().toString();
webviewAssetServer = new WebviewAssetServer();
var result = webviewAssetServer.resolve(jsDirectoryPath);
if (!result) {
return Optional.of("Failed to load JS");
}
var loginJsPath = webviewAssetServer.getUri() + "getStart.js";
boolean isDarkTheme = THEME_DETECTOR.isDarkTheme();
return Optional.of(String.format(
"""
<!DOCTYPE html>
<html>
<head>
<meta
http-equiv="Content-Security-Policy"
content="default-src 'none'; script-src %s 'unsafe-inline'; style-src %s 'unsafe-inline';
img-src 'self' data:; object-src 'none'; base-uri 'none'; connect-src swt:;"
>
<title>AWS Q</title>
</head>
<body class="jb-light">
<div id="app"></div>
<script type="text/javascript" src="%s" defer></script>
<script type="text/javascript">
%s
const init = () => {
changeTheme(%b);
Promise.all([
waitForFunction('ideCommand'),
waitForFunction('telemetryEvent')
])
.then(([ideCommand, telemetryEvent]) => {
const ideApi = {
postMessage(message) {
ideCommand(JSON.stringify(message));
}
};
window.ideApi = ideApi;
const telemetryApi = {
postClickEvent(event) {
telemetryEvent(event);
}
};
window.telemetryApi = telemetryApi;
ideCommand(JSON.stringify({"command":"onLoad"}));
})
.catch(error => console.error('Error in initialization:', error));
};
window.addEventListener('load', init);
</script>
</body>
</html>
""",
loginJsPath, loginJsPath, loginJsPath, getWaitFunction(), isDarkTheme));
} catch (IOException e) {
return Optional.of("Failed to load JS");
}
}