import * as vscode from 'vscode' ; import { Plugin } from './plugin' ; import { ThemeConfig , getConfigValue } from './config/config' ; import { Particles } from './config/particles' ; import { Fireworks } from './config/fireworks' ; import { Flames } from './config/flames' ; import { Magic } from './config/magic' ; import { Clippy } from './config/clippy' ; import { SimpleRift , ExplodingRift } from './config/rift' ; import { ScreenShaker } from './screen-shaker/screen-shaker' ; import { CursorExploder } from './cursor-exploder/cursor-exploder' ; import { ProgressBarTimer } from './progress-bar-timer' ; import { StatusBarItem } from './status-bar-item' ; const DEFAULT_THEME_ID = 'particles' ; const DEFAULT_THEME_CONFIG = Particles ; let documentChangeListenerDisposer = null ; let enabled = false ; let comboThreshold ; let screenShaker ; let cursorExploder ; let statusBarItem ; let progressBarTimer ; let plugins = [ ] ; let themes = { fireworks : Fireworks , particles : Particles , flames : Flames , magic : Magic , clippy : Clippy , [ "simple-rift" ] : SimpleRift , [ "exploding-rift" ] : ExplodingRift , } ; let combo = 0 ; export function activate ( context ) { vscode . workspace . onDidChangeConfiguration ( onDidChangeConfiguration ) ; onDidChangeConfiguration ( ) ; } function init ( config , activeTheme ) { deactivate ( ) ; combo = 0 ; screenShaker = new ScreenShaker ( activeTheme ) , cursorExploder = new CursorExploder ( activeTheme ) , statusBarItem = new StatusBarItem ( ) ; progressBarTimer = new ProgressBarTimer ( onProgressTimerExpired ) ; plugins . push ( screenShaker , cursorExploder , statusBarItem , progressBarTimer ) ; plugins . forEach ( plugin => plugin . onDidChangeConfiguration ( config ) ) ; documentChangeListenerDisposer = vscode . workspace . onDidChangeTextDocument ( onDidChangeTextDocument ) ; } /**
 * Note: this method is also called automatically
 * when the extension is deactivated
 */ export function deactivate ( ) { combo = 0 ; if ( documentChangeListenerDisposer ) { documentChangeListenerDisposer . dispose ( ) ; documentChangeListenerDisposer = null ; } while ( plugins . length > 0 ) { plugins . shift ( ) . dispose ( ) ; } } function onDidChangeConfiguration ( ) { const config = vscode . workspace . getConfiguration ( 'powermode' ) ; const themeId = config . get < string > ( 'presets' ) ; const theme = getThemeConfig ( themeId ) ; const oldEnabled = enabled ; enabled = config . get < boolean > ( 'enabled' , false ) ; comboThreshold = config . get < number > ( 'comboThreshold' , 0 ) ; if ( ! oldEnabled && enabled ) { init ( config , theme ) ; return ; } if ( oldEnabled && ! enabled ) { deactivate ( ) ; return ; } if ( ! enabled ) { return ; } screenShaker . themeConfig = theme ; cursorExploder . themeConfig = theme ; plugins . forEach ( plugin => plugin . onDidChangeConfiguration ( config ) ) ; } function getThemeConfig ( themeId ) { return themes [ themeId ] ; } const onProgressTimerExpired = ( ) => { plugins . forEach ( plugin => plugin . onPowermodeStop ( combo ) ) ; combo = 0 ; } ; function isPowerMode ( ) { return enabled && combo >= comboThreshold ; } function onDidChangeTextDocument ( event ) { combo ++ ; const powermode = isPowerMode ( ) ; plugins . forEach ( plugin => plugin . onDidChangeTextDocument ( combo , powermode , event ) ) ; }