<commit_before>var GitWatcher = require('./lib/GitWatcher'),
	Git = require('./lib/Git'),
	Highlighter = require('./lib/Highlighter'),
	baseRepoDirectory = null, 
	currentModulePath = null, 
	currentModuleName = null, 
	gitWatcher = null,
	appTray;
	
var gitErrHandler = require('domain').create();
gitErrHandler.on('error', function(err) {
	UI.showError(err);
});

function init() {
	initApp();
	
	baseRepoDirectory = gui.App.argv[0] || config.defaultRepository || null;
	
	if (!baseRepoDirectory && isValidRepository(process.env.PWD)) {
		openRepository(process.env.PWD);
	} else if (baseRepoDirectory) {
		openRepository(baseRepoDirectory);
	}
}

function initApp() {
	appTray = new gui.Tray({
		title: 'Git Watcher',
		icon: 'icons/git-watcher.png'
	});
	appTray.on('click', function(e) {
		gui.Window.get().focus();
	});
    
    $('#repositoryChooser').setAttribute('nwworkingdir', process.env.HOME);
	$('#repositoryChooser').addEventListener('change', function(e) {
		openRepository(this.value);
	}, false);
    
	AppMenus.init();
	
	gui.Window.get().on('close', function() {
		Config.save();
		this.close(true);
	});
}

function updateGlobalStatus() {
	gitWatcher.getStatus(function(err, status) {
		if (err) throw err;
		for (var module in status) {
			UI.updateModule(module, status[module]);
		}
	});
}

function updateCurrentModuleStatus() {
	log('Updating current module status...');
	gitWatcher.getModuleStatus(currentModuleName, function(err, status) {
		if (err) throw err;
		UI.updateModule(currentModuleName, status);
	});
}

function isValidRepository(path) {
    return require('fs').existsSync(require('path').join(path, '.git'));
}

function openRepository(repositoryPath) {
	closeRepository();
    
    if (!isValidRepository(repositoryPath)) {
        UI.showError('Invalid repository path given!\n\nPlease select a valid Git repository.');
        chooseRepository();
        return;
    }
    
	$('#loadingImage').classList.add('visible');
    
	baseRepoDirectory = repositoryPath;
    
	gitWatcher = new GitWatcher(repositoryPath);
	gitWatcher.on('change', function(status) {
		log('Event: change', status);
		UI.updateModule(status.module, status.status);
	});
	gitWatcher.on('error', function(err) {
		logError('Event: error', err);
		UI.showError(err);
		throw err;
	});
	gitWatcher.on('ready', function() {
		log('Event: ready');
		UI.load();
	});
	gitWatcher.init();
	
	AppMenus.enableRepoMenu(true);
	
	$('#main').classList.remove('empty');
}

function chooseRepository() {
    gui.Window.get().focus();
	$('#repositoryChooser').click();
}

function closeRepository() {
	if (baseRepoDirectory && gitWatcher !== null) {
		gitWatcher.close();
        gitWatcher.removeAllListeners();
		gitWatcher = null;
		baseRepoDirectory = null;
		
        AppMenus.enableRepoMenu(false);
		
		$$('.module').forEach(function(node) {
			node.parentNode.removeChild(node);
		});
		$('#gitModules').innerHTML = '';
        $('#main').classList.add('empty');
		$('#repositoryChooser').value = '';
	}
}

var UI = {
	load: function() {
		gitWatcher.getStatus(function(err, status) {
			if (err) throw err;
			log('Status:', status);
			$('#loadingImage').classList.remove('visible');
			var modules = gitWatcher.getModules();
			modules.forEach(function(module) {
				UI.createModule(module);
			});
			UI.showModule(modules[0]);
			for (var module in status) {
				UI.updateModule(module, status[module]);
			}
		});
	},
	
	showModule: function(moduleName) {<commit_msg>Show repository path in window title<commit_after>var GitWatcher = require('./lib/GitWatcher'),
	Git = require('./lib/Git'),
	Highlighter = require('./lib/Highlighter'),
	baseRepoDirectory = null, 
	currentModulePath = null, 
	currentModuleName = null, 
	gitWatcher = null,
	appTray;
	
var gitErrHandler = require('domain').create();
gitErrHandler.on('error', function(err) {
	UI.showError(err);
});

function init() {
	initApp();
	
	baseRepoDirectory = gui.App.argv[0] || config.defaultRepository || null;
	
	if (!baseRepoDirectory && isValidRepository(process.env.PWD)) {
		openRepository(process.env.PWD);
	} else if (baseRepoDirectory) {
		openRepository(baseRepoDirectory);
	}
}

function initApp() {
	appTray = new gui.Tray({
		title: 'Git Watcher',
		icon: 'icons/git-watcher.png'
	});
	appTray.on('click', function(e) {
		gui.Window.get().focus();
	});
    
    $('#repositoryChooser').setAttribute('nwworkingdir', process.env.HOME);
	$('#repositoryChooser').addEventListener('change', function(e) {
		openRepository(this.value);
	}, false);
    
	AppMenus.init();
	
	gui.Window.get().on('close', function() {
		Config.save();
		this.close(true);
	});
}

function updateGlobalStatus() {
	gitWatcher.getStatus(function(err, status) {
		if (err) throw err;
		for (var module in status) {
			UI.updateModule(module, status[module]);
		}
	});
}

function updateCurrentModuleStatus() {
	log('Updating current module status...');
	gitWatcher.getModuleStatus(currentModuleName, function(err, status) {
		if (err) throw err;
		UI.updateModule(currentModuleName, status);
	});
}

function isValidRepository(path) {
    return require('fs').existsSync(require('path').join(path, '.git'));
}

function openRepository(repositoryPath) {
	closeRepository();
    
    if (!isValidRepository(repositoryPath)) {
        UI.showError('Invalid repository path given!\n\nPlease select a valid Git repository.');
        chooseRepository();
        return;
    }
    
	$('#loadingImage').classList.add('visible');
    
	baseRepoDirectory = repositoryPath;
    
	gitWatcher = new GitWatcher(repositoryPath);
	gitWatcher.on('change', function(status) {
		log('Event: change', status);
		UI.updateModule(status.module, status.status);
	});
	gitWatcher.on('error', function(err) {
		logError('Event: error', err);
		UI.showError(err);
		throw err;
	});
	gitWatcher.on('ready', function() {
		log('Event: ready');
		UI.load();
	});
	gitWatcher.init();
	
	gui.Window.get().title = gui.App.manifest.window.title + ' :: ' + repositoryPath;
	AppMenus.enableRepoMenu(true);
	
	$('#main').classList.remove('empty');
}

function chooseRepository() {
    gui.Window.get().focus();
	$('#repositoryChooser').click();
}

function closeRepository() {
	if (baseRepoDirectory && gitWatcher !== null) {
		gitWatcher.close();
        gitWatcher.removeAllListeners();
		gitWatcher = null;
		baseRepoDirectory = null;
		
		gui.Window.get().title = gui.App.manifest.window.title;
        AppMenus.enableRepoMenu(false);
		
		$$('.module').forEach(function(node) {
			node.parentNode.removeChild(node);
		});
		$('#gitModules').innerHTML = '';
        $('#main').classList.add('empty');
		$('#repositoryChooser').value = '';
	}
}

var UI = {
	load: function() {
		gitWatcher.getStatus(function(err, status) {
			if (err) throw err;
			log('Status:', status);
			$('#loadingImage').classList.remove('visible');
			var modules = gitWatcher.getModules();
			modules.forEach(function(module) {
				UI.createModule(module);
			});
			UI.showModule(modules[0]);
			for (var module in status) {
				UI.updateModule(module, status[module]);
			}
		});
	},
	
	showModule: function(moduleName) {
{'fraction_non_alphanumeric': 0.1747545582047686, 'fraction_numerical': 0.0005610098176718093, 'mean_word_length': 4.456006120887529, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3027812', 'n_tokens_mistral': 2444, 'n_tokens_neox': 2327, 'n_words': 392}