Add an automatic version notification for new stable releases, and optionally beta releases
This commit is contained in:
parent
d3a60fbef5
commit
09ac9624ed
6 changed files with 106 additions and 0 deletions
|
|
@ -18,6 +18,7 @@ import { TAFMacro } from "../documents/Macro.mjs";
|
|||
import { TAFTokenDocument } from "../documents/Token.mjs";
|
||||
|
||||
// Settings
|
||||
import { registerReleaseSettings } from "../utils/ReleaseChannels.mjs";
|
||||
import { registerWorldSettings } from "../settings/world.mjs";
|
||||
|
||||
// Utils
|
||||
|
|
@ -89,6 +90,7 @@ Hooks.on(`init`, () => {
|
|||
);
|
||||
// #endregion Sheets
|
||||
|
||||
registerReleaseSettings();
|
||||
registerWorldSettings();
|
||||
|
||||
registerSockets();
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { checkForNewReleases } from "../utils/ReleaseChannels.mjs";
|
||||
import { checkMigrations } from "../migrations/checkMigrations.mjs";
|
||||
|
||||
Hooks.on(`ready`, () => {
|
||||
|
|
@ -7,4 +8,5 @@ Hooks.on(`ready`, () => {
|
|||
};
|
||||
|
||||
checkMigrations();
|
||||
checkForNewReleases();
|
||||
});
|
||||
|
|
|
|||
75
module/utils/ReleaseChannels.mjs
Normal file
75
module/utils/ReleaseChannels.mjs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
import { __ID__, filePath } from "../consts.mjs";
|
||||
import { Logger } from "./Logger.mjs";
|
||||
|
||||
const { ChatMessage } = foundry.documents;
|
||||
const { renderTemplate } = foundry.applications.handlebars;
|
||||
const { fetchJsonWithTimeout, isNewerVersion } = foundry.utils;
|
||||
|
||||
let newestVersion = null;
|
||||
|
||||
async function fetchLatestVersion() {
|
||||
const includeBetas = game.settings.get(__ID__, `betaChannel`);
|
||||
try {
|
||||
const releases = await fetchJsonWithTimeout(`https://git.varify.ca/api/v1/repos/Foundry/taf/releases?pre-release=${includeBetas}&limit=1`);
|
||||
return releases.at(0);
|
||||
} catch {
|
||||
Logger.error(`Failed to fetch latest version from Forgejo, halting version checks`);
|
||||
return;
|
||||
};
|
||||
};
|
||||
|
||||
export async function getLatestVersion() {
|
||||
if (!newestVersion) {
|
||||
newestVersion = await fetchLatestVersion();
|
||||
};
|
||||
return newestVersion;
|
||||
};
|
||||
|
||||
export async function checkForNewReleases() {
|
||||
// Only perform the update check if the game is ready and the user is the active GM
|
||||
if (!game.user.isActiveGM || !game.ready) { return };
|
||||
|
||||
// Don't do any version notifications if this is a fresh world
|
||||
const lastNotifiedVersion = game.settings.get(__ID__, `lastUpdateNotified`);
|
||||
if (!lastNotifiedVersion) {
|
||||
game.settings.set(__ID__, `lastUpdateNotified`, game.system.version);
|
||||
return;
|
||||
};
|
||||
let latest = newestVersion = await getLatestVersion();
|
||||
|
||||
// Is the latest release newer than the previously notified release
|
||||
const latestVersion = latest.tag_name.replace(/^v/, ``);
|
||||
if (!isNewerVersion(latestVersion, lastNotifiedVersion)) { return };
|
||||
|
||||
const content = await renderTemplate(
|
||||
filePath(`templates/new-version-message.hbs`),
|
||||
{
|
||||
release: latest,
|
||||
system: game.system,
|
||||
},
|
||||
);
|
||||
ChatMessage.implementation.create({
|
||||
whisper: [ game.user.id ],
|
||||
content,
|
||||
});
|
||||
|
||||
// Mark the new version as the
|
||||
game.settings.set(__ID__, `lastUpdateNotified`, latestVersion);
|
||||
};
|
||||
|
||||
export function registerReleaseSettings() {
|
||||
game.settings.register(__ID__, `betaChannel`, {
|
||||
name: `${__ID__}.settings.betaChannel.name`,
|
||||
hint: `${__ID__}.settings.betaChannel.hint`,
|
||||
config: true,
|
||||
type: Boolean,
|
||||
default: false,
|
||||
scope: `world`,
|
||||
});
|
||||
|
||||
game.settings.register(__ID__, `lastUpdateNotified`, {
|
||||
config: false,
|
||||
type: String,
|
||||
scope: `world`,
|
||||
});
|
||||
};
|
||||
|
|
@ -23,6 +23,9 @@
|
|||
@import url("./elements/span.css") layer(elements);
|
||||
@import url("./elements/table.css") layer(elements);
|
||||
|
||||
/* Partials */
|
||||
@import url("./misc.css") layer(partials);
|
||||
|
||||
/* Apps */
|
||||
@import url("./Apps/common.css") layer(apps);
|
||||
@import url("./Apps/Ask.css") layer(apps);
|
||||
|
|
|
|||
7
styles/misc.css
Normal file
7
styles/misc.css
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
.taf-chat-version-notif {
|
||||
h2 {
|
||||
font-family: var(--font-body);
|
||||
font-size: 1.5rem;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
17
templates/new-version-message.hbs
Normal file
17
templates/new-version-message.hbs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<div class="taf-chat-version-notif">
|
||||
<h2>
|
||||
{{ system.title }}
|
||||
{{ release.tag_name }}
|
||||
</h2>
|
||||
<p>
|
||||
A new {{ifThen release.prerelease "beta" ""}} version of {{ system.title }} has been released.
|
||||
</p>
|
||||
<a
|
||||
class="button"
|
||||
href="{{ release.html_url }}"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
Release Notes
|
||||
</a>
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue