Skip to content

Commit

Permalink
Temporary fix #19
Browse files Browse the repository at this point in the history
  • Loading branch information
olrenso committed Mar 20, 2023
1 parent 11f9aca commit 67f43e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App, Setting, PluginSettingTab, normalizePath } from 'obsidian'
import { App, Setting, PluginSettingTab, normalizePath, Platform } from 'obsidian'
import type HomeTab from './main'
import iconSuggester from './suggester/iconSuggester'
import { lucideIcons, type LucideIcon } from './utils/lucideIcons'
Expand All @@ -8,6 +8,7 @@ import isLink from './utils/isLink'
import fontSuggester from './suggester/fontSuggester'
import type { recentFileStored } from './recentFiles'
import type { starredFileStore } from './starredFiles'
import { checkFont } from './utils/fontValidator'

type ColorChoices = 'default' | 'accentColor' | 'custom'
type LogoChoiches = 'default' | 'imagePath' | 'imageLink' | 'lucideIcon' | 'none'
Expand Down Expand Up @@ -379,11 +380,19 @@ export class HomeTabSettingTab extends PluginSettingTab{
titleFontSettings.descEl.parentElement?.addClass('compressed')

if(this.plugin.settings.customFont === 'custom'){
let invalidFontIcon: HTMLElement
titleFontSettings
.addExtraButton((button) => {button
.setIcon('alert-circle')
.setTooltip('The font is not valid.')
invalidFontIcon = button.extraSettingsEl
invalidFontIcon.toggleVisibility(false)
invalidFontIcon.addClass('mod-warning')})

titleFontSettings.addSearch((text) => {
text.setValue(this.plugin.settings.font ? this.plugin.settings.font.replace(/"/g, ''): '')
text.setPlaceholder('Type anything ... ')
const isMobile = this.app.isMobile
const suggester: fontSuggester | undefined = isMobile ? undefined : new fontSuggester(this.app, text.inputEl, {
const suggester: fontSuggester | undefined = Platform.isMobile || Platform.isMacOS ? undefined : new fontSuggester(this.app, text.inputEl, {
isScrollable: true,
style: `max-height: 200px;
width: fit-content;
Expand All @@ -392,12 +401,15 @@ export class HomeTabSettingTab extends PluginSettingTab{

text.onChange(async (value) => {
value = value.indexOf(' ') >= 0 ? `"${value}"` : value //Restore "" if font name contains whitespaces
if(isMobile || suggester && (await suggester.getInstalledFonts()).includes(value)){
if((suggester && (await suggester.getInstalledFonts()).includes(value)) || checkFont(value) ){
this.plugin.settings.font = value
this.plugin.saveSettings()
invalidFontIcon.toggleVisibility(false)
}
else{
invalidFontIcon.toggleVisibility(true)
}
})

.inputEl.parentElement?.addClass('wide-input-container')
})
}
Expand Down
4 changes: 4 additions & 0 deletions src/utils/fontValidator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function checkFont(font: string, size?: number): boolean{
if(font.trim().length == 0) return false
return document.fonts.check(`${size ?? 18}px ${font}`)
}

0 comments on commit 67f43e2

Please sign in to comment.