"Fossies" - the Fresh Open Source Software Archive

Member "deltachat-desktop-1.3.4/src/main/deltachat/login.ts" (18 May 2020, 4533 Bytes) of package /linux/misc/deltachat-desktop-1.3.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "login.ts": 1.3.3_vs_1.3.4.

    1 import { DeltaChat } from 'deltachat-node'
    2 import { app } from 'electron'
    3 import logger from '../../shared/logger'
    4 import { setupMarkseenFix } from '../markseenFix'
    5 import setupNotifications from '../notifications'
    6 import setupUnreadBadgeCounter from '../unread-badge'
    7 import SplitOut from './splitout'
    8 import DeltaChatController from './controller'
    9 import { Credentials } from '../../shared/shared-types'
   10 const log = logger.getLogger('main/deltachat/login')
   11 
   12 export interface credential_config extends Credentials {
   13   mail_security?: string
   14   send_security?: string
   15   mail_pw?: string
   16   [key: string]: string
   17 }
   18 
   19 export default class DCLoginController extends SplitOut {
   20   /**
   21    * Called when this controller is created and when current
   22    * locale changes
   23    */
   24   setCoreStrings(strings: { [key: number]: string }) {
   25     if (!this._dc) return
   26 
   27     Object.keys(strings).forEach(key => {
   28       this._dc.setStockTranslation(Number(key), strings[Number(key)])
   29     })
   30 
   31     this._controller._sendStateToRenderer()
   32   }
   33 
   34   login(
   35     accountDir: string,
   36     credentials: credential_config,
   37     sendStateToRenderer: typeof DeltaChatController.prototype._sendStateToRenderer,
   38     coreStrings: Parameters<
   39       typeof DCLoginController.prototype.setCoreStrings
   40     >[0],
   41     updateConfiguration = false
   42   ) {
   43     // Creates a separate DB file for each login
   44     this._controller.accountDir = accountDir
   45     log.info(`Using deltachat instance ${this._controller.accountDir}`)
   46     const dc = new DeltaChat()
   47     this._controller._dc = dc
   48     this._controller.credentials = credentials
   49     this._controller._sendStateToRenderer = sendStateToRenderer
   50 
   51     if (!DeltaChat.maybeValidAddr(credentials.addr)) {
   52       this._controller.sendToRenderer(
   53         'error',
   54         this._controller.translate('bad_email_address')
   55       )
   56       return
   57     }
   58 
   59     this._dc.open(this._controller.accountDir, (err: any) => {
   60       if (err) throw err
   61       this.setCoreStrings(coreStrings)
   62       const onReady = () => {
   63         log.info('Ready')
   64         this._controller.ready = true
   65         this._controller.configuring = false
   66         this._controller.emit('ready', this._controller.credentials)
   67         log.info('dc_get_info', dc.getInfo())
   68         this.updateDeviceChats()
   69         sendStateToRenderer()
   70       }
   71       if (!this._dc.isConfigured() || updateConfiguration) {
   72         this._dc.once('ready', onReady)
   73         this._controller.configuring = true
   74         this._dc.configure(this.addServerFlags(credentials), undefined)
   75         sendStateToRenderer()
   76       } else {
   77         onReady()
   78       }
   79     })
   80     this._controller.registerEventHandler(dc)
   81     setupNotifications(this._controller, (app as any).state.saved)
   82     setupUnreadBadgeCounter(this._controller)
   83     setupMarkseenFix(this._controller)
   84   }
   85 
   86   logout() {
   87     this.close()
   88     this._controller._resetState()
   89 
   90     log.info('Logged out')
   91     this._controller.emit('logout')
   92     if (typeof this._controller._sendStateToRenderer === 'function')
   93       this._controller._sendStateToRenderer()
   94   }
   95 
   96   configure(
   97     credentials: any,
   98     cb: Parameters<typeof DeltaChat.prototype.configure>[1]
   99   ) {
  100     this._controller.configuring = true
  101     this._dc.configure(this.addServerFlags(credentials), cb)
  102   }
  103 
  104   close() {
  105     if (!this._dc) return
  106     this._dc.close()
  107     this._controller._dc = null
  108   }
  109 
  110   addServerFlags(credentials: any) {
  111     return Object.assign({}, credentials, {
  112       server_flags: this._controller.settings.serverFlags(credentials),
  113     })
  114   }
  115 
  116   updateDeviceChats() {
  117     this._dc.updateDeviceChats()
  118     this._dc.addDeviceMessage(
  119       'changelog-version-1.3.0-1',
  120       `Changes in v1.3.0
  121 
  122 - QR codes can now be scanned from desktop as you know it from Android/iOS. Try
  123   it out by clicking on Menu -> Scan QR code. Besides using any available webcam,
  124   you can also scan a qr code by importing a picture of it. This way we can 
  125   finally join verified groups from desktop!
  126 - Support for openpgp4fpr urls. They allow you to do the same things as with qr
  127   codes, but the information is baked into an url. Wanna try it out? Try to
  128   login to our support forum (https://support.delta.chat) with DeltaChat and the
  129   "Manual link" option :)
  130 - You can now pin chats. This will make sure they stay on the top of your list
  131   of chats.
  132 - It's now possible to change the name of a contact in the same way as it's with
  133   changing the name of a group.
  134 
  135 Full changelog: https://github.com/deltachat/deltachat-desktop/blob/master/CHANGELOG.md#130---2020-04-30
  136     ` as any
  137     )
  138   }
  139 }