Skip to content

Commit

Permalink
Improved auto update
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Jul 4, 2024
1 parent ba697c5 commit 4f90f07
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
17 changes: 9 additions & 8 deletions apps/spa/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import { checkPeriodically, createUpdateApi } from 'piral-update';
import { SelectUser } from './SelectUser';
import { layout, errors } from './layout';
import { getCurrentUser } from './auth';
import { autoUpdate } from './update';

const root = createRoot(document.querySelector('#app'));
const user = getCurrentUser();
const autoUpdate = process.env.DEBUG_PILET === 'on';
const every10Seconds = {
period: 10 * 1000,
};
const neverCheck = () => {};

if (!user) {
root.render(<SelectUser />);
Expand All @@ -24,13 +28,10 @@ if (!user) {
},
plugins: [
...createStandardApi(),
autoUpdate &&
createUpdateApi({
listen: checkPeriodically({
period: 10 * 1000,
}),
}),
].filter(Boolean),
createUpdateApi({
listen: autoUpdate ? checkPeriodically(every10Seconds) : neverCheck,
}),
],
requestPilets() {
return fetch(`${feedUrl}?role=${user.role}&target=spa`)
.then((res) => res.json())
Expand Down
2 changes: 1 addition & 1 deletion apps/spa/src/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
MenuItemProps,
ExtensionSlot,
} from 'piral';
import { getCurrentUser, logoutCurrentUser } from './auth';
import { UpdateDialog } from 'piral-update';
import { getCurrentUser, logoutCurrentUser } from './auth';

const MenuItem: React.FC<MenuItemProps> = ({ children }) => <li className="nav-item">{children}</li>;

Expand Down
1 change: 1 addition & 0 deletions apps/spa/src/update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const autoUpdate = process.env.DEBUG_PILET !== 'on';

0 comments on commit 4f90f07

Please sign in to comment.