Skip to content

Commit

Permalink
Window settings are preserved, added demonstration
Browse files Browse the repository at this point in the history
  • Loading branch information
scpedicini committed Dec 21, 2020
1 parent 2744f10 commit 1912aab
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 29 deletions.
5 changes: 4 additions & 1 deletion .stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"extends": "stylelint-config-standard",
"rules": {
"comment-empty-line-before": null,
"comment-whitespace-inside": null
"comment-whitespace-inside": null,
"max-empty-lines": null,
"no-eol-whitespace": null,
"value-keyword-case": null
}
}
Binary file added assets/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 63 additions & 15 deletions css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,74 @@
/* pointer-events: none; */
/* } */

.fill {
min-height: 90%;
height: 90%;
}

/*region Glightbox related */

.glightbox-paddedbox {
margin: 0;
}

.copy-to-clipboard {
margin-top: 5px;
}

.gslide-description {
background-color: transparent !important;
}


.gallery {
/*background-color: #fff;*/
display: flex;
flex-flow: row wrap;
align-items: center;
justify-content: center;
}


@keyframes gzoomInRegular {
from {
opacity: 0;
transform: scale3d(0.3, 0.3, 0.3);
}

to {
opacity: 1;
}
}

@keyframes gfastZoomOut {
from {
opacity: 1;
}

50% {
opacity: 0;
transform: scale3d(0.3, 0.3, 0.3);
}

to {
opacity: 0;
}
}

.gzoomInHead {
animation: gzoomInRegular 0.5s ease;
}

.gzoomOutHead {
animation: gfastZoomOut 0.1s ease;
}

/*endregion*/

.fill {
min-height: 90%;
height: 90%;
}


.copy-to-clipboard {
margin-top: 5px;
}

body {
padding-left: 12px;
padding-right: 12px;
Expand Down Expand Up @@ -97,15 +148,12 @@ img {
opacity: 0;
}

.gallery {
/*background-color: #fff;*/
display: flex;
flex-flow: row wrap;
align-items: center;
justify-content: center;
}

.bi::before {
vertical-align: -0.125em !important;
margin-bottom: calc(-0.125em / 2);
}





2 changes: 2 additions & 0 deletions js/appsettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ appSettings.CSE_ID = process.env.CSE_ID;
appSettings.CSE_KEY = process.env.CSE_KEY;
appSettings.COLOR_SETTINGS = '#eeeeee';

appSettings.BOUNDS = { };

// appSettings.LocalPath = `F:\\Temp\\Images`;

module.exports = appSettings;
34 changes: 29 additions & 5 deletions js/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@ class Misc {
// no matter how often it is called, it waits "delay" before invoking itself
static debounce(fn, delay) {
let timeout_fn = undefined;
return (...args) => {

let debounce_fn = (...args) => {
clearTimeout(timeout_fn);
timeout_fn = setTimeout(() => {
fn.call(this, ...args);
}, delay);
};

debounce_fn.cancel = () => clearTimeout(timeout_fn);

return debounce_fn;
}

/**
* Check if element is below current viewport for DOM
* @param $el
* @returns {boolean}
*/
static isBelow($el) {
let win_height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
let top = window.scrollY || window.scrollTop || document.getElementsByTagName('html')[0].scrollTop;
Expand All @@ -24,6 +34,10 @@ class Misc {
}


/**
* Simple CPU-bound blocking operation for testing purposes
* @param baseNumber - higher the value, the longer the operation will block
*/
static blockCPU(baseNumber) {
console.time('blockCPU');
let result = 0;
Expand All @@ -35,8 +49,8 @@ class Misc {

/**
* Convert a JSON string into a standard Javascript Object
* @param x
* @returns {{}}
* @param x - JSON string
* @returns {{}} - Deserialized object or empty object
*/
static SafeParse(x) {
let obj = { };
Expand Down Expand Up @@ -80,17 +94,22 @@ class Misc {
*/
static GetISOTime(dateObj = undefined)
{
//return (dateObj ?? new Date()).toISOString().replace(/[TZ]/g, ' ').trim();
return (dateObj ?? new Date()).toISOString().replace(/\.\d\d\d/g, '').trim();
}

// 2020-12-06T02:03:46
/**
* Convert a JS date object into a ISO compatible locale-time string
* @param {Date} dateObj
* @returns {string} - 2020-12-06T02:03:46
* @constructor
*/
static ConvertToLocaleTimeString(dateObj) {
return dateObj.getFullYear() + '-' + (dateObj.getMonth() + 1).toString().padStart(2, '0') + '-' +
dateObj.getDate().toString().padStart(2, '0') + 'T' + dateObj.getHours().toString().padStart(2, '0') + ':' +
dateObj.getMinutes().toString().padStart(2, '0') + ':' + dateObj.getSeconds().toString().padStart(2, '0');
}


static Render(template, paramobj) {
if(paramobj instanceof Object) {
for (let key in paramobj) {
Expand All @@ -102,6 +121,11 @@ class Misc {
return template;
}

/**
* Checks whether a string can be converted to a number (integer or float)
* @param str
* @returns {boolean}
*/
static IsNumerical(str) {
return !isNaN(parseInt(str));
}
Expand Down
18 changes: 14 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,23 @@ try {

function createWindow() {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 1440,
height: 800,
let options = {
width: appSettings.BOUNDS?.width ?? 1440,
height: appSettings.BOUNDS?.height ?? 800,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
devTools: appSettings.DEV_ENV ?? false, // can't bring them up even with the menu bar
},
transparent: true,
frame: false,
};

});
// if('x' in appSettings.BOUNDS)
// options.x = appSettings.BOUNDS.x;
// if('y' in appSettings.BOUNDS)
// options.y = appSettings.BOUNDS.y;

mainWindow = new BrowserWindow(options);

mainWindow.on('ready-to-show', function () {
mainWindow.show();
Expand All @@ -63,6 +69,10 @@ ipcMain.handle('load-settings', args => {
});

ipcMain.on('close', function() {

appSettings.BOUNDS = mainWindow.getBounds();
fs.writeFileSync(settingsFile, JSON.stringify(appSettings), 'utf8');

app.quit();
});

Expand Down
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

## About

Truman Show is a quick image search program designed to be hotkeyed via AUTOHOTKEY to search google image repository and copy to a desired image to the clipboard in a fast accessible manner.
Truman Show is a quick image search program designed to be hotkeyed via AUTOHOTKEY to search the google image repository and copy selected images to the clipboard in an easy and accessible manner. The intent is to be as seamless as possible so that the user is not taken out of their normal workflow.

![alt text](assets/demo.gif)

## Getting Started

Expand Down
12 changes: 9 additions & 3 deletions renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ function setupHandlers() {
document.addEventListener('keydown', event => {
if(!(event.key in Config.keyMap)) {
Config.keyMap[event.key] = true;
if (event.key === 'Escape' && !Config.lightBoxOpen) {
window.ipcRenderer.send('close');
if (event.key === 'Escape') {
if(!Config.lightBoxOpen)
window.ipcRenderer.send('close');
else {
Config.lightBoxOpen = false;
}
}
}
});
Expand Down Expand Up @@ -180,8 +184,9 @@ function initializeLightBox() {
touchFollowAxis: true,
zoomable: false,
draggable: false,
skin: 'paddedbox', // creates a class called glightbox-paddedbox
skin: 'paddedbox' // creates a class called glightbox-paddedbox
});

// slide_after_load
lightBox.on('slide_changed', e => {
console.info('slide changed', e);
Expand Down Expand Up @@ -218,6 +223,7 @@ function initializeLightBox() {
});

lightBox.on('close', (e) => {
console.log('glightbox closed');
Config.lightBoxOpen = false;
});

Expand Down

0 comments on commit 1912aab

Please sign in to comment.