Skip to content

Commit

Permalink
2.5.0
Browse files Browse the repository at this point in the history
* Update Discord Rich Presence for operations
* Add link to live game on csgostats.gg
* Fix issues with the Snap package for Linux
* Update dependency versions
  • Loading branch information
CorySanin committed Dec 29, 2019
1 parent f9435fc commit 9bfd875
Show file tree
Hide file tree
Showing 7 changed files with 426 additions and 553 deletions.
11 changes: 11 additions & 0 deletions app.js
Expand Up @@ -516,6 +516,17 @@ ipc.on('show-kitten-dir', function(){
shell.openItem(state.audioDir)
}
})

ipc.on('open-csgostats', function(){
let steamid = server.getId();
if(steamid){
shell.openExternal(`https://csgostats.gg/player/${steamid}#/live`)
}
else{
shell.openExternal('https://csgostats.gg')
}
})

ipc.on('welcome-message-done', newAudioDir)

//executes when the selected directory dialog is completed
Expand Down
72 changes: 36 additions & 36 deletions gamestateIntegration.js
Expand Up @@ -6,13 +6,13 @@ const os = require('os')
const ipc = require('electron').ipcRenderer

const REG = 'SteamPath'
const WINSTEAMLIB = path.join('steamapps','libraryfolders.vdf')
const WINSTEAMLIB = path.join('steamapps', 'libraryfolders.vdf')
const GSIFILENAME = 'gamestate_integration_kitten.cfg'
const HOMEDIR = os.homedir()
const HOMEDIR = (process.env.SNAP) ? path.join('/home', process.env.USER) : os.homedir()

function saveConfig(config){
function saveConfig(config) {
let cfg = VDF.stringify({
'Kitten State API Config':{
'Kitten State API Config': {
'uri': config.url,
'timeout': 5.0,
'buffer': 0.1,
Expand All @@ -27,22 +27,22 @@ function saveConfig(config){
}
}
})
getCSGOPath(function(pth){
getCSGOPath(function (pth) {
fs.writeFile(path.join(pth, GSIFILENAME), cfg)
if(os.platform() === 'win32'){
if (os.platform() === 'win32') {
ipc.send('csgoicon', path.resolve(pth, '..', '..', 'csgo.exe'))
}
})
}

function getCSGOPath(cb){
getLibraryFoldersVDFPath(function(vdfPath){
getLibraryFolders(vdfPath,function(libraries){
libraries.push(path.join(path.dirname(vdfPath),'common'))
libraries.forEach(function(pth,index){
function getCSGOPath(cb) {
getLibraryFoldersVDFPath(function (vdfPath) {
getLibraryFolders(vdfPath, function (libraries) {
libraries.push(path.join(path.dirname(vdfPath), 'common'))
libraries.forEach(function (pth, index) {
let cfgPath = path.join(pth, 'Counter-Strike Global Offensive', 'csgo', 'cfg')
fs.pathExists(cfgPath , function(err, exists){
if(!err && exists){
fs.pathExists(cfgPath, function (err, exists) {
if (!err && exists) {
cb(cfgPath)
}
})
Expand All @@ -51,61 +51,61 @@ function getCSGOPath(cb){
})
}

function getLibraryFoldersVDFPath(cb=function(){}){
if(os.platform() === 'win32'){
function getLibraryFoldersVDFPath(cb = function () { }) {
if (os.platform() === 'win32') {
//look at HKEY_CURRENT_USER\Software\Valve\Steam
let regKey = new Registry({
hive: Registry.HKCU, // open registry hive HKEY_CURRENT_USER
key: '\\Software\\Valve\\Steam'
key: '\\Software\\Valve\\Steam'
})
regKey.values(function (err, items) {
let r = false
if (err){
console.log('ERROR: '+err)
if (err) {
console.log('ERROR: ' + err)
}
else{
for (var i=0; i<items.length && !r; i++){
if(items[i].name === REG){
r = path.join(items[i].value,WINSTEAMLIB)
else {
for (var i = 0; i < items.length && !r; i++) {
if (items[i].name === REG) {
r = path.join(items[i].value, WINSTEAMLIB)
}
}
}
cb(r)
})
}
else{
else {
let vdfpath
if(os.platform() === 'darwin'){
vdfpath = path.join(HOMEDIR,'Library/Application Support/Steam/steamapps/libraryfolders.vdf')
if (os.platform() === 'darwin') {
vdfpath = path.join(HOMEDIR, 'Library/Application Support/Steam/steamapps/libraryfolders.vdf')
}
else{
vdfpath = path.join(HOMEDIR,'.local/share/Steam/steamapps/libraryfolders.vdf')
else {
vdfpath = path.join(HOMEDIR, '.local/share/Steam/steamapps/libraryfolders.vdf')
}
cb(vdfpath)
return vdfpath
}
}

function getLibraryFolders(vdfPath,cb){
function getLibraryFolders(vdfPath, cb) {
let folders = []
try{
fs.readFile(vdfPath,{encoding:'utf8'},function(err,data){
if(!err){
try {
fs.readFile(vdfPath, { encoding: 'utf8' }, function (err, data) {
if (!err) {
let vdfdata = VDF.parse(data)
if('LibraryFolders' in vdfdata){
if ('LibraryFolders' in vdfdata) {
vdfdata = vdfdata['LibraryFolders']
let key
for(key in vdfdata){
if(!isNaN(key)){
folders.push(path.join(vdfdata[key],'steamapps','common'))
for (key in vdfdata) {
if (!isNaN(key)) {
folders.push(path.join(vdfdata[key], 'steamapps', 'common'))
}
}
}
}
cb(folders)
})
}
catch(err){
catch (err) {
cb(folders)
}
}
Expand Down
3 changes: 2 additions & 1 deletion locales/en-US/translation.json
Expand Up @@ -42,6 +42,7 @@
"misc":{
"launchgame": "Launch CS:GO",
"openkittendir": "Open Kitten Folder",
"devtools": "Developer Tools"
"devtools": "Developer Tools",
"csgostats": "Current Game on CS:GO Stats"
}
}
64 changes: 40 additions & 24 deletions main.js
Expand Up @@ -18,12 +18,14 @@ const launchcsgo = 'steam://rungameid/730'
let mainWindow
let _

function createWindow () {
function createWindow() {
// Create the browser window.
mainWindow = new BrowserWindow({backgroundColor: '#212121',
width: 380, height: 575, resizable: false, maximizable: false, fullscreenable:false,
frame: os.platform() !== 'win32', titleBarStyle: 'hiddenInset',
icon:path.join(__dirname,'icon',(os.platform() == 'win32')?'icon.ico':'icon_512.png')})
mainWindow = new BrowserWindow({
backgroundColor: '#212121',
width: 380, height: 575, resizable: false, maximizable: false, fullscreenable: false,
frame: os.platform() !== 'win32', titleBarStyle: 'hiddenInset',
icon: path.join(__dirname, 'icon', (os.platform() == 'win32') ? 'icon.ico' : 'icon_512.png')
})

// and load the index.html of the app.
mainWindow.loadURL(url.format({
Expand All @@ -49,18 +51,32 @@ function createWindow () {
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', function(){
app.on('ready', function () {
autoUpdater.checkForUpdatesAndNotify()
_ = i18n.translate(app.getLocale())
menu.append(new electron.MenuItem({ label: 'Kitten [$VERSION$]',
enabled: false}))
menu.append(new electron.MenuItem({ label: _('misc.launchgame'),
click: function(){electron.shell.openExternal(launchcsgo)}}))
menu.append(new electron.MenuItem({ label: _('misc.openkittendir'),
click: function(){mainWindow.webContents.send('show-kitten-dir')}}))
menu.append(new electron.MenuItem({ label: _('misc.devtools'),
click: function(){mainWindow.webContents.openDevTools()}}))
if(os.platform() === 'win32'){
menu.append(new electron.MenuItem({
label: _('misc.openkittendir'),
click: function () { mainWindow.webContents.send('show-kitten-dir') }
}))
menu.append(new electron.MenuItem({
label: _('misc.csgostats'),
click: function () { mainWindow.webContents.send('open-csgostats') }
}))
if (!process.env.SNAP) {
menu.append(new electron.MenuItem({
label: _('misc.launchgame'),
click: function () { electron.shell.openExternal(launchcsgo) }
}))
}
menu.append(new electron.MenuItem({
label: _('misc.devtools'),
click: function () { mainWindow.webContents.openDevTools() }
}))
menu.append(new electron.MenuItem({
label: 'Kitten [$VERSION$]',
enabled: false
}))
if (os.platform() === 'win32') {
app.setUserTasks([]) //why does it need to be initialized first???
}
createWindow()
Expand Down Expand Up @@ -94,7 +110,7 @@ ipc.on('show-context-menu', function (event) {
menu.popup(win)
})

ipc.on('open-kitten-dir', function (event, callback){
ipc.on('open-kitten-dir', function (event, callback) {
electron.dialog.showOpenDialog({
properties: ['openDirectory']
}, function (files) {
Expand All @@ -115,7 +131,7 @@ ipc.on('dialog', function (event, message, title, response = false) {
buttons: [_('dialog.ok')]
}
electron.dialog.showMessageBox(mainWindow, options, function (index) {
if(response){
if (response) {
event.sender.send(response, index)
}
})
Expand All @@ -135,17 +151,17 @@ ipc.on('yes-no', function (event, message, title, response) {

ipc.on('resize', function (event, args) {
let dim = mainWindow.getSize()
let width = ('width' in args)?args.width:dim[0]
let height = ('height' in args)?args.height:dim[1]
let width = ('width' in args) ? args.width : dim[0]
let height = ('height' in args) ? args.height : dim[1]
mainWindow.setSize(width, height, true)
})

ipc.on('lang', function (event) {
event.sender.send('lang', app.getLocale())
})

ipc.on('csgoicon', function (event, exepath){
if(os.platform() === 'win32'){
ipc.on('csgoicon', function (event, exepath) {
if (os.platform() === 'win32') {
app.setUserTasks([
{
type: 'task',
Expand All @@ -159,12 +175,12 @@ ipc.on('csgoicon', function (event, exepath){
}
})

ipc.on('inviteUrl', function (event, steamid){
request('https://steamcommunity.com/profiles/' + steamid, function(err, resp, body){
ipc.on('inviteUrl', function (event, steamid) {
request('https://steamcommunity.com/profiles/' + steamid, function (err, resp, body) {
if (!err && resp.statusCode === 200) {
let dom = new JSDOM(body, { runScripts: "outside-only" })
let joinBtn = dom.window.document.querySelector('.profile_in_game_joingame a');
event.sender.send('inviteUrl', (joinBtn !== null)?joinBtn.href:'')
event.sender.send('inviteUrl', (joinBtn !== null) ? joinBtn.href : '')
}
})
})

0 comments on commit 9bfd875

Please sign in to comment.