Skip to content

Commit

Permalink
Merge pull request #25 from yaht-app/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
SRichner authored May 30, 2021
2 parents 0490c41 + 00b5fbb commit e969efb
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 16 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yaht-client",
"version": "1.0.0",
"version": "1.0.1",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand All @@ -20,6 +20,7 @@
"@tailwindcss/postcss7-compat": "^2.0.2",
"@tailwindcss/typography": "^0.4.0",
"animate.css": "^4.1.1",
"auto-launch": "^5.0.5",
"autoprefixer": "^9",
"axios": "^0.21.1",
"core-js": "^3.6.5",
Expand All @@ -41,6 +42,7 @@
"vuex-typescript": "^3.0.2"
},
"devDependencies": {
"@types/auto-launch": "^5.0.1",
"@types/cron": "^1.7.2",
"@types/electron-devtools-installer": "^2.2.0",
"@types/jest": "^24.0.19",
Expand Down
9 changes: 9 additions & 0 deletions src/main/AppUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { autoUpdater } from 'electron-updater';
const LOG = getLogger('AutoUpdater');

export default class AppUpdater {
private checkForUpdatesInterval: NodeJS.Timeout | undefined;
constructor() {
autoUpdater.logger = LOG;
}
Expand All @@ -14,4 +15,12 @@ export default class AppUpdater {
LOG.error(`An error occurred while trying to check for updates: ${e}`);
}
}

public startCheckForUpdatesInterval() {
LOG.info('startCheckForUpdatesInterval called, starting interval...');
this.checkForUpdatesInterval = setInterval(
this.checkForUpdatesAndNotify,
10 * 60 * 1000
);
}
}
14 changes: 13 additions & 1 deletion src/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { NotificationService } from '@/main/core/NotificationService';
import { getLogger } from '@/shared/logger';
import { app, protocol, BrowserWindow, ipcMain } from 'electron';
import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer';
import AutoLaunch from 'auto-launch';

const isDevelopment = process.env.NODE_ENV !== 'production';
const LOG = getLogger('app.ts', true);
Expand Down Expand Up @@ -49,8 +50,19 @@ app.on('ready', async () => {
}
}
await system.ready();
updater.checkForUpdatesAndNotify();
updater.startCheckForUpdatesInterval();
notificationService.setWebContents(system.webContents);
const autoLaunch = new AutoLaunch({
name: 'yaht',
});

ipcMain.on('auto-launch-check', () => {
autoLaunch.isEnabled().then((isEnabled: boolean) => {
if (!isEnabled) {
autoLaunch.enable();
}
});
});
});

// Exit cleanly on request from parent process in development mode.
Expand Down
23 changes: 19 additions & 4 deletions src/renderer/core/auth/AuthUseCases.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AuthService } from '@/renderer/core/auth/AuthService';
import { UserAuthDTO } from '@/renderer/core/auth/models/UserAuthDTO.ts';
import { getLogger } from '@/shared/logger';
import { ipcRenderer } from 'electron';
import { inject, injectable } from 'inversify';
import SERVICE from '@/constants/ServiceIdentifiers.ts';
import store from '@/renderer/ui/store';
Expand All @@ -16,10 +17,24 @@ export class AuthUseCases {

async login(username: string, password: string): Promise<void> {
LOG.debug('login useCase');
const user: UserAuthDTO = await this.authService.login(username, password);
store.commit('authStore/setUser', user);
store.commit('authStore/setIsLoggedIn', true);
store.commit('authStore/setToken', user.token);
store.commit('authStore/setErrorMessage', '');
try {
const user: UserAuthDTO = await this.authService.login(
username,
password
);
store.commit('authStore/setUser', user);
store.commit('authStore/setIsLoggedIn', true);
store.commit('authStore/setToken', user.token);
ipcRenderer.send('setGlobalUser', user);
} catch (e) {
store.commit(
'authStore/setErrorMessage',
'Please check your credentials and try again.'
);
LOG.info(`Error during login: ${e}`);
throw e;
}
}

async logout(): Promise<void> {
Expand Down
2 changes: 0 additions & 2 deletions src/renderer/infrastructure/auth/JwtAuthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { AuthService } from '@/renderer/core/auth/AuthService';
import { UserAuthDTO } from '@/renderer/core/auth/models/UserAuthDTO.ts';
import { getLogger } from '@/shared/logger';
import axios, { AxiosInstance } from 'axios';
import { ipcRenderer } from 'electron';
import { injectable } from 'inversify';

const LOG = getLogger('JwtAuthService');
Expand All @@ -27,7 +26,6 @@ export class JwtAuthService implements AuthService {
});

this.user = response.data.data as UserAuthDTO;
ipcRenderer.send('setGlobalUser', this.user);
return this.user;
}

Expand Down
6 changes: 6 additions & 0 deletions src/renderer/ui/store/AuthStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ export interface AuthState {
isLoggedIn: boolean;
user?: UserAuthDTO;
token: string;
errorMessage?: string;
}

const state: AuthState = {
isLoggedIn: false,
user: undefined,
token: '',
errorMessage: '',
};

const mutations = {
Expand All @@ -25,12 +27,16 @@ const mutations = {
setToken(state: AuthState, token: string): void {
state.token = token;
},
setErrorMessage(state: AuthState, error: string): void {
state.errorMessage = error;
},
};
const actions = {
logout(context: ActionContext<AuthState, RootState>): void {
context.commit('setUser', undefined);
context.commit('setIsLoggedIn', false);
context.commit('setToken', '');
context.commit('setErrorMessage', '');
},
};
const getters = {};
Expand Down
33 changes: 26 additions & 7 deletions src/renderer/ui/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
<input id="password" type="password" v-model="password" />
</div>
</div>
<div
class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative text-sm"
v-if="errorMessage"
>
<span>{{ errorMessage }}</span>
</div>
<button class="btn btn-primary w-full" @click="loginClicked">
<img
src="~@/renderer/ui/assets/images/spinner.svg"
Expand All @@ -34,12 +40,15 @@
</div>
</div>
<div class="temporary-user-wrapper" v-else>
<h1 class="mt-6 text-center text-3xl font-extrabold text-gray-900">
<h1 class="mt-0 mb-20 text-center text-3xl font-extrabold text-gray-900">
Welcome, {{ user.username }}!
</h1>
<span class="mt-12">
You're all set up. You can now close this window.
</span>

<button class="btn btn-primary w-full mt-5" @click="logoutClicked">
Log out
<button class="btn btn-primary w-full mt-5" @click="hideWindow">
Close Window
</button>
</div>
</div>
Expand Down Expand Up @@ -84,6 +93,7 @@ export default class Home extends Vue {
@auth.State isLoggedIn!: boolean;
@auth.State user!: UserAuthDTO;
@auth.State errorMessage!: string;
constructor() {
super();
Expand All @@ -109,10 +119,8 @@ export default class Home extends Vue {
this.isLoggingIn = true;
try {
await this.authUseCase.login(this.userName, this.password);
const mainWindow = await remote.BrowserWindow.getFocusedWindow();
if (process.env.NODE_ENV === 'production' && mainWindow) {
mainWindow.hide();
}
this.requestAutoStartPermission();
await this.fetchNotifications();
this.fetchNotificationsInterval = window.setInterval(
Expand Down Expand Up @@ -222,6 +230,17 @@ export default class Home extends Vue {
}
}
private requestAutoStartPermission(): void {
ipcRenderer.send('auto-launch-check');
}
private async hideWindow(): Promise<void> {
const mainWindow = await remote.BrowserWindow.getFocusedWindow();
if (mainWindow) {
mainWindow.hide();
}
}
logoutClicked(): void {
clearInterval(this.fetchNotificationsInterval);
this.isFetchingNotifications = false;
Expand Down
28 changes: 27 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,11 @@
resolved "https://registry.yarnpkg.com/@types/anymatch/-/anymatch-1.3.1.tgz#336badc1beecb9dacc38bea2cf32adf627a8421a"
integrity sha512-/+CRPXpBDpo2RK9C68N3b2cOvO0Cf5B9aPijHsoDQTHivnGSObdOF2BRQOYjojWTDy6nQvMjmqRXIxH55VjxxA==

"@types/auto-launch@^5.0.1":
version "5.0.1"
resolved "https://registry.yarnpkg.com/@types/auto-launch/-/auto-launch-5.0.1.tgz#388a047edc0e754d8e8978cbd9ed4672b36be2c4"
integrity sha512-+KQ+/koZ7sJXnf5cnCANofY6yXAdYJNEoVZEuWcwJfuWbUp9u6l09I7KhwD+ivU+cdz7JId4V5ukxscWtHdSuw==

"@types/babel__core@^7.1.0":
version "7.1.14"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.14.tgz#faaeefc4185ec71c389f4501ee5ec84b170cc402"
Expand Down Expand Up @@ -2511,6 +2516,11 @@ [email protected]:
semver "^7.3.4"
temp-file "^3.3.7"

applescript@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/applescript/-/applescript-1.0.0.tgz#bb87af568cad034a4e48c4bdaf6067a3a2701317"
integrity sha1-u4evVoytA0pOSMS9r2Bno6JwExc=

aproba@^1.0.3, aproba@^1.1.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/aproba/-/aproba-1.2.0.tgz#6802e6264efd18c790a1b0d517f0f2627bf2c94a"
Expand Down Expand Up @@ -2743,6 +2753,17 @@ atob@^2.1.2:
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==

auto-launch@^5.0.5:
version "5.0.5"
resolved "https://registry.yarnpkg.com/auto-launch/-/auto-launch-5.0.5.tgz#d14bd002b1ef642f85e991a6195ff5300c8ad3c0"
integrity sha512-ppdF4mihhYzMYLuCcx9H/c5TUOCev8uM7en53zWVQhyYAJrurd2bFZx3qQVeJKF2jrc7rsPRNN5cD+i23l6PdA==
dependencies:
applescript "^1.0.0"
mkdirp "^0.5.1"
path-is-absolute "^1.0.0"
untildify "^3.0.2"
winreg "1.2.4"

autoprefixer@^9, autoprefixer@^9.8.6:
version "9.8.6"
resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-9.8.6.tgz#3b73594ca1bf9266320c5acf1588d74dea74210f"
Expand Down Expand Up @@ -13172,7 +13193,7 @@ unset-value@^1.0.0:
has-value "^0.3.1"
isobject "^3.0.0"

[email protected]:
[email protected], untildify@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/untildify/-/untildify-3.0.3.tgz#1e7b42b140bcfd922b22e70ca1265bfe3634c7c9"
integrity sha512-iSk/J8efr8uPT/Z4eSUywnqyrQU7DSdMfdqK4iWEaUVVmcP5JcnpRqmVMwcwcnmI1ATFNgC5V90u09tBynNFKA==
Expand Down Expand Up @@ -13855,6 +13876,11 @@ widest-line@^3.1.0:
dependencies:
string-width "^4.0.0"

[email protected]:
version "1.2.4"
resolved "https://registry.yarnpkg.com/winreg/-/winreg-1.2.4.tgz#ba065629b7a925130e15779108cf540990e98d1b"
integrity sha1-ugZWKbepJRMOFXeRCM9UCZDpjRs=

word-wrap@~1.2.3:
version "1.2.3"
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c"
Expand Down

0 comments on commit e969efb

Please sign in to comment.