Skip to content

Commit 87ad3cd

Browse files
committed
v13 compatibility
1 parent fe794d7 commit 87ad3cd

4 files changed

Lines changed: 134 additions & 59 deletions

File tree

.github/workflows/main.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Release Creation
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
release:
8+
types: [published]
9+
env:
10+
MODULE_ID: warning-remove
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
# Get part of the tag after the `v`.
21+
- name: Extract tag version number
22+
id: get_version
23+
uses: battila7/get-version-action@v2
24+
25+
# Modify manifest version, download, esmodules, styles, remove hotreload.
26+
- name: Modify Manifest to remove HotReload
27+
uses: microsoft/variable-substitution@v1
28+
with:
29+
files: "module.json"
30+
env:
31+
flags.hotReload: false
32+
version: ${{steps.get_version.outputs.version-without-v}}
33+
id: ${{env.MODULE_ID}}
34+
url: https://github.com/${{ github.repository }}
35+
download: https://github.com/${{ github.repository }}/releases/download/${{steps.get_version.outputs.version}}/${{env.MODULE_ID}}.zip
36+
manifest: https://github.com/${{ github.repository }}/releases/latest/download/module.json
37+
38+
# Create zip file.
39+
- name: Create ZIP archive
40+
run: zip -r ./${{env.MODULE_ID}}.zip
41+
module.json
42+
warning-remove.js
43+
README.md
44+
LICENSE
45+
CHANGELOG.md
46+
css/
47+
48+
# Get the release notes and set a convenient 'id' for accessing later
49+
- name: Read release notes and add to package
50+
uses: yashanand1910/standard-release-notes@v1.5.0
51+
id: get_release_notes
52+
with:
53+
changelog_path: ./CHANGELOG.md # Optional
54+
version: ${{steps.get_version.outputs.version}} # Required
55+
56+
# Create a release for this specific version.
57+
- name: Update Release with Files
58+
if: '!github.event.release.prerelease'
59+
id: create_version_release
60+
uses: ncipollo/release-action@v1
61+
with:
62+
allowUpdates: true
63+
name: ${{ github.event.release.name }}
64+
draft: false
65+
prerelease: false
66+
token: ${{ secrets.GITHUB_TOKEN }}
67+
artifacts: "./module.json, ./${{env.MODULE_ID}}.zip"
68+
tag: ${{ github.event.release.tag_name }}
69+
body: ${{ steps.get_release_notes.outputs.release_notes }}

CANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# CHANGELOG
2+
3+
## [1.3.00]
4+
5+
- Foundry v13 Compatibility

module.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"id": "warning-remove",
33
"title": "Remove warnings",
4-
"description": "Remove resolution warning.",
5-
"version": "1.1.2",
6-
"download": "https://github.com/misthero/warning-remove/releases/download/v1.1.2/warning-remove.zip",
7-
"manifest": "https://github.com/misthero/warning-remove/releases/download/v1.1.2/module.json",
4+
"description": "Remove notifications and warning.",
5+
"version": "2.0.0",
6+
"download": "https://github.com/misthero/warning-remove/releases/download/v2.0.0/warning-remove.zip",
7+
"manifest": "https://github.com/misthero/warning-remove/releases/download/v2.0.0/module.json",
88
"url": "https://github.com/misthero/warning-remove",
99
"authors": [
1010
{
@@ -14,8 +14,8 @@
1414
],
1515
"compatibility": {
1616
"minimum": "11",
17-
"verified": "12",
18-
"maximum": "12"
17+
"verified": "13",
18+
"maximum": "13"
1919
},
2020
"scripts": [
2121
"warning-remove.js"

warning-remove.js

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
/* list of default strings to remove */
22
let defaultStrings = [
3-
"Foundry Virtual Tabletop requires a minimum screen resolution",
3+
"Foundry Virtual Tabletop requires",
44
"not displayed because the game Canvas is disabled",
55
"is unmaintained and may introduce stability issues"
66
];
77

88
let removeStrings = []
99

10+
// CONFIG.debug.hooks = true
11+
1012
const W_R_ID = 'warning-remove';
1113

12-
Hooks.on('ready', () => {
14+
Hooks.on('init', () => {
1315
game.settings.register(W_R_ID, 'qty', {
1416
name: 'Number of messages to remove',
1517
hint: 'default: 3',
@@ -93,60 +95,59 @@ Hooks.on('ready', () => {
9395
*
9496
* This function should be run during the "ready" Hook call.
9597
*/
96-
function InitNotificationsProxy(patternsToHide = []) {
97-
// Do nothing if no patterns are provided.
98-
if (!patternsToHide.length) { return; }
99-
100-
// Get the original array of queued notifications, and store a constant reference to it
101-
const notificationQueue = ui.notifications.queue;
102-
103-
// Convert the provided patterns into regular expressions
104-
const regExpPatterns = patternsToHide.map((pattern) => new RegExp(pattern));
105-
106-
// Define a handler for the proxy that will be used to intercept notifications
107-
const handler = {
108-
set: function (target, property, value) {
109-
// Handle changes to the array length property
110-
if (property === "length") {
111-
// Perform the default behavior for length changes
112-
target.length = value;
113-
return true; // Indicate success
114-
}
115-
// Handle directly setting the value for non-index properties (necessary for array methods like 'next')
116-
else if (typeof property === "string" && isNaN(Number(property))) {
117-
// Perform the default behavior for non-index properties.
118-
target[property] = value;
119-
return true; // Indicate success
120-
}
121-
// Handle setting array indices
122-
else if (!isNaN(Number(property))) {
123-
// If the value is a notification and its content matches one of the provided patterns ...
124-
if (value
125-
&& typeof value === "object"
126-
&& "message" in value
127-
&& typeof value.message === "string"
128-
&& regExpPatterns.some((pattern) => pattern.exec(value.message))) {
129-
// ... edit the notification to:
130-
Object.assign(value, {
131-
console: false, // ... prevent logging it to the console
132-
permanent: false, // ... ensure the notification element is removed automatically
133-
type: "do-not-display" // ... 'hack' the type to add the 'do-not-display' class
134-
});
98+
Hooks.once("canvasReady", () => {
99+
if (!ui.notifications) {
100+
console.error("ui.notifications is not initialized. Skipping notification interception.");
101+
return;
102+
}
103+
104+
// List of patterns to block
105+
const patternsToBlock = removeStrings;
106+
107+
console.log("Patterns to block:", removeStrings);
108+
109+
// Convert patterns to regular expressions
110+
const regExpPatterns = patternsToBlock.map(pattern => new RegExp(pattern, "i"));
111+
112+
// Save the original notify method
113+
const originalNotify = ui.notifications.notify;
114+
115+
// Override the notify method
116+
ui.notifications.notify = function (message, type = "info", opts = {}) {
117+
// Shallow-copy options so we don't mutate the caller's object
118+
const options = foundry.utils.mergeObject({ localize: false, escape: true, clean: true, format: null }, opts, { inplace: false });
119+
120+
// 1) Normalize to string (or Error.message)
121+
let text = message instanceof Error ? message.message : String(message);
122+
123+
// 2) Apply formatting placeholders if present
124+
if (options.format) {
125+
if (options.escape) {
126+
for (let k of Object.keys(options.format)) {
127+
options.format[k] = foundry.utils.escapeHTML(options.format[k]);
135128
}
136-
// Otherwise, perform the default behavior for setting index properties.
137-
target[Number(property)] = value;
138-
return true; // Indicate success
129+
// If it’s a real localization key, no extra cleaning
130+
if (game.i18n.has(text)) options.clean = false;
139131
}
140-
return false; // Indicate failure for all other cases
132+
text = game.i18n.format(text, options.format);
133+
}
134+
// 3) Otherwise localize if requested
135+
else if (options.localize) {
136+
if (game.i18n.has(text)) options.clean = false;
137+
text = game.i18n.localize(text);
141138
}
139+
// 4) Finally clean HTML if still flagged
140+
if (options.clean) text = foundry.utils.cleanHTML(text);
141+
142+
// Check if the message matches any of the patterns
143+
if (regExpPatterns.some(pattern => pattern.test(text))) {
144+
console.warn(`Blocked notification [${type}]: ${text}`);
145+
return; // Prevent the notification from being displayed
146+
}
147+
148+
// Call the original notify method for non-blocked messages
149+
return originalNotify.call(this, message, type, options);
142150
};
143151

144-
// Replace the notifications queue array with a Proxy defined by the above handler.
145-
ui.notifications.queue = new Proxy(notificationQueue, handler);
146-
}
147-
// Initialize the notifications proxy during the 'ready' hook, after ui.notifications has been defined
148-
Hooks.once("ready", () => {
149-
// I've hard-coded the two notifications I want to hide, but this could easily be a
150-
// user setting, allowing users to customize which notifications are silenced.
151-
InitNotificationsProxy(removeStrings);
152+
console.log("Notification interception initialized.");
152153
});

0 commit comments

Comments
 (0)