diff --git a/plugin.json b/plugin.json index b8f532b..e281c2e 100644 --- a/plugin.json +++ b/plugin.json @@ -2,7 +2,7 @@ "id": "ir.quera.mattermost-vazirmatn", "name": "Mattermost Vazirmatn", "description": "Changes Mattermost font to Vazirmatn.", - "version": "1.0.1", + "version": "1.0.2", "min_server_version": "5.12.0", "webapp": { "bundle_path": "webapp/dist/main.js" diff --git a/webapp/package-lock.json b/webapp/package-lock.json index 218ee23..c578e1b 100644 --- a/webapp/package-lock.json +++ b/webapp/package-lock.json @@ -1,12 +1,12 @@ { "name": "mattermost-vazirmatn", - "version": "1.0.1", + "version": "1.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "mattermost-vazirmatn", - "version": "1.0.1", + "version": "1.0.2", "devDependencies": { "@babel/core": "^7.22.9", "babel-loader": "^9.1.3", diff --git a/webapp/package.json b/webapp/package.json index 62cb42c..4e816ce 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -1,6 +1,6 @@ { "name": "mattermost-vazirmatn", - "version": "1.0.1", + "version": "1.0.2", "description": "Changes Mattermost font to Vazirmatn.", "main": "src/index.js", "scripts": { diff --git a/webapp/src/index.js b/webapp/src/index.js index 7c80547..a925dfe 100644 --- a/webapp/src/index.js +++ b/webapp/src/index.js @@ -2,6 +2,29 @@ import manifest from './manifest'; import './style.css'; class MattermostVazirmatnPlugin { + // eslint-disable-next-line class-methods-use-this + initialize(registry, store) { + const state = store.getState(); + const siteURL = state?.entities?.general?.config?.SiteURL || state?.entities?.admin?.config?.ServiceSettings?.SiteURL || ''; + + console.log('initializing mattermost-vazirmatn plugin. SiteURL:', siteURL); + + // Load VazirmatnNL font face + const fontURL = `${siteURL}/plugins/${manifest.id}/public/fonts/vazirmatn-v33.003/Vazirmatn-NL[wght].woff2`; + const fontSrc = `url(${fontURL}) format('woff2 supports variations'), url(${fontURL}) format('woff2-variations')`; + const fontFace = new FontFace('VazirmatnNL', fontSrc, { + weight: '100 900', + style: 'normal', + display: 'swap', + // Only apply to arabic script. + // https://en.wikipedia.org/wiki/Arabic_script_in_Unicode + unicodeRange: 'U+0600-06FF, U+0750-077F, U+08A0-08FF, U+0870-089F, U+FB50-FDFF, U+FE70-FEFF, U+1EE00-1EEFF', + }); + fontFace.load().then((loadedFace) => { + document.fonts.add(loadedFace); + console.log('VazirmatnNL font loaded.'); + }); + } } window.registerPlugin(manifest.id, new MattermostVazirmatnPlugin()); diff --git a/webapp/src/style.css b/webapp/src/style.css index 7968faf..901902b 100644 --- a/webapp/src/style.css +++ b/webapp/src/style.css @@ -1,17 +1,3 @@ -@font-face { - font-family: VazirmatnNL; - src: url("/plugins/ir.quera.mattermost-vazirmatn/public/fonts/vazirmatn-v33.003/Vazirmatn-NL[wght].woff2") format('woff2 supports variations'), - url("/plugins/ir.quera.mattermost-vazirmatn/public/fonts/vazirmatn-v33.003/Vazirmatn-NL[wght].woff2") format('woff2-variations'); - font-weight: 100 900; - font-style: normal; - font-display: swap; - /** - * Only apply to arabic script. - * https://en.wikipedia.org/wiki/Arabic_script_in_Unicode - */ - unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+0870-089F, U+FB50-FDFF, U+FE70-FEFF, U+1EE00-1EEFF; -} - /* https://github.com/mattermost/mattermost/blob/master/webapp/channels/src/sass/base/_typography.scss */ body, .app__body.font--open_sans { font-family: VazirmatnNL, 'Open Sans', sans-serif !important;