import { Application , ApplicationCacheConfigAndExecutorImpl , ApplicationImpl , DatetimeProjectItemImpl , DescriptionGetter , Group , GroupName , NohupShellExecutor , Platform , } from '../../Types' ; import { readFile } from 'fs/promises' ; import { isEmpty , isNil , unique } from 'licia' ; import { parse } from 'path' ; import { existsOrNot } from '../../Utils' ; import { Context } from '../../Context' ; import { generatePinyinIndex } from '../../utils/index-generator/PinyinIndex' ; const JETBRAINS = 'jetbrains' ; export class JetBrainsProjectItemImpl extends DatetimeProjectItemImpl { } /**
 * JetBrains 系列应用实现
 */ export class JetBrainsApplicationImpl extends ApplicationCacheConfigAndExecutorImpl < JetBrainsProjectItemImpl > { constructor ( id , name , icon , platform = [ Platform . win32 , Platform . darwin , Platform . linux ] , description = '' , beta = false , configFilename = 'recentProject.xml' ) { super ( id , name , icon , JETBRAINS , platform , Group [ GroupName . jetbrains ] , description , beta , configFilename ) ; } override defaultConfigPath ( ) { return '' ; } override defaultExecutorPath ( ) { return '' ; } async generateCacheProjectItems ( context ) { let items = [ ] ; let buffer = await readFile ( this . config ) ; if ( ! isNil ( buffer ) ) { let content = buffer . toString ( ) ; let domParser = new DOMParser ( ) . parseFromString ( content , 'application/xml' ) ; domParser . querySelectorAll ( 'application option[name=additionalInfo] entry' ) . forEach ( ( element , index ) => { let path = element . getAttribute ( 'key' ) ?? '' ; let datetime = element . querySelector ( 'option[name=projectOpenTimestamp]' ) ?. getAttribute ( 'value' ) ?? 0 ; if ( ! isEmpty ( path ) ) { path = path . replace ( '$USER_HOME$' , utools . getPath ( 'home' ) ) ; let parseObj = parse ( path ) ; let { exists , description , icon } = existsOrNot ( path , { description : path , icon : this . icon , } ) ; items . push ( { id : '' , title : parseObj . name , description : description , icon : icon , searchKey : unique ( [ ... generatePinyinIndex ( context , parseObj . name ) , parseObj . name , path ] ) , exists : exists , command : new NohupShellExecutor ( this . executor , path ) , datetime : parseInt ( `${ datetime }` ) , } ) ; } } ) ; } return items ; } } export const applications = [ new JetBrainsApplicationImpl ( 'android' , 'Android Studio' , 'icon/jetbrains-android.png' ) , new JetBrainsApplicationImpl ( 'appcode' , 'AppCode' , 'icon/jetbrains-appcode.png' , [ Platform . darwin ] ) , new JetBrainsApplicationImpl ( 'clion' , 'CLion' , 'icon/jetbrains-clion.png' ) , new JetBrainsApplicationImpl ( 'datagrip' , 'DataGrip' , 'icon/jetbrains-datagrip.png' ) , new JetBrainsApplicationImpl ( 'goland' , 'GoLand' , 'icon/jetbrains-goland.png' ) , new JetBrainsApplicationImpl ( 'idea' , 'Intellij IDEA Ultimate' , 'icon/jetbrains-idea.png' ) , new JetBrainsApplicationImpl ( 'idea-ce' , 'Intellij IDEA Community Edition' , 'icon/jetbrains-idea-ce.png' ) , new JetBrainsApplicationImpl ( 'idea-edu' , 'Intellij IDEA Edu' , 'icon/jetbrains-idea-edu.png' ) , new JetBrainsApplicationImpl ( 'mps' , 'MPS' , 'icon/jetbrains-mps.png' ) , new JetBrainsApplicationImpl ( 'phpstorm' , 'PhpStorm' , 'icon/jetbrains-phpstorm.png' ) , new JetBrainsApplicationImpl ( 'pycharm' , 'PyCharm Professional' , 'icon/jetbrains-pycharm.png' ) , new JetBrainsApplicationImpl ( 'pycharm-ce' , 'PyCharm Community' , 'icon/jetbrains-pycharm-ce.png' ) , new JetBrainsApplicationImpl ( 'pycharm-edu' , 'PyCharm Edu' , 'icon/jetbrains-pycharm-edu.png' ) , new JetBrainsApplicationImpl ( 'rider' , 'Rider' , 'icon/jetbrains-rider.png' , undefined , undefined , undefined , 'recentSolution.xml' ) , new JetBrainsApplicationImpl ( 'rubymine' , 'RubyMine' , 'icon/jetbrains-rubymine.png' ) , new JetBrainsApplicationImpl ( 'webstorm' , 'WebStorm' , 'icon/jetbrains-webstorm.png' ) , ] ;