import { ApplicationImpl , DatetimeProjectItemImpl , ElectronExecutor , Group , GroupName , Platform } from '../../../Types' ; import { BrowserId , getDefaultConfigPath , SqliteBrowserApplicationImpl } from '../index' ; import { execFileSync } from 'child_process' ; import { isEmpty , unique } from 'licia' ; import { removeAllQueryFromUrl } from '../../../Utils' ; import { Context } from '../../../Context' ; import { i18n , sentenceKey } from '../../../i18n' ; import { generatePinyinIndex } from '../../../utils/index-generator/PinyinIndex' ; import { generateHostIndex } from '../../../utils/index-generator/HostIndex' ; import { parseSqliteDefaultResult } from '../../../utils/sqlite/ParseResult' ; const CHROMIUM = 'chromium' ; const configName = 'History' ; const handler = text => `${ configName } ${ i18n . t ( sentenceKey . browserPathDescPrefix ) } ${ text }` ; export class ChromiumHistoryProjectItemImpl extends DatetimeProjectItemImpl { } export class ChromiumHistoryApplicationImpl extends SqliteBrowserApplicationImpl < ChromiumHistoryProjectItemImpl > { private readonly browserId : BrowserId ; constructor ( id , name , type , platforms = [ Platform . win32 , Platform . darwin , Platform . linux ] , description = true , beta = false , configName = '' ) { super ( `${ id }-history` , `${ name }` , `icon/browser-${ id }.png` , type , platforms , Group [ GroupName . browserHistory ] , description ? ( ) => handler ( this . defaultConfigPath ( ) ) : undefined , beta , configName ) ; this . browserId = id ; } override defaultConfigPath ( ) { return `${ getDefaultConfigPath ( this . browserId ) }${ configName }` ; } async generateCacheProjectItems ( context ) { let items = [ ] ; let sql = 'select v.id                                                                                                        as id,\n       u.url                                                                                                       as url,\n       u.title                                                                                                     as title,\n       cast(strftime(\'%s\', datetime((v.visit_time / 1000000) - 11644473600, \'unixepoch\',\n                                    \'localtime\')) as numeric)                                                      as timestamp\nfrom visits v\n         left join urls u on v.url = u.id\nwhere v.visit_time is not null\n  and v.url is not null\n  and v.visit_duration != 0\ngroup by u.last_visit_time\norder by timestamp desc\nlimit ' + context . browserHistoryLimit ; let result = '' ; await this . copyAndReadFile ( this . config , path => { result = execFileSync ( this . executor , [ path , sql , '-readonly' ] , { encoding : 'utf-8' , maxBuffer : 20971520 } ) ; } ) ; if ( ! isEmpty ( result ) ) { let array = parseSqliteDefaultResult ( result , [ 'n/id' , 'url' , 'title' , 'n/timestamp' ] ) ; array . forEach ( i => { let title = i [ 'title' ] ?? '' ; let url = i [ 'url' ] ?? '' ; items . push ( { id : '' , title : title , description : url , icon : this . ifGetFavicon ( removeAllQueryFromUrl ( url ) , context ) , searchKey : unique ( [ ... generatePinyinIndex ( context , title ) , ... generateHostIndex ( context , url ) , title , ] ) , exists : true , command : new ElectronExecutor ( url ) , datetime : i [ 'timestamp' ] ?? 0 , } ) ; } ) ; } return items ; } } export const applications = [ new ChromiumHistoryApplicationImpl ( 'chromium' , 'Chromium' , CHROMIUM , undefined , false , undefined , configName ) , new ChromiumHistoryApplicationImpl ( 'chrome' , 'Google Chrome' , CHROMIUM , undefined , false , undefined , configName ) , new ChromiumHistoryApplicationImpl ( 'edge' , 'Microsoft Edge' , CHROMIUM , undefined , false , undefined , configName ) , new ChromiumHistoryApplicationImpl ( 'qq' , 'QQ Browser' , CHROMIUM , [ Platform . win32 ] , false , undefined , configName ) , new ChromiumHistoryApplicationImpl ( 'maxthon' , 'Maxthon (傲游)' , CHROMIUM , [ Platform . win32 ] , false , undefined , configName ) , new ChromiumHistoryApplicationImpl ( 'opera' , 'Opera' , CHROMIUM , undefined , false , undefined , configName ) , new ChromiumHistoryApplicationImpl ( 'brave' , 'Brave' , CHROMIUM , undefined , false , undefined , configName ) , new ChromiumHistoryApplicationImpl ( 'vivaldi' , 'Vivaldi' , CHROMIUM , undefined , false , undefined , configName ) , new ChromiumHistoryApplicationImpl ( 'cent' , 'CentBrowser (百分)' , CHROMIUM , [ Platform . win32 ] , false , undefined , configName ) , new ChromiumHistoryApplicationImpl ( 'yandex' , 'Yandex' , CHROMIUM , undefined , false , undefined , configName ) , new ChromiumHistoryApplicationImpl ( 'liebao' , '猎豹浏览器' , CHROMIUM , [ Platform . win32 ] , false , undefined , configName ) , new ChromiumHistoryApplicationImpl ( 'deepin' , '深度浏览器' , CHROMIUM , [ Platform . linux ] , false , undefined , configName ) , ] ;