-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: continue Nouvelle initialisation de l'application #47
- Loading branch information
Showing
9 changed files
with
254 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
electron-app/ecoindex-app/src/main/handlers/Initalization.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { IpcMainEvent, IpcMainInvokeEvent } from 'electron' | ||
|
||
import Store from 'electron-store' | ||
import { channels } from '../../shared/constants' | ||
import { getMainLog } from '../main' | ||
import { getMainWindow } from '../../shared/memory' | ||
import { initIsNodeInstalled } from './initHandlers/IsNodeInstalled' | ||
import { initIsNodeNodeVersionOK } from './initHandlers/isNodeVersionOK' | ||
|
||
const store = new Store() | ||
|
||
type initializedDatas = { | ||
initIsNodeInstalled?: boolean | ||
initIsNodeNodeVersionOK?: boolean | ||
} | ||
|
||
const readInitalizedDatas = (value: initializedDatas): boolean => { | ||
return value.initIsNodeInstalled && value.initIsNodeNodeVersionOK | ||
} | ||
|
||
export const initialization = async ( | ||
event: IpcMainEvent | IpcMainInvokeEvent | ||
) => { | ||
const mainLog = getMainLog().scope('main/initialization') | ||
const initializedDatas: initializedDatas = {} | ||
try { | ||
mainLog.log(`Initialization start...`) | ||
mainLog.log(`1. Node installed start...`) | ||
// #region Node installed | ||
const isNodeReturned = await initIsNodeInstalled(event) | ||
initializedDatas.initIsNodeInstalled = isNodeReturned.result as boolean | ||
mainLog.log(isNodeReturned.toString()) | ||
getMainWindow().webContents.send( | ||
channels.INITIALIZATION_DATAS, | ||
isNodeReturned | ||
) | ||
mainLog.log(`2. Node Version upper or equal to 20 start...`) | ||
// #region Node installed | ||
const isNode20Returned = await initIsNodeNodeVersionOK(event) | ||
initializedDatas.initIsNodeNodeVersionOK = | ||
isNode20Returned.result as boolean | ||
mainLog.log(isNode20Returned.toString()) | ||
getMainWindow().webContents.send( | ||
channels.INITIALIZATION_DATAS, | ||
isNode20Returned | ||
) | ||
|
||
return readInitalizedDatas(initializedDatas) | ||
} catch (error) { | ||
mainLog.error(error) | ||
return false | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
electron-app/ecoindex-app/src/main/handlers/initHandlers/IsNodeInstalled.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { IpcMainEvent, IpcMainInvokeEvent } from 'electron' | ||
import { getTryNode, setTryNode } from '../../../shared/memory' | ||
|
||
import { ConfigData } from '../../../class/ConfigData' | ||
import { channels } from '../../../shared/constants' | ||
import { getMainLog } from '../../main' | ||
import { handle_CMD_Actions } from '../HandleCMDActions' | ||
import { sleep } from '../../../main/utils/Sleep' | ||
|
||
/** | ||
* | ||
* @param _event | ||
* @returns {string} | ||
*/ | ||
const fetchNode = async ( | ||
_event: IpcMainEvent | IpcMainInvokeEvent | ||
): Promise<string> => { | ||
const _nodeDir = await handle_CMD_Actions( | ||
_event, | ||
channels.IS_NODE_INSTALLED | ||
) | ||
// #region tries read node | ||
// give some tries before return false | ||
if (_nodeDir === '' && getTryNode() > 0) { | ||
await sleep(2000) | ||
setTryNode() | ||
return fetchNode(_event) | ||
} | ||
return _nodeDir as string | ||
} | ||
|
||
export const initIsNodeInstalled = async ( | ||
_event: IpcMainEvent | IpcMainInvokeEvent | ||
) => { | ||
const mainLog = getMainLog().scope( | ||
'main/initialization/initIsNodeInstalled' | ||
) | ||
try { | ||
const returned: string = await fetchNode(_event) | ||
|
||
const output = new ConfigData('node_installed') | ||
if (returned === '') { | ||
output.error = `Node not found` | ||
} else { | ||
output.result = true | ||
output.message = `Node is Installed in ${returned}` | ||
} | ||
mainLog.debug(output) | ||
return new Promise<ConfigData>((resolve, reject) => { | ||
if (output.error) reject(output) | ||
else resolve(output) | ||
}) | ||
} catch (error) { | ||
mainLog.error(error) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
electron-app/ecoindex-app/src/main/handlers/initHandlers/isNodeVersionOK.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { IpcMainEvent, IpcMainInvokeEvent } from 'electron' | ||
|
||
import { ConfigData } from '../../../class/ConfigData' | ||
import { channels } from '../../../shared/constants' | ||
import { getMainLog } from '../../main' | ||
import { handle_CMD_Actions } from '../HandleCMDActions' | ||
|
||
export const initIsNodeNodeVersionOK = async ( | ||
_event: IpcMainEvent | IpcMainInvokeEvent | ||
) => { | ||
const mainLog = getMainLog().scope( | ||
'main/initialization/initIsNodeNodeVersionOK' | ||
) | ||
try { | ||
const returned: string = await handle_CMD_Actions( | ||
_event, | ||
channels.GET_NODE_VERSION | ||
) | ||
const major = returned.replace('v', '').split('.')[0] | ||
|
||
const output = new ConfigData('node_version_is_ok') | ||
if (returned === '') { | ||
output.error = `Node version not found` | ||
} else { | ||
output.result = Number(major) >= 20 | ||
output.message = `Node version is ${returned} and it's upper or equal to 20=${output.result}` | ||
} | ||
mainLog.debug(output) | ||
return new Promise<ConfigData>((resolve, reject) => { | ||
if (output.error) reject(output) | ||
else resolve(output) | ||
}) | ||
} catch (error) { | ||
mainLog.error(error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.