1
- import { Injectable , InternalServerErrorException , Logger , OnApplicationBootstrap } from '@nestjs/common' ;
1
+ import {
2
+ Injectable , InternalServerErrorException , Logger , OnApplicationBootstrap ,
3
+ } from '@nestjs/common' ;
2
4
import { EventEmitter2 } from '@nestjs/event-emitter' ;
3
5
import config , { Config } from 'src/utils/config' ;
4
6
import { AppAnalyticsEvents } from 'src/constants/app-events' ;
5
7
import { TelemetryEvents } from 'src/constants/telemetry-events' ;
6
8
import { ServerInfoNotFoundException } from 'src/constants/exceptions' ;
7
9
import { EncryptionService } from 'src/modules/encryption/encryption.service' ;
8
10
import { ServerRepository } from 'src/modules/server/repositories/server.repository' ;
9
- import { AppType , BuildType } from 'src/modules/server/models/server' ;
11
+ import { AppType , BuildType , PackageType } from 'src/modules/server/models/server' ;
10
12
import { GetServerInfoResponse } from 'src/modules/server/dto/server.dto' ;
11
13
import { FeaturesConfigService } from 'src/modules/feature/features-config.service' ;
12
14
@@ -88,6 +90,7 @@ export class ServerService implements OnApplicationBootstrap {
88
90
appType : ServerService . getAppType ( SERVER_CONFIG . buildType ) ,
89
91
encryptionStrategies : await this . encryptionService . getAvailableEncryptionStrategies ( ) ,
90
92
fixedDatabaseId : REDIS_STACK_CONFIG ?. id ,
93
+ packageType : ServerService . getPackageType ( SERVER_CONFIG . buildType ) ,
91
94
...( await this . featuresConfigService . getControlInfo ( ) ) ,
92
95
} ;
93
96
this . logger . log ( 'Succeed to get server info.' ) ;
@@ -110,4 +113,47 @@ export class ServerService implements OnApplicationBootstrap {
110
113
return AppType . Unknown ;
111
114
}
112
115
}
116
+
117
+ static getPackageType ( buildType : string ) : PackageType {
118
+ if ( buildType === BuildType . Electron ) {
119
+ // Darwin
120
+ if ( process . platform === 'darwin' ) {
121
+ if ( process . env . mas || process [ 'mas' ] ) {
122
+ return PackageType . Mas ;
123
+ }
124
+
125
+ return PackageType . UnknownDarwin ;
126
+ }
127
+
128
+ // Linux
129
+ if ( process . platform === 'linux' ) {
130
+ if ( process . env . APPIMAGE ) {
131
+ return PackageType . AppImage ;
132
+ }
133
+
134
+ if ( process . env . SNAP_INSTANCE_NAME || process . env . SNAP_DATA ) {
135
+ return PackageType . Snap ;
136
+ }
137
+
138
+ if ( process . env . container ) {
139
+ return PackageType . Flatpak ;
140
+ }
141
+
142
+ return PackageType . UnknownLinux ;
143
+ }
144
+
145
+ // Windows
146
+ if ( process . platform === 'win32' ) {
147
+ if ( process . env . windowsStore || process [ 'windowsStore' ] ) {
148
+ return PackageType . WindowsStore ;
149
+ }
150
+
151
+ return PackageType . UnknownWindows ;
152
+ }
153
+
154
+ return PackageType . Unknown ;
155
+ }
156
+
157
+ return undefined ;
158
+ }
113
159
}
0 commit comments