Socialify

Folder ..

Viewing login-page.component.ts
78 lines (64 loc) • 3.2 KB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-misused-promises */
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { ElectronService } from 'ngx-electron';

@Component({
  selector: 'app-login-page',
  templateUrl: './login-page.component.html',
  styleUrls: ['./login-page.component.scss']
})
export class LoginPageComponent implements OnInit {

  constructor(private _electronService: ElectronService, private router: Router) { }

  ngOnInit(): void {
  }

  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
  async setTheme(theme: string) {
    const themeInvoker = await this._electronService.ipcRenderer.invoke('currentTheme');
    const currentSelectedTheme = themeInvoker.scheme; // light, dark or system
    const isCurrentColorSchemeDark = themeInvoker.darkColorsUsed; // dark = true or false
    const currentSelectedThemeElement = document.getElementsByClassName('selected')[0];
    currentSelectedThemeElement.classList.remove('selected');
    document.getElementById(theme).classList.add('selected');

    // Dark theme is clicked and the system theme is selected currently and the current system theme is light
    // or Dark theme is clicked and the light theme is selected currently
    // then go ahead and toggle the dark mode

    if (theme === 'dark' && currentSelectedTheme === 'system' && !isCurrentColorSchemeDark || theme === 'dark' && currentSelectedTheme === 'light') {
      await this._electronService.ipcRenderer.invoke('dark-mode:toggle');
    }

    // light theme is clicked and the system theme is selected currently and the current system theme is dark
    // or light theme is clicked and the dark theme is selected currently
    // then go ahead and toggle the light mode

    if (theme === 'light' && currentSelectedTheme === 'system' && isCurrentColorSchemeDark || theme === 'light' && currentSelectedTheme === 'dark') {
      await this._electronService.ipcRenderer.invoke('dark-mode:toggle');
    }

    // system theme is clicked

    if (theme === 'system') {
      await this._electronService.ipcRenderer.invoke('dark-mode:system');
    }
  }

  showDataIsSafeDialog() {
    const options = {
      type: 'info',
      buttons: ['Yes, please', 'No, thanks'],
      defaultId: 1,
      title: 'Question',
      message: 'That is a great question!',
      detail: 'Gravity recieves no data at all. Whatever login info is fetched from GitHub, is all stored on your local system. Gravity\'s code is open-source and available for your review. Do you want me to take you to the code repository?',
    };

    this._electronService.remote.dialog.showMessageBox(null, options).then(response => {
      if (response.response === 0) {
        this._electronService.remote.shell.openExternal('https://github.com/luciferreeves/gravity/');
      }
    });

  }

  authenticate() {
    this._electronService.ipcRenderer.send('github-oauth', 'getToken');
    this._electronService.ipcRenderer.on('github-oauth-reply', (event, { access_token }) => {
      localStorage.setItem('githubOAuthToken', access_token);
      this.router.navigate(['home']);
      window.location.reload();
    });
  }
}