Skip to content
This repository has been archived by the owner on Feb 26, 2021. It is now read-only.

Commit

Permalink
fixed breaking if/return statement
Browse files Browse the repository at this point in the history
  • Loading branch information
lonkaars committed Jul 24, 2020
1 parent 2a9d3e8 commit 33d78ce
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 58 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ server.on('message', data => {

ipcMain.on('serverRestart', () => {
server.kill();
server = cp.fork(__dirname + '/server/index.js');
server = cp.fork(__dirname + '/server/index.js', {stdio: 'pipe'});
server.on('message', data => {
var formatted = formatTermData(data);

Expand All @@ -122,4 +122,4 @@ ipcMain.on('serverRestart', () => {

function formatTermData(data) {
return `${chalk.gray(`[${new Date().toLocaleTimeString('nl')}] `)}${data}\n\r`
}
}
17 changes: 9 additions & 8 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@ var express = require('express'),
writefile = util.promisify(fs.writeFile),
allApps = fs.readdirSync(__dirname + '/user/palettes'),
c = require('chalk'),
chalk = new c.Instance({
level: 1
}),
chalk = new c.Instance({ level: 1 }),
tiles = [],
oldProcess: any = {};

// debugging server outside electron
if(typeof process.send == "undefined") process.send = console.log;

Array.prototype["isIn"] = function(item: string) {
var returnVal = false
this.forEach((i: string) => {
if (i.toLowerCase().includes(item.toLowerCase())) {
returnVal = true;
}
if (i.toLowerCase().includes(item.toLowerCase())) returnVal = true;
});
return returnVal;
}
Expand Down Expand Up @@ -85,12 +84,13 @@ io.on('connection', async (socket: any) => {
});
});

expressApp.use(express.static(path.join(__dirname, '/../')));

expressApp.use(express.static(path.join(__dirname, '..')));
expressApp.all("/", (request: any, response: any) => {
response.sendFile(path.join(__dirname, '../client/index.html'));
});

var errorcatch = (err: any) => process.send(JSON.stringify(err));
var errorcatch = err => process.send(JSON.stringify(err))
process.on('uncaughtException', err => errorcatch(err));
process.on('warning', err => errorcatch(err));
process.on('unhandledRejection', err => errorcatch(err));
Expand All @@ -99,3 +99,4 @@ server.on('listening', () => {
process.send(chalk.blue(chalk.bold(`Server started on *:${config.serverPort}`)));
});
server.listen(config.serverPort);

86 changes: 39 additions & 47 deletions src/server/processMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
var exeicon: any, linuxDesktop: any;
let exeicon: any, linuxDesktop: any;
switch (process.platform) {
case 'win32':
case 'win32': {
exeicon = require('icon256').extractIconAsync;
}

case 'linux':
case 'linux': {
linuxDesktop = require('linux-desktop');
linuxDesktop.indexItems();
linuxDesktop.indexItems();
}
}
var activeWin = require('active-win');
var fs = require('fs');
Expand All @@ -18,7 +20,7 @@ var readdir = util.promisify(fs.readdir);
var path = require('path');
var emptyPng = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";

module.exports.getCurrentProcess = async function(oldApp) {
module.exports.getCurrentProcess = async function(oldApp: any) {
var returnObj: any = {};
var win: any = await activeWin();
var readCachedIcon: boolean = false;
Expand All @@ -35,63 +37,53 @@ module.exports.getCurrentProcess = async function(oldApp) {
if (String(i).toLowerCase().includes(String(returnObj.name).toLowerCase())) readCachedIcon = true;
})

console.time("switch")
switch (process.platform) {
case 'win32':
case 'win32': {
returnObj.name = win.owner.name.slice(0, -4);
if (!readCachedIcon && !noIcon) returnObj.icon = {
data: await exeicon(returnObj.executable),
type: 'png'
if (!readCachedIcon && !noIcon) returnObj.icon = {
data: await exeicon(returnObj.executable),
type: 'png'
}
break;
}
break;

case 'linux':
console.time("findDesktopEntry")
var desktopEntry: any = linuxDesktop.findByExacutable(returnObj.executable);
console.timeEnd("findDesktopEntry")
if (!desktopEntry) {
var p: string[] = returnObj.executable.split('/')
desktopEntry = linuxDesktop.findByCommand(p[p.length - 1])
} else {
console.time("refineEntry")
var desktopFile: any = linuxDesktop.refineEntry(desktopEntry);
console.timeEnd("refineEntry")
returnObj.name = desktopFile.Name;
var filetype: any = String(desktopFile.Icon).match(/^(.+\.)(.+)$/)[2];
/* console.log(desktopFile.Icon) */
if (!readCachedIcon && !noIcon) returnObj.icon = {
data: await readfile(desktopFile.Icon, "base64"),
type: filetype
};
case 'linux': {
var desktopEntry: any = linuxDesktop.findByExacutable(returnObj.executable);
if (!desktopEntry) {
var p: string[] = returnObj.executable.split('/')
desktopEntry = linuxDesktop.findByCommand(p[p.length - 1])
} else {
// refineEntry is really slow
var desktopFile: any = linuxDesktop.refineEntry(desktopEntry);
returnObj.name = desktopFile.Name;
var filetype: any = String(desktopFile.Icon).match(/^(.+\.)(.+)$/)[2];
if (!readCachedIcon && !noIcon) returnObj.icon = {
data: await readfile(desktopFile.Icon, "base64"),
type: filetype
};
}
break;
}
break;
}
console.timeEnd("switch")

// findDesktopEntry: 0.038ms
// refineEntry: 1679.093ms
// switch: 1679.285ms
// readCachedIcon: true
// noIcon: true

// WYYYYYYYYY >:(((

console.log(`readCachedIcon: ${readCachedIcon}\nnoIcon: ${noIcon}`)
if (readCachedIcon && !noIcon) {
var location: string = __dirname.replace(/\\/g, "/") + "/user/palettes/" + returnObj.name
var files: string[] = await readdir(location)
var iconFile: any = files.find(f => f.includes('icon')).match(/^(.+\.)(.+)$/);
returnObj.icon = {
data: await readfile(path.join(location, iconFile[0]), "base64"),
type: iconFile[2]
};
} else /* if(!allApps.includes(returnObj.name)) */ {
// temp fix n.2
var iconIndex: any = files.find(f => f.includes('icon'))
if(iconIndex) {
var iconFile: any = iconIndex.match(/^(.+\.)(.+)$/);
returnObj.icon = {
data: await readfile(path.join(location, iconFile[0]), "base64"),
type: iconFile[2]
};
}
} else if(!allApps.includes(returnObj.name)) {
var appPath = __dirname + '/user/palettes/' + returnObj.name
allApps.push(returnObj.name)
await mkdir(appPath);
await writefile(appPath + '/app.json', '{}')
await writefile(appPath + '/palette.json', '[]')
console.log(`type: ${returnObj.icon.type} data: ${returnObj.icon.data.toString().substr(0, 20)}`)
await writefile(appPath + '/icon.' + returnObj.icon.type, returnObj.icon.data, 'base64')
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/user/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
"devMenu": true,
"defaultShortcuts": true,
"language": "en-us"
}
}
20 changes: 20 additions & 0 deletions src/themes/pywal-dark.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@import url("file:///home/loek/.config/cinquo/themes/pywal.css");

:root {
--accent0: var(--pywal-color0);
--accent1: var(--pywal-color1);
--accent2: var(--pywal-color2);
--accent3: var(--pywal-color3);
--accent4: var(--pywal-color4);
--accent5: var(--pywal-color5);
--accent6: var(--pywal-color6);
--accent7: var(--pywal-color7);
--shade0: var(--pywal-shade0);
--shade1: var(--pywal-shade1);
--shade2: var(--pywal-shade2);
--shade3: var(--pywal-shade3);
--shade4: var(--pywal-shade4);
--shade5: var(--pywal-shade5);
--shade6: var(--pywal-shade6);
--shade7: var(--pywal-shade7);
}
20 changes: 20 additions & 0 deletions src/themes/pywal-light.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@import url("file:///home/loek/.config/cinquo/themes/pywal.css");

:root {
--accent0: var(--pywal-color0);
--accent1: var(--pywal-color1);
--accent2: var(--pywal-color2);
--accent3: var(--pywal-color3);
--accent4: var(--pywal-color4);
--accent5: var(--pywal-color5);
--accent6: var(--pywal-color6);
--accent7: var(--pywal-color7);
--shade0: var(--pywal-shade7);
--shade1: var(--pywal-shade6);
--shade2: var(--pywal-shade5);
--shade3: var(--pywal-shade4);
--shade4: var(--pywal-shade3);
--shade5: var(--pywal-shade2);
--shade6: var(--pywal-shade1);
--shade7: var(--pywal-shade0);
}

0 comments on commit 33d78ce

Please sign in to comment.