- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.6k
feat(plugin): add font-customizer plugin #3785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            kev2block
  wants to merge
  11
  commits into
  pear-devs:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
kev2block:master
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from 8 commits
      Commits
    
    
            Show all changes
          
          
            11 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      c8d8dc3
              
                Create index.ts
              
              
                kev2block 215d46c
              
                Add files via upload
              
              
                kev2block 3796b89
              
                Delete src/plugins/src directory
              
              
                kev2block 96dad03
              
                Create font-customizer
              
              
                kev2block 3dc8b51
              
                Delete src/plugins/font-customizer
              
              
                kev2block 4460b02
              
                Create 1
              
              
                kev2block 5d78f70
              
                Add files via upload
              
              
                kev2block 0b2c3ec
              
                Delete src/plugins/font-customizer/1
              
              
                kev2block 4e18f81
              
                Add files via upload
              
              
                kev2block 7d2a9f1
              
                Refactor font menu logic for clarity and structure
              
              
                kev2block 8bae779
              
                Remove ensureScopedStyles function
              
              
                kev2block File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or 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,29 @@ | ||
| import { createPlugin } from '@/utils'; | ||
|  | ||
| import { menu } from './menu'; | ||
| import { renderer } from './renderer'; | ||
|  | ||
| import type { FontCustomizerConfig } from './types'; | ||
|  | ||
| const defaultConfig: FontCustomizerConfig = { | ||
| enabled: true, | ||
| mode: 'simple', | ||
| globalFont: 'System Default', | ||
| primaryFont: 'System Default', | ||
| headerFont: 'System Default', | ||
| titleFont: 'System Default', | ||
| artistFont: 'System Default', | ||
| lyricsFont: 'System Default', | ||
| menuFont: 'System Default', | ||
| customFonts: [], | ||
| }; | ||
|  | ||
| export default createPlugin({ | ||
| name: () => 'Font Customizer', | ||
| description: () => | ||
| 'Change fonts globally or specifically for song title, artist, lyrics, and navigation menu. Uses Google Fonts.', | ||
| restartNeeded: false, | ||
| config: defaultConfig, | ||
| menu, | ||
| renderer, | ||
| }); | 
  
    
      This file contains hidden or 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,170 @@ | ||
| import { popularFonts } from './types'; | ||
|  | ||
| import prompt from 'custom-electron-prompt'; | ||
| import promptOptions from '@/providers/prompt-options'; | ||
|  | ||
| import type { MenuItemConstructorOptions } from 'electron'; | ||
|  | ||
| import type { MenuContext } from '@/types/contexts'; | ||
|  | ||
| import type { FontCustomizerConfig } from './types'; | ||
|  | ||
| const toRadio = ( | ||
| current: string, | ||
| label: string, | ||
| click: (value: string) => void, | ||
| ): MenuItemConstructorOptions => ({ | ||
| label, | ||
| type: 'radio', | ||
| checked: current === label, | ||
| click: () => click(label), | ||
| }); | ||
|  | ||
| export const menu = async ({ | ||
| getConfig, | ||
| setConfig, | ||
| window, | ||
| refresh, | ||
| }: MenuContext<FontCustomizerConfig>): Promise< | ||
| MenuItemConstructorOptions[] | ||
| > => { | ||
| const cfg = await getConfig(); | ||
|  | ||
| const allFonts = [...new Set([ | ||
| 'System Default', | ||
| ...popularFonts.filter((f) => f !== 'System Default'), | ||
| ...(cfg.customFonts || []), | ||
| ])]; | ||
|  | ||
| const section = ( | ||
| title: string, | ||
| current: string, | ||
| onPick: (value: string) => void, | ||
| ): MenuItemConstructorOptions => ({ | ||
| label: title, | ||
| submenu: allFonts.map((f) => toRadio(current, f, onPick)), | ||
| }); | ||
|  | ||
| const createFontPicker = ( | ||
| label: string, | ||
| fontType: keyof FontCustomizerConfig, | ||
| ): MenuItemConstructorOptions => ({ | ||
| label, | ||
| type: 'normal', | ||
| enabled: cfg.enabled, | ||
| click: async () => { | ||
| const currentConfig = await getConfig(); | ||
| const newFont = await prompt( | ||
| { | ||
| title: `${label.replace('Pick ', '').replace('…', '')}`, | ||
| label: 'Enter a Google Font family name:', | ||
| type: 'input', | ||
| value: currentConfig[fontType] as string, | ||
| ...promptOptions(), | ||
| }, | ||
| window!, | ||
| ); | ||
|  | ||
| if (newFont && newFont.trim()) { | ||
| const trimmedFont = newFont.trim(); | ||
| const customFonts = currentConfig.customFonts || []; | ||
| const isNew = !popularFonts.includes(trimmedFont) && !customFonts.includes(trimmedFont); | ||
|  | ||
| const newConfig: Partial<FontCustomizerConfig> = { [fontType]: trimmedFont }; | ||
| if (isNew) { | ||
| newConfig.customFonts = [...customFonts, trimmedFont]; | ||
| } | ||
|  | ||
| await setConfig(newConfig); | ||
| refresh?.(); | ||
| } | ||
| }, | ||
| }); | ||
|  | ||
| return [ | ||
| { | ||
| label: 'Mode', | ||
| submenu: [ | ||
| { | ||
| label: 'Simple (Global)', | ||
| type: 'radio', | ||
| checked: cfg.mode === 'simple', | ||
| click: async () => { | ||
| await setConfig({ mode: 'simple' }); | ||
| try { window?.webContents.send('close-all-in-app-menu-panel'); } catch {} | ||
| setTimeout(() => refresh?.(), 100); | ||
| }, | ||
| }, | ||
| { | ||
| label: 'Advanced (Per section)', | ||
| type: 'radio', | ||
| checked: cfg.mode === 'advanced', | ||
| click: async () => { | ||
| await setConfig({ mode: 'advanced' }); | ||
| try { window?.webContents.send('close-all-in-app-menu-panel'); } catch {} | ||
| setTimeout(() => refresh?.(), 100); | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| { type: 'separator' }, | ||
| // Simple mode | ||
| { | ||
| ...createFontPicker('Pick global font…', 'globalFont'), | ||
| visible: cfg.mode === 'simple', | ||
| }, | ||
| { | ||
| ...section('Global font', cfg.globalFont, (value) => setConfig({ globalFont: value })), | ||
| visible: cfg.mode === 'simple', | ||
| }, | ||
| // Advanced mode | ||
| { | ||
| ...createFontPicker('Pick primary UI font…', 'primaryFont'), | ||
| visible: cfg.mode === 'advanced', | ||
| }, | ||
| { | ||
| ...section('Primary UI font', cfg.primaryFont, (value) => setConfig({ primaryFont: value })), | ||
| visible: cfg.mode === 'advanced', | ||
| }, | ||
| { | ||
| ...createFontPicker('Pick header font…', 'headerFont'), | ||
| visible: cfg.mode === 'advanced', | ||
| }, | ||
| { | ||
| ...section('Header font', cfg.headerFont, (value) => setConfig({ headerFont: value })), | ||
| visible: cfg.mode === 'advanced', | ||
| }, | ||
| { | ||
| ...createFontPicker('Pick title font…', 'titleFont'), | ||
| visible: cfg.mode === 'advanced', | ||
| }, | ||
| { | ||
| ...section('Title font', cfg.titleFont, (value) => setConfig({ titleFont: value })), | ||
| visible: cfg.mode === 'advanced', | ||
| }, | ||
| { | ||
| ...createFontPicker('Pick artist font…', 'artistFont'), | ||
| visible: cfg.mode === 'advanced', | ||
| }, | ||
| { | ||
| ...section('Artist font', cfg.artistFont, (value) => setConfig({ artistFont: value })), | ||
| visible: cfg.mode === 'advanced', | ||
| }, | ||
| { | ||
| ...createFontPicker('Pick lyrics font…', 'lyricsFont'), | ||
| visible: cfg.mode === 'advanced', | ||
| }, | ||
| { | ||
| ...section('Lyrics font', cfg.lyricsFont, (value) => setConfig({ lyricsFont: value })), | ||
| visible: cfg.mode === 'advanced', | ||
| }, | ||
| { | ||
| ...createFontPicker('Pick menu font…', 'menuFont'), | ||
| visible: cfg.mode === 'advanced', | ||
| }, | ||
| { | ||
| ...section('Menu font', cfg.menuFont, (value) => setConfig({ menuFont: value })), | ||
| visible: cfg.mode === 'advanced', | ||
| }, | ||
| ]; | ||
| }; | ||
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.