-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notification): update notification (#1420)
* sends a one-time message when the system migrates versions #1396
- Loading branch information
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Handles all logic related to migrating the system to a new version, including sending notifications | ||
* @returns {Promise<void>} | ||
*/ | ||
export async function handleUpdate() { | ||
const registeredVersion = game.settings.get("starwarsffg", "systemMigrationVersion"); | ||
const runningVersion = game.system.version; | ||
if (registeredVersion !== runningVersion) { | ||
await handleMigration(runningVersion); | ||
await sendChanges(runningVersion); | ||
await game.settings.set("starwarsffg", "systemMigrationVersion", runningVersion); | ||
} | ||
} | ||
|
||
/** | ||
* Handles migration logic for the system | ||
* @param oldVersion - version previously run (from the settings) | ||
* @param newVersion - version currently running (from game.system.version) | ||
* @returns {Promise<void>} | ||
*/ | ||
async function handleMigration(oldVersion, newVersion) { | ||
// migration handlers should be added here going forward | ||
} | ||
|
||
/** | ||
* Sends a notification to all users in the game that the system has been updated | ||
* @param newVersion - version currently running (from game.system.version) | ||
* @returns {Promise<void>} | ||
*/ | ||
async function sendChanges(newVersion) { | ||
const template = "systems/starwarsffg/templates/notifications/new_version.html"; | ||
const html = await renderTemplate(template, { version: newVersion }); | ||
const messageData = { | ||
user: game.user.id, | ||
type: CONST.CHAT_MESSAGE_TYPES.OTHER, | ||
content: html, | ||
}; | ||
ChatMessage.create(messageData); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div class="updateNotification"> | ||
<h2>Star Wars FFG v{{ version }}</h2> | ||
Hello! Welcome to a new version of the Star Wars FFG system. :) | ||
<hr> | ||
<div class="updateLinks"> | ||
Useful links:<br> | ||
• <a href="/~https://github.com/StarWarsFoundryVTT/StarWarsFFG/wiki/new%E2%80%90features%E2%80%90v{{ version }}">Changes to how you interact with the system</a><br> | ||
• <a href="/~https://github.com/StarWarsFoundryVTT/StarWarsFFG/blob/main/CHANGELOG.md">Full changelog</a><br> | ||
• <a href="/~https://github.com/StarWarsFoundryVTT/StarWarsFFG/wiki">System Wiki</a><br> | ||
</div> | ||
<hr> | ||
This message will show once per version update. | ||
</div> |