Skip to content

Commit

Permalink
Version 1.0.2
Browse files Browse the repository at this point in the history
+ Add setting to remove the resize locking
+ Add some string in the translation file
+ The app now register the size of the window and if you maximize it or not

// "+"  Added
// "~"  Modified
// "-"  Removed
  • Loading branch information
Ward727a committed Oct 31, 2021
1 parent 19acbcb commit af82873
Showing 9 changed files with 204 additions and 33 deletions.
2 changes: 2 additions & 0 deletions lang/ui/en-EN.xml
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@
<parameterLang>Language: </parameterLang>
<parameterAutoUpdate>Auto-update on start-up: </parameterAutoUpdate>
<parameterResetSave>Reset save file!</parameterResetSave>
<parameterResizeLock>Unlock resize locking (WILL create UI issues): </parameterResizeLock>

<parameterWarning>Each change will AUTOMATICALLY restart the application!</parameterWarning>
<aboutTitle>About</aboutTitle>

2 changes: 2 additions & 0 deletions lang/ui/fr-FR.xml
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@
<parameterLang>Langage : </parameterLang>
<parameterAutoUpdate>Mise à jour auto : </parameterAutoUpdate>
<parameterResetSave>Réinitialiser la sauvegarde !</parameterResetSave>
<parameterResizeLock>Retirer le blocage de redimension (provoquera des soucis d'IU) : </parameterResizeLock>

<parameterWarning>Chaque changement relance l'application !</parameterWarning>
<aboutTitle>À propos</aboutTitle>

165 changes: 140 additions & 25 deletions main.js
Original file line number Diff line number Diff line change
@@ -18,6 +18,13 @@ let jobData;
let materialsData;

let lang = "en-EN";
let autoUpdate = true;
let canResize = false;

let windowWidth = 1600;
let windowHeight = 800;

let windowMax = false;

let langJob;
let langMaterials;
@@ -26,7 +33,6 @@ let langUI;
let updaterWindows;
let mainWindows;

let autoUpdate = true;

autoUpdater.on('error', (err)=>{
updaterWindows.webContents.send('update_error', err);
@@ -112,7 +118,7 @@ async function checkDataFile(){
resolve();
})
}).then(()=>{
createWindow();
createWindow(windowWidth, windowHeight);
updaterWindows.destroy();
})
)
@@ -123,20 +129,40 @@ async function checkDataFile(){

}

function createWindow(){
mainWindows = new BrowserWindow({
minWidth: 1600,
minHeight: 800,
autoHideMenuBar: true,
webPreferences:{
nodeIntegration: false, // is default value after Electron v5
contextIsolation: true, // protect against prototype pollution
enableRemoteModule: false, // turn off remote
preload: path.join(__dirname, "/script/preload.js"), // use a preload script
nativeWindowOpen: true
},
titleBarStyle: 'hidden'
})
function createWindow(width = 1600, height = 800){


if(!canResize){
mainWindows = new BrowserWindow({
autoHideMenuBar: true,
minWidth: 1600,
minHeight: 800,
width: width,
height: height,
webPreferences:{
nodeIntegration: false, // is default value after Electron v5
contextIsolation: true, // protect against prototype pollution
enableRemoteModule: false, // turn off remote
preload: path.join(__dirname, "/script/preload.js"), // use a preload script
nativeWindowOpen: true
},
titleBarStyle: 'hidden'
})
} else {
mainWindows = new BrowserWindow({
autoHideMenuBar: true,
width: width,
height: height,
webPreferences:{
nodeIntegration: false, // is default value after Electron v5
contextIsolation: true, // protect against prototype pollution
enableRemoteModule: false, // turn off remote
preload: path.join(__dirname, "/script/preload.js"), // use a preload script
nativeWindowOpen: true
},
titleBarStyle: 'hidden'
})
}

mainWindows.loadFile('pages/index.html');

@@ -162,9 +188,54 @@ function createWindow(){
mainWindows.webContents.on('will-navigate', handleRedirect)
mainWindows.webContents.on('new-window', handleRedirect)

mainWindows.once("close", async (e)=>{

e.preventDefault();
let tmpWidth = mainWindows.getSize()[0],
tmpHeight = mainWindows.getSize()[1];
if(await mainWindows.isMaximized()) {
tmpWidth = windowWidth;
tmpHeight = windowHeight;
}

console.log(tmpWidth)
console.log(tmpHeight)

let tmpMax = mainWindows.isMaximized();

let setting = {
"settings":
{
"lang": lang,
"autoupdate": autoUpdate,
"maximize": tmpMax,
"canResize": canResize,
"size": {
"width": tmpWidth,
"height": tmpHeight
}
}
}

await fs.writeFile(app.getPath('userData')+'/data/settings.json', JSON.stringify(setting), ()=>{

console.info("Set setting: done!");

mainWindows.close();

})

})

mainWindows.once('ready-to-show', ()=>{

mainWindows.center();
if(windowMax){
mainWindows.maximize();
mainWindows.webContents.send('maxSizeResponse');
} else {
mainWindows.center();
}

})

}
@@ -203,7 +274,13 @@ function createLoader(){
"settings":
{
"lang": "en-EN",
"autoupdate": true
"autoupdate": true,
"maximize": false,
"canResize": false,
"size": {
"width": 1600,
"height": 800
}
}
}

@@ -215,7 +292,7 @@ function createLoader(){
})
} else {

fs.readFile(app.getPath('userData') + "/data/settings.json", (err1, data) => {
fs.readFile(app.getPath('userData') + "/data/settings.json", async (err1, data) => {

let result = JSON.parse(data.toString("utf-8"))

@@ -224,13 +301,43 @@ function createLoader(){
lang = setting['lang'];
autoUpdate = setting['autoupdate'];

if(setting['maximize'] === undefined) { //Change variable for each new version of settings.json
let data = {
"settings":
{
"lang": lang,
"autoupdate": autoUpdate,
"maximize": false,
"canResize": false,
"size": {
"width": 1600,
"height": 800
}
}
}

await mkdirp(app.getPath('userData') + "/data/");
await fs.writeFile(app.getPath('userData') + "/data/settings.json", JSON.stringify(data), (err1) => {

app.relaunch();
app.exit();

})
}


canResize = setting['canResize'];
windowWidth = setting['size']['width'];
windowHeight = setting['size']['height'];
windowMax = setting['maximize']

if (!autoUpdate) {

checkDataFile()
await checkDataFile()

} else {

autoUpdater.checkForUpdatesAndNotify();
await autoUpdater.checkForUpdatesAndNotify();

}
})
@@ -422,7 +529,7 @@ ipcMain.on('clearTab', async (ipc)=>{

ipcMain.once('closeApp', (ipc)=>{

app.quit();
mainWindows.close();

})

@@ -479,13 +586,21 @@ ipcMain.on('getAutoUpdate', (ipc)=>{

});

ipcMain.on('setSettings', (ipc, setting)=>{
ipcMain.on('getResize', (ipc)=>{

fs.writeFile(app.getPath('userData')+'/data/settings.json', JSON.stringify(setting), ()=>{
mainWindows.webContents.send('getResizeResponse', {canResize: canResize, width: windowWidth, height: windowHeight});

mainWindows.webContents.send('setSettingsResponse');
})

ipcMain.on('getMax', (ipc)=>{
mainWindows.webContents.send('getMaxResponse', windowMax);
})

ipcMain.on('setSettings', (ipc, setting) =>{

fs.writeFile(app.getPath('userData')+'/data/settings.json', JSON.stringify(setting), ()=>{

mainWindows.webContents.send('setSettingsResponse');

})

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "new_world_refining_calculator",
"productName": "NWRC",
"version": "1.0.1",
"version": "1.0.2",
"description": "Launch New Word Refining Calculator",
"main": "main.js",
"scripts": {
6 changes: 4 additions & 2 deletions pages/index.html
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@

<div id="frame">

<p id="title">NWRC - Version: 1.0.1</p>
<p id="title">NWRC - Version: 1.0.2</p>

<div id="frameMinimizeContainer" class="frameButton">
<img id="frameMinimize" alt="minimize" width="16px" height="16px"/>
@@ -125,7 +125,9 @@ <h3 data-lang="parameterTitle"></h3>

</select><br/><br/>
<label for="autoCheck" data-lang="parameterAutoUpdate"></label>
<input type="checkbox" id="autoCheck"/>
<input type="checkbox" id="autoCheck"/><br/><br/>
<label for="autoCheck" data-lang="parameterResizeLock"></label>
<input type="checkbox" id="canResize"/>

<button id="resetSave" data-lang="parameterResetSave"></button>

52 changes: 51 additions & 1 deletion script/calculator/parameter-manager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
let setting = {
settings:{
lang: "",
autoupdate: ""
autoupdate: "",
maximize: "",
canResize: "",
size: {
width: 0,
height : 0
}
}
}

@@ -139,6 +145,47 @@ function initResetSave(){
})

}
function initResize(){

window["api"].sendAsync('getResize');

window["api"].receiveOnce('getResizeResponse', (state)=>{

let checkbox = document.getElementById('canResize');

checkbox.checked = state.canResize;
setting.settings.canResize = state.canResize;

setting.settings.size.height = state.height;
setting.settings.size.width = state.width;

checkbox.addEventListener('change', ()=>{

setting.settings.canResize = checkbox.checked;
window["api"].sendAsync('setSettings', setting);

window["api"].receiveOnce('setSettingsResponse', ()=>{

window["api"].sendAsync('restartApp');

})

})

})


}
function initMaximize(){

window["api"].sendAsync('getMax');

window["api"].receiveOnce('getMaxResponse', (state)=>{

setting.settings.maximize = state;

})
}

function openSettings(){
document.getElementById("paramContainer").className = "roundButton clickRound";
@@ -153,7 +200,10 @@ function openAbout(){
}

initResetSave();

initAutoUpdate();
initResize();

initAbout();

setLangOption();
4 changes: 2 additions & 2 deletions script/preload.js
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ const {
*/
let validChannelsSend = ['getAllJobs', 'getDataFrom', 'getLang', 'getAllItems', "getUID", "installUpdate", "openApp",
"getSavedTab", "saveTab", "deleteTab", "GetVersion", "GetUpdate", "StartTest", "closeApp", "minApp", "minSize", "maxSize", "restartApp",
"getLanguage", 'getAutoUpdate', "setSettings", "clearTab"];
"getLanguage", 'getAutoUpdate', "setSettings", "clearTab", "getResize", "getMax"];

/**
* An array that contains ALL the valid receive channels (security purposes)
@@ -23,7 +23,7 @@ let validChannelsSend = ['getAllJobs', 'getDataFrom', 'getLang', 'getAllItems',
let validChannelsReceive = ["update_error", "update_available", "update_downloaded", "no_update",
'getAllJobsResponse', 'getDataFromResponse', "getLangResponse", "getAllItemsResponse", "returnUID",
"getSavedTabResponse", "deleteTabResponse", "StopTest", "maxSizeResponse", "minSizeResponse",
"getLanguageResponse", "setAutoUpdate", 'getAutoUpdateResponse', "setSettingsResponse"];
"getLanguageResponse", "setAutoUpdate", 'getAutoUpdateResponse', "setSettingsResponse", "getResizeResponse", "getMaxResponse"];

let uuid = uuidv4();

2 changes: 1 addition & 1 deletion style/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit af82873

Please sign in to comment.