Skip to content

Commit

Permalink
Allow startup snip
Browse files Browse the repository at this point in the history
  • Loading branch information
wandyezj committed Sep 18, 2024
1 parent 0e1c64b commit 15fa9fe
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 2 deletions.
6 changes: 6 additions & 0 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ module.exports = async (env, options) => {
settings: "./src/settings.tsx",
blocks: "./src/blocks.tsx",
test: "./src/test.ts",
shared: "./src/shared.ts",
},
output: {
// Add contenthash to cache bust on CDN
Expand Down Expand Up @@ -131,6 +132,11 @@ module.exports = async (env, options) => {
filename: "test.html",
chunks: ["test"],
}),
new HtmlWebpackPlugin({
template: "src/shared.html",
filename: "shared.html",
chunks: ["shared"],
}),
new MonacoWebpackPlugin({
languages: [
"typescript",
Expand Down
3 changes: 3 additions & 0 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { setHost } from "./core/globals";
import { TriggerManager } from "./core/actions/TriggerManager";
import { getWatch } from "./core/util/getWatch";

// Redirect immediately to shared for simpler testing.
window.location.href = "./shared.html";

console.log("actions load");

// Store triggers in custom XML
Expand Down
6 changes: 4 additions & 2 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ async function runSnip() {
let html = snip.files["html"].content;
// Add back button to top of html
if (goBack) {
const backButtonHtml = `<button onclick="window.location.href='./edit.html';"> Back</button>`;
// window.location.href='./edit.html';
const backButtonHtml = `<button onclick="window.history.back();"> Back</button>`;
const refreshButtonHtml = `<button onclick="window.location.reload();">Refresh</button>`;
html = `${backButtonHtml} ${refreshButtonHtml}<br/><br/>${html}`;
}
// TODO: will need to compile TypeScript, where should this be done?

// compile TypeScript
const ts = snip.files["typescript"].content;
const { js, issues } = compileCode(ts);
console.log("Issues");
Expand Down
3 changes: 3 additions & 0 deletions src/shared.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background-color: white;
}
16 changes: 16 additions & 0 deletions src/shared.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html lang="en">
<metadata>
<title>Shared</title>
</metadata>
<head>
<meta charset="UTF-8" />
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="./shared.css" />
</head>
<body>
<div>
<h1>Shared</h1>
</div>
</body>
</html>
25 changes: 25 additions & 0 deletions src/shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Shared runtime, will be used for snips that should run in the background.

import { setupOffice } from "./core/setupOffice";

// Some rules for snips to run in the background
// must
// - only allow one to run in the background
// - be embedded in the document
// - only have default library references

// Want a button to go back from currently loaded
// Want a button to load a new one.

async function setup() {
await setupOffice();

// After the first time the add in is opened it will automatically load
Office.addin.setStartupBehavior(Office.StartupBehavior.load);

// redirect to edit and allow back
window.location.href = "./run.html#back";
// back will act as reload in this case.
}

setup();

0 comments on commit 15fa9fe

Please sign in to comment.