Skip to content

Commit 6eaecff

Browse files
committed
allow single instance
1 parent 12fb4ce commit 6eaecff

File tree

5 files changed

+104
-51
lines changed

5 files changed

+104
-51
lines changed

index.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ require('v8-compile-cache');
22
const electron = require('electron');
33
const path = require('path');
44
const url = require('url');
5-
var mainWindow;
5+
var mainWindow = null;
66
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
77
process.env.NODE_ENV = 'production';
88

@@ -14,12 +14,23 @@ const {
1414
shell,
1515
} = electron;
1616

17+
const gotTheLock = app.requestSingleInstanceLock()
18+
19+
if(!gotTheLock){
20+
app.quit()
21+
} else{
22+
app.on('second-instance', (event, commandLine, workingDirectory) => {
23+
if (mainWindow) {
24+
if (mainWindow.isMinimized()) mainWindow.restore()
25+
mainWindow.focus()
26+
}
27+
})
28+
}
1729

1830
ipcMain.on("back", function (e, d) {
1931
mainWindow.webContents.send("back", d);
2032
})
2133

22-
2334
ipcMain.on("plotsetting", function (e, d) {
2435
mainWindow.webContents.send("plotsetting", d);
2536
})
@@ -34,7 +45,7 @@ ipcMain.on("exportAll", function (e, d) {
3445
})
3546

3647

37-
ipcMain.on('checkClose', function (eg, d) {
48+
ipcMain.on('checkClose', function (e, d) {
3849
mainWindow.destroy();
3950
app.quit();
4051
})

src/css/style.css

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,9 @@ button:active {
237237
.borders {
238238
padding: 2px 0 2px 0;
239239
border: 1px solid black;
240-
box-shadow: inset -2px -2px 3px 0px rgba(0,0,0,.15);
240+
/* box-shadow: inset -2px -2px 3px 0px rgba(0,0,0,.15); */
241+
box-shadow: 0px 4px 8px 0px rgba(0,0,0,.15);
242+
241243
border-radius: 1px;
242244
width: 100%;
243245
background-color: white;
@@ -312,6 +314,12 @@ button:active {
312314

313315
#gridSel{
314316
/* grid-column: 1/3; */
317+
width: fit-content;
318+
background: none;
319+
padding: 3px 0 3px 3px;
320+
/* border: 0; */
321+
margin-left: 0px;
322+
margin-right: 0px;
315323
grid-area: sl;
316324
}
317325
.bl { grid-area: bl; background-color: lawngreen;}
@@ -333,13 +341,7 @@ button:active {
333341

334342

335343

336-
/* #fend{
337-
margin-left: 8px;
338-
}
339344

340-
#fstep{
341-
margin-left: 3px;
342-
} */
343345
#flcl{
344346
margin-left: 4px;
345347
}
@@ -604,14 +606,16 @@ a:focus{
604606

605607

606608
#filler{
607-
background-color: #aba7a729;
609+
/* background-color: #aba7a729; */
608610
position: fixed;
609611
width: 98.5% ;
610-
height: 100%;
612+
/* height: 100%; */
611613
}
612614

613615
.extendUtils,#filler,#extendUtils2D,#rgFit,#lmFit{
614616
display: none;
617+
z-index: 99;
618+
615619
}
616620

617621

@@ -639,6 +643,7 @@ a:focus{
639643

640644
#figurecontainer{
641645
flex: 1;
646+
z-index: -99;
642647
}
643648

644649
#full {
@@ -861,53 +866,81 @@ a:focus{
861866
margin-left: 5px;
862867
}
863868
.fList{
869+
padding: 3px;
864870
margin: 0 0 2px 0;
865871
/* background-color: #1299E6; */
866872
}
867873
.fList:hover{
868874
background-color: #ececec !important;
869875
text-shadow: rgb(10, 10, 10);
870876
padding-left: 1px;
871-
872-
873877
}
874-
875-
.fList:hover .fclsBtn{
878+
.flTools{
879+
display: none;
880+
float:right;
881+
width: fit-content;
882+
}
883+
/* .fList:hover .fclsBtn{
876884
display: inline;
877885
background-color: #ececec !important;
878886
}
879887
.fList:hover .fcpyBtn{
880888
display: inline;
881889
background-color: #ececec !important;
882-
}
890+
} */
883891
.fList:hover .fName{
884-
width: calc(95% - 3pc);
892+
width: calc(95% - 7pc);
893+
}
894+
895+
.fList:hover .flTools{
896+
display: inline !important;
885897
}
886898

887899
.fclsBtn,.fcpyBtn{
888-
float: right;
900+
/* float: right; */
889901
margin-left: 5px;
890-
display: none;
902+
display: inline-block;
891903
cursor: pointer;
892904
height: 1.25pc;
893905
width: 1.25pc;
894906
z-index: -1;
895907
background-color: #dbdbdb;
896908
}
909+
910+
.flSelect{
911+
/* width: 3pc; */
912+
/* margin-right: 3px; */
913+
/* margin-left: 3px; */
914+
/* cursor: pointer; */
915+
/* font-family: sans-serif; */
916+
font-size: 100%;
917+
/* padding: 3px; */
918+
color: #444;
919+
border: none;
920+
background-color: transparent;
921+
text-decoration: none;
922+
border-radius: 0px;
923+
/* display: inline-block; */
924+
/* zoom: 1; */
925+
/* line-height: normal; */
926+
white-space: nowrap;
927+
padding: 0px;
928+
margin: 0px;
929+
vertical-align: top;
930+
/* text-align: center;*/
931+
-webkit-appearance: none;
932+
width: 2pc;
933+
}
934+
.flSelect:active,.flSelect:hover,.flSelect:focus{
935+
box-shadow: none;
936+
}
937+
897938
.selected{
898939
background-color: #dbdbdb;
899940
border-width: 1px;
900941
/* border-style: outset; */
901942
}
902943

903-
#gridSel{
904-
width: fit-content;
905-
background: none;
906-
padding: 3px 0 3px 3px;
907-
/* border: 0; */
908-
margin-left: 0px
909-
}
910-
911944
#lockAxes{
912945
margin: 0 5px 21px 7px;
913946
}

src/html/index.html

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<head>
55
<title>Interactive Data Editor</title>
66
<link href="../css/style.css" rel="stylesheet">
7-
<script>
7+
<script>
88
if (typeof module === 'object') { window.module = module; module = undefined;}
99
</script>
1010
</head>
@@ -41,7 +41,7 @@
4141
<div class="closebtn" onclick="closeNav()">X</div>
4242
<div class="sideheader"> Plots</div>
4343
<div id="lockAllAxes"> <!-- onclick="isAxesLocked =!isAxesLocked; document.getElementById('lockAxes').checked=isAxesLocked"> -->
44-
<input type="checkbox" id="lockAxes" name="axes" value="lockAxes" onclick="isAxesLocked =this.checked">
44+
<input type="checkbox" id="lockAxes" name="axes" value="lockAxes" onclick="isAxesLocked =this.checked">
4545
<span for="lockAxes">Lock Axes</span>
4646
</div>
4747
<div id="files"></div>
@@ -72,7 +72,7 @@
7272
</div>
7373

7474

75-
<div id="range-div" class='3D' >
75+
<div id="range-div" class='3D' >
7676
<input type="range" name="" id="range" min=0 max=100 step=1 value=0 onclick="this.blur()">
7777
<span id="thumb"></span>
7878
</div>
@@ -82,7 +82,7 @@
8282
<div id="extendUtils2D" class="borders">
8383

8484
<div id="rgFit" style="padding:3px">
85-
<span > Order of polynomial </span>
85+
<span > Order of polynomial </span>
8686
<input id="polyInp" type="number" value="1" min="1">
8787
<input type="submit" value="Solve" onclick="polyfit()" class="rgfit-buttons">
8888
<input type="submit" value="Save" onclick="saveFit()" class="rgfit-buttons">
@@ -107,29 +107,29 @@
107107
Damping factor <input id='dampVal' type="text" value="1.5">
108108
Step Size <input id='stepVal' type="text" value='1e-2'>
109109
Error Tolerance <input id='etVal' type="text" value='1e-5'>
110-
Error gradient <input id='egVal' type="text" value='1e-8'>
110+
Error gradient <input id='egVal' type="text" value='1e-8'>
111111
</div>
112112
</div>
113113
</div>
114114

115115
<div id="figurecontainer"></div>
116116

117-
<div id="filler">
118-
<div class="borders">
117+
<!-- <div id="filler"> -->
118+
<div class="borders" id="filler">
119119
<div id='fill' class="extendUtils">
120-
<span class="fillTmp">Start</span>
120+
<span class="fillTmp">Start</span>
121121
<input type="text" id="fstart" tabindex="1">
122122
<span class="shift">
123123
Extrapolate
124124
</span>
125125
<select id="expSel" tabindex="4">
126126
<option>Closest</option>
127127
<option>Regression</option>
128-
</select>
128+
</select>
129129
<br>
130-
<span class="fillTmp">End</span> <input type="text" id="fend" tabindex="2">
130+
<span class="fillTmp">End</span> <input type="text" id="fend" tabindex="2">
131131
<input type="submit" value="OK" onclick="dataFiller()" class="utilBtn shift" tabindex="4">
132-
<input type="submit" value="Cancel" class="utilBtn">
132+
<input type="submit" value="Cancel" class="utilBtn"style="margin-top: 1px;">
133133
<span style="margin-left: 7px">
134134
&#9432;<span style="font-size:.9pc;"> This operation is not reversible. You may want to save before proceeding.</span><br>
135135
</span>
@@ -168,7 +168,7 @@
168168
</div>
169169
</div>
170170

171-
</div>
171+
<!-- </div> -->
172172
</div>
173173

174174

@@ -219,7 +219,7 @@
219219
</div>
220220

221221
<script>
222-
document.getElementById('versionname').innerHTML =`Version ${require('../../package.json').version}`
222+
document.getElementById('versionname').innerHTML =`Version ${require('../../package.json').version}`
223223
</script>
224224

225225
<script src='../js/init.js'></script>

src/js/functions.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,9 +681,13 @@ function settingWindow(){
681681
}
682682

683683

684-
684+
var editorWindow=null
685685
function spreadsheet() {
686-
let editorWindow = new BrowserWindow({
686+
if(editorWindow) {
687+
editorWindow.focus()
688+
return
689+
}
690+
editorWindow = new BrowserWindow({
687691
minWidth: 1200,
688692
title: "Interactive Data Editor",
689693
show: false,
@@ -701,6 +705,8 @@ function spreadsheet() {
701705
editorWindow.setMenuBarVisibility(false);
702706

703707
editorWindow.show();
708+
editorWindow.on("closed", function () { editorWindow = null })
709+
704710
// if (!app.isPackaged) editorWindow.webContents.openDevTools();
705711
editorWindow.webContents.once("dom-ready", function () {
706712
editorWindow.webContents.send("slider", [xName, col.x, data]);
@@ -710,6 +716,10 @@ function spreadsheet() {
710716

711717
var viewerWindow=null; // this variable is used inside the update on server function
712718
function openViewer() {
719+
if(viewerWindow) {
720+
viewerWindow.focus()
721+
return
722+
}
713723
viewerWindow = new BrowserWindow({
714724
show: false,
715725
title: "Interactive Data Editor",
@@ -804,11 +814,14 @@ function tools(option,index){
804814
function makeRows() {
805815
$('#files').html(
806816
fileNames.map((i,j)=>{
817+
var selTxt = "<select class='flSelect'>" +fullData[j][0].map((_,j)=>j).map(i=>`<option>${i+1}</option>`).join(' ') + "</select>"
807818
return `
808819
<div class="fList ${currentEditable==j? 'selected': ''}" >
809820
<div class="fName" onclick="tools(0,${j})" title=${replaceWithHome(i)}>
810821
${j+1}. ${path.basename(i)}
811822
</div>
823+
<div class="flTools">
824+
${selTxt}:${selTxt}:${selTxt}
812825
<div class="fclsBtn" onclick="tools(2,${j})" title='Remove this file' ${currentEditable==j? 'style="pointer-events: none;opacity: 0.4;"': ''}>
813826
<svg viewBox="0 0 1792 1792">
814827
<path d="M1490 1322q0 40-28 68l-136 136q-28 28-68 28t-68-28l-294-294-294 294q-28 28-68 28t-68-28l-136-136q-28-28-28-68t28-68l294-294-294-294q-28-28-28-68t28-68l136-136q28-28 68-28t68 28l294 294 294-294q28-28 68-28t68 28l136 136q28 28 28 68t-28 68l-294 294 294 294q28 28 28 68z"/>
@@ -819,6 +832,7 @@ function makeRows() {
819832
<path d="M1664 1632v-1088q0-13-9.5-22.5t-22.5-9.5h-1088q-13 0-22.5 9.5t-9.5 22.5v1088q0 13 9.5 22.5t22.5 9.5h1088q13 0 22.5-9.5t9.5-22.5zm128-1088v1088q0 66-47 113t-113 47h-1088q-66 0-113-47t-47-113v-1088q0-66 47-113t113-47h1088q66 0 113 47t47 113zm-384-384v160h-128v-160q0-13-9.5-22.5t-22.5-9.5h-1088q-13 0-22.5 9.5t-9.5 22.5v1088q0 13 9.5 22.5t22.5 9.5h160v128h-160q-66 0-113-47t-47-113v-1088q0-66 47-113t113-47h1088q66 0 113 47t47 113z"/>
820833
</svg>
821834
</div>
835+
</div>
822836
</div>`}).join(' ')
823837
)
824838
document.getElementById('lockAllAxes').style.display = fullData.length >1 ? 'block': 'none'

src/js/keyIpcTrigger.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ window.onkeyup = function hotDKeys(e) {
2626

2727
window.onkeydown = function hotKeys(e) {
2828
if (document.activeElement.type == "text") return
29-
29+
// console.log(e)
3030
if(e.key==' '){
3131
if(cRangeY.every(i=>isNaN(i))){
3232
Plotly.relayout(figurecontainer, {
@@ -270,16 +270,11 @@ ipcRenderer.on('checkClose', function (_,_) {
270270

271271

272272
window.addEventListener("resize", function(){
273-
274-
275-
$('#filler').width($('#container').parent().width())
273+
$('#filler').width($('#container').width())
276274
if(fullData.length && ddd) sliderChanged()
277275
})
278276

279-
280-
281-
282-
$('#filler').width($('#container').parent().width())
277+
$('#filler').width($('#container').width())
283278

284279

285280

0 commit comments

Comments
 (0)