Skip to content

Commit

Permalink
v0.0.64
Browse files Browse the repository at this point in the history
  • Loading branch information
therockerline committed May 9, 2024
1 parent 0e03967 commit f47771c
Show file tree
Hide file tree
Showing 23 changed files with 159 additions and 58 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nethlink",
"version": "0.0.63",
"version": "0.0.64",
"description": "Neth Connector app",
"main": "./out/main/main.js",
"license": "UNLICENSED",
Expand Down Expand Up @@ -45,7 +45,7 @@
"@fortawesome/react-fontawesome": "^0.2.0",
"@headlessui/react": "^1.7.18",
"@hookform/resolvers": "^3.3.4",
"@nethesis/phone-island": "^0.8.11",
"@nethesis/phone-island": "^0.8.12",
"@tailwindcss/forms": "^0.5.7",
"@types/lodash": "^4.14.202",
"@types/node": "^18.19.9",
Expand Down
44 changes: 44 additions & 0 deletions src/main/classes/controllers/AppController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Account } from "@shared/types"
import { AccountController } from "./AccountController"
import { LoginController } from "./LoginController"
import { NethLinkController } from "./NethLinkController"
import { PhoneIslandController } from "./PhoneIslandController"
import { SplashScreenController } from "./SplashScreenController"
import { TrayController } from "./TrayController"
import { log } from "@shared/utils/logger"
import { DevToolsController } from "./DevToolsController"

export class AppController {
static _app: Electron.App
static onQuit = false
constructor(app: Electron.App) {
AppController._app = app
}


static async safeQuit() {
if (!AppController.onQuit) {
AppController.onQuit = true
log('SAFE QUIT')
SplashScreenController.instance.window.hide()
NethLinkController.instance.window.hide()
PhoneIslandController.instance.window.hide()
LoginController.instance.window.hide()
const account = AccountController.instance.getLoggedAccount()
try {
await PhoneIslandController.instance.logout(account!)
} catch (e) {
log(e)
}
setTimeout(() => {
SplashScreenController.instance.window.quit()
NethLinkController.instance.window.quit()
PhoneIslandController.instance.window.quit()
LoginController.instance.window.quit()
DevToolsController.instance.window.quit()
TrayController.instance.tray.destroy()
AppController._app.exit()
}, 1500)
}
}
}
6 changes: 3 additions & 3 deletions src/main/classes/controllers/LoginController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IPC_EVENTS } from '@shared/constants'
import { LoginWindow } from '../windows'
import { LOGIN_WINDOW_WIDTH, LoginWindow } from '../windows'
import { AccountController } from './AccountController'

export class LoginController {
Expand All @@ -16,8 +16,8 @@ export class LoginController {
const loginPage = this.window!.getWindow()
if (loginPage) {
const bounds = loginPage.getBounds()
loginPage.setBounds({ ...bounds, width: 500, height: h }, true)
loginPage.center()
loginPage.setBounds({ ...bounds, width: LOGIN_WINDOW_WIDTH, height: h }, true)
//loginPage.center()
}
}
show() {
Expand Down
8 changes: 3 additions & 5 deletions src/main/classes/controllers/NethCTIController.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { join } from 'path'
import axios from 'axios'
import crypto from 'crypto'
import moment from 'moment'
import { Account, NewContactType, OperatorData, ContactType, NewSpeedDialType } from '@shared/types'
import { Account, NewContactType, OperatorData, ContactType, NewSpeedDialType, Extension } from '@shared/types'
import { log } from '@shared/utils/logger'
import { NetworkController } from './NetworkController'

Expand Down Expand Up @@ -269,8 +267,8 @@ export class NethVoiceAPI {
all: async () => await this._GET('/webrest/user/all'),
all_avatars: async () => await this._GET('/webrest/user/all_avatars'),
all_endpoints: async () => await this._GET('/webrest/user/endpoints/all'),
heartbeat: async (extension: string) => await this._POST('/webrest/user/nethlink', { extension })

heartbeat: async (extension: string) => await this._POST('/webrest/user/nethlink', { extension }),
default_device: async (deviceIdInformation: Extension) => await this._POST('/webrest/user/default_device', { id: deviceIdInformation.id })
//all_avatars: () => this._GET('/webrest/user/all_avatars'),
}

Expand Down
23 changes: 18 additions & 5 deletions src/main/classes/controllers/PhoneIslandController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IPC_EVENTS, PHONE_ISLAND_EVENTS, PHONE_ISLAND_RESIZE } from '@shared/co
import { log } from '@shared/utils/logger'
import { NethVoiceAPI } from './NethCTIController'
import { AccountController } from './AccountController'
import { screen } from 'electron'
import { ipcMain, screen } from 'electron'
import { debouncer } from '@shared/utils/utils'

export class PhoneIslandController {
Expand Down Expand Up @@ -116,9 +116,22 @@ export class PhoneIslandController {
this.showPhoneIsland()
}

logout(account: Account, isExit: boolean = false) {
this.window.emit(IPC_EVENTS.ON_DATA_CONFIG_CHANGE, undefined, account)
if (!isExit)
this.hidePhoneIsland()
async logout(account: Account) {
let isResolved = false
return new Promise<void>((resolve, reject) => {
this.window.emit(IPC_EVENTS.ON_DATA_CONFIG_CHANGE, undefined, account)
try {
ipcMain.on(PHONE_ISLAND_EVENTS['phone-island-socket-disconnected'], () => {
this.hidePhoneIsland()
isResolved = true
resolve()
})
setTimeout(() => {
if (!isResolved) reject(new Error('timeout logout'))
}, 5000)
} catch (e) {
reject(e)
}
})
}
}
10 changes: 3 additions & 7 deletions src/main/classes/controllers/TrayController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { LoginController } from './LoginController'
import { NethLinkController } from './NethLinkController'
import { SplashScreenController } from './SplashScreenController'
import { PhoneIslandController } from './PhoneIslandController'
import { AppController } from './AppController'

export class TrayController {
tray: Tray
Expand All @@ -26,17 +27,12 @@ export class TrayController {
})
const menu: (MenuItemConstructorOptions | MenuItem)[] = [
{
role: 'quit',
role: 'close',
//accelerator: 'Command+Q',
commandId: 1,
click: () => {
//TODO: trovare un modo per killare l'app
SplashScreenController.instance.window.quit()
NethLinkController.instance.window.quit()
PhoneIslandController.instance.window.quit()
LoginController.instance.window.quit()
TrayController.instance.tray.destroy()
app.quit()
AppController.safeQuit()
}
}
]
Expand Down
6 changes: 5 additions & 1 deletion src/main/classes/windows/BaseWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ export class BaseWindow {
}

quit() {
this._window?.close()
try {
this._window?.close()
} catch (e) {
log(e)
}
}
}

2 changes: 1 addition & 1 deletion src/main/classes/windows/DevToolsWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class DevToolsWindow extends BaseWindow {
closable: false,
movable: true,
frame: true,
height: 280,
height: 380,
width: 300,
resizable: true,
alwaysOnTop: true,
Expand Down
3 changes: 2 additions & 1 deletion src/main/classes/windows/LoginWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { AccountController } from '../controllers'
import { BaseWindow } from './BaseWindow'
import { log } from '@shared/utils/logger'

export const LOGIN_WINDOW_WIDTH = 500
export class LoginWindow extends BaseWindow {
constructor() {
super(PAGES.LOGIN, {
width: 500,
width: LOGIN_WINDOW_WIDTH,
height: 0,
show: false,
fullscreenable: false,
Expand Down
2 changes: 1 addition & 1 deletion src/main/classes/windows/NethLinkWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class NethLinkWindow extends BaseWindow {
alwaysOnTop: true,
minimizable: false,
maximizable: false,
movable: false,
movable: true,
resizable: false,
skipTaskbar: true,
roundedCorners: false,
Expand Down
15 changes: 14 additions & 1 deletion src/main/lib/ipcEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { join } from 'path'
import { log } from '@shared/utils/logger'
import { cloneDeep } from 'lodash'
import { NethLinkController } from '@/classes/controllers/NethLinkController'
import { AppController } from '@/classes/controllers/AppController'

function onSyncEmitter<T>(
channel: IPC_EVENTS,
Expand Down Expand Up @@ -68,6 +69,18 @@ export function registerIpcEvents() {
NethVoiceAPI.instance.Phonebook.deleteSpeeddial(contact)
)

onSyncEmitter(IPC_EVENTS.DEVICE_DEFAULT_CHANGE, (deviceIdInformation) => new Promise(async (resolve, reject) => {
try {
const d = await NethVoiceAPI.instance.User.default_device(deviceIdInformation)
await NethVoiceAPI.instance.User.me()
resolve(d)
} catch (e) {
reject(e)
}
})

)

ipcMain.on(IPC_EVENTS.LOGOUT, async (_event) => {
AccountController.instance.logout()
})
Expand All @@ -77,7 +90,7 @@ export function registerIpcEvents() {
})

ipcMain.on(IPC_EVENTS.CLOSE_NETH_LINK, async (event) => {
app.exit()
AppController.safeQuit()
})

ipcMain.on(IPC_EVENTS.OPEN_HOST_PAGE, async (_, path) => {
Expand Down
5 changes: 2 additions & 3 deletions src/main/lib/windowConstructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { mainBindings } from 'i18next-electron-fs-backend'
import { join } from 'path'
import fs from 'fs'
import { AccountController, PhoneIslandController } from '@/classes/controllers'
import { AppController } from '@/classes/controllers/AppController'


export type WindowOptions = {
Expand Down Expand Up @@ -65,10 +66,8 @@ export function createWindow(
})

mainWindow.on('close', () => {
const account = AccountController.instance.getLoggedAccount()
if (account) PhoneIslandController.instance.logout(account)
AccountController.instance.stopAuthPolling()
AccountController.instance._app?.exit()
AppController.safeQuit()
})

mainBindings(ipcMain, mainWindow, fs)
Expand Down
8 changes: 6 additions & 2 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import { SplashScreenController } from './classes/controllers/SplashScreenContro
import { debouncer, delay } from '@shared/utils/utils'
import { IPC_EVENTS } from '@shared/constants'
import { NetworkController } from './classes/controllers/NetworkController'
import { AppController } from './classes/controllers/AppController'

new AppController(app)
new NetworkController()
new AccountController(app)

Expand Down Expand Up @@ -136,11 +138,11 @@ const onAccountLogin = (account: Account) => {
AccountController.instance.addEventListener('LOGOUT', onAccountLogout)
}

const onAccountLogout = (account: Account, isExit: boolean = false) => {
const onAccountLogout = async (account: Account, isExit: boolean = false) => {
//ormai mi sono sloggato quindi rimuovo il listener
AccountController.instance.removeEventListener('LOGOUT', onAccountLogout)
PhoneIslandController.instance.logout(account, isExit)
if (!isExit) {
await PhoneIslandController.instance.logout(account)
NethLinkController.instance.hide()
AccountController.instance.addEventListener('LOGIN', onLoginFromLoginPage)
AccountController.instance.addEventListener('LOGIN', onAccountLogin)
Expand All @@ -159,6 +161,8 @@ app.on('window-all-closed', () => {
//i18nextBackend.clearMainBindings(ipcMain);
})



app.on('quit', () => {
log('quit')
const account = AccountController.instance.getLoggedAccount()
Expand Down
4 changes: 4 additions & 0 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Account,
AvailableThemes,
ContactType,
Extension,
HistoryCallData,
NewContactType,
NewSpeedDialType,
Expand Down Expand Up @@ -33,6 +34,7 @@ export interface IElectronAPI {
): Promise<ContactType>
deleteSpeedDial(contact: ContactType): Promise<string>
getLocale(): Promise<string>
deviceDefaultChange: (deviceIdInformation: Extension) => Promise<void>

//LISTENERS - receive data async
onAccountChange(updateAccount: (account: Account | undefined) => void): void
Expand Down Expand Up @@ -65,6 +67,7 @@ export interface IElectronAPI {
showPhoneIsland: () => void
hidePhoneIsland: () => void


//PHONE ISLAND EVENTS:
(funcName: PHONE_ISLAND_EVENTS): () => void
}
Expand Down Expand Up @@ -111,6 +114,7 @@ const api: IElectronAPI = {
editSpeedDialContact: setEmitterSync<ContactType>(IPC_EVENTS.EDIT_SPEEDDIAL_CONTACT),
deleteSpeedDial: setEmitterSync<string>(IPC_EVENTS.DELETE_SPEEDDIAL),
getLocale: setEmitterSync<string>(IPC_EVENTS.GET_LOCALE),
deviceDefaultChange: setEmitterSync<void>(IPC_EVENTS.DEVICE_DEFAULT_CHANGE),

//EMITTER - only emit, no response
openDevTool: setEmitter(IPC_EVENTS.OPEN_DEV_TOOLS),
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getSystemTheme } from './utils'

function Layout({ theme }: { theme?: AvailableThemes }) {
return (
<div className={`${theme} font-Poppins`}>
<div className={`${theme} font-Poppins`} id="phone-island-container">
<Outlet />
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/components/SearchNumberBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function SearchNumberBox({
})

function saveUnfiltered(receivedPhoneNumbers: SearchCallData) {
console.log('Receveid numbers: ', receivedPhoneNumbers)
log('Receveid numbers: ', receivedPhoneNumbers)
const filteredNumbers = receivedPhoneNumbers.rows.filter(
(phoneNumber) => !(!phoneNumber.name || phoneNumber.name === '')
)
Expand Down
Loading

0 comments on commit f47771c

Please sign in to comment.