import { app , BrowserWindow , ipcMain , shell , Menu } from "electron" ; import * as path from "path" ; import * as url from "url" ; import os = require ( 'os' ) ; import { SettingsService } from "./settings" ; import { AWSService } from "./aws" ; import { S3Service } from "./s3" ; import { RequestTracking } from "./request-tracking" ; import { JobManager } from "./job-manager" ; import { HistoryStorage } from "./history-storage" ; import { UpdaterService } from "./updater" ; import { AnalyticsService } from "./analytics" ; let homeDir = os . homedir ( ) ; let appDir = homeDir + "/S3Uploder/" ; import { GlobalEnv } from './environments/environment' ; import { AccountsService } from "./accounts" ; let mainWindow ; let settings ; let aws ; let accounts ; let s3 ; let tracking ; let jobs ; let histories ; let updater ; let analytics ; const DEBUG = process . mainModule . filename . indexOf ( 'app.asar' ) === - 1 ; ipcMain . on ( 'Application-Initialize' , ( event , arg ) => { initializeApp ( ) ; } ) ; ipcMain . on ( 'Application-OpenExternal' , ( event , arg ) => { shell . openExternal ( arg . address ) ; } ) ; ipcMain . on ( 'Application-ShowInFolder' , ( event , arg ) => { shell . showItemInFolder ( arg . path ) ; } ) ; ipcMain . on ( 'Application-OpenSecondary' , ( evetn , arg ) => { openSecondaryWindow ( arg . address ) ; } ) ; function openSecondaryWindow ( address ) { let aboutWindow = new BrowserWindow ( { height : 600 , width : 800 , } ) ; aboutWindow . setMenu ( null ) ; aboutWindow . loadURL ( formatUrl ( address ) ) ; } function formatUrl ( relativeUrl ) { let urlPath = "" ; if ( DEBUG ) { urlPath = url . format ( { pathname : path . join ( __dirname , `../app/frontend/dist/${ relativeUrl }` ) , protocol : "file:" , slashes : true , } ) ; } else { urlPath = url . format ( { pathname : path . join ( __dirname , `./frontend/dist/${ relativeUrl }` ) , protocol : "file:" , slashes : true , } ) ; } return urlPath ; } function initializeApp ( ) { accounts . initialize ( mainWindow ) ; settings . initialize ( mainWindow ) ; tracking . initialize ( mainWindow ) ; aws . initialize ( mainWindow ) ; jobs . initialize ( mainWindow ) ; s3 . initialize ( mainWindow , tracking , jobs ) ; histories . initialize ( mainWindow ) ; updater . initialize ( mainWindow , settings ) ; analytics . initialize ( mainWindow , settings ) ; } function createWindow ( ) { mainWindow = new BrowserWindow ( { height : 600 , width : 800 , } ) ; mainWindow . loadURL ( formatUrl ( 'index.html' ) ) ; mainWindow . maximize ( ) ; mainWindow . on ( "closed" , ( ) => { mainWindow = null ; } ) ; } app . on ( "ready" , ( ) => { settings = new SettingsService ( appDir ) ; aws = new AWSService ( ) ; s3 = new S3Service ( ) ; tracking = new RequestTracking ( appDir ) ; jobs = new JobManager ( ) ; histories = new HistoryStorage ( appDir ) ; updater = new UpdaterService ( appDir ) ; analytics = new AnalyticsService ( GlobalEnv . VERSION , GlobalEnv . GA_TRACKING_ID ) ; accounts = new AccountsService ( appDir ) ; createWindow ( ) ; } ) ; app . on ( "window-all-closed" , ( ) => { if ( process . platform !== "darwin" ) { app . quit ( ) ; } } ) ; app . on ( "activate" , ( ) => { if ( mainWindow === null ) { createWindow ( ) ; } } ) ;