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
@@ -51,6 +53,7 @@ export class ServerService implements OnApplicationBootstrap {
51
53
sessionId : this . sessionId ,
52
54
appType : ServerService . getAppType ( SERVER_CONFIG . buildType ) ,
53
55
appVersion : SERVER_CONFIG . appVersion ,
56
+ packageType : ServerService . getPackageType ( SERVER_CONFIG . buildType ) ,
54
57
...( await this . featuresConfigService . getControlInfo ( ) ) ,
55
58
} ) ;
56
59
@@ -63,6 +66,7 @@ export class ServerService implements OnApplicationBootstrap {
63
66
osPlatform : process . platform ,
64
67
buildType : SERVER_CONFIG . buildType ,
65
68
port : SERVER_CONFIG . port ,
69
+ packageType : ServerService . getPackageType ( SERVER_CONFIG . buildType ) ,
66
70
} ,
67
71
nonTracking : true ,
68
72
} ) ;
@@ -88,6 +92,7 @@ export class ServerService implements OnApplicationBootstrap {
88
92
appType : ServerService . getAppType ( SERVER_CONFIG . buildType ) ,
89
93
encryptionStrategies : await this . encryptionService . getAvailableEncryptionStrategies ( ) ,
90
94
fixedDatabaseId : REDIS_STACK_CONFIG ?. id ,
95
+ packageType : ServerService . getPackageType ( SERVER_CONFIG . buildType ) ,
91
96
...( await this . featuresConfigService . getControlInfo ( ) ) ,
92
97
} ;
93
98
this . logger . log ( 'Succeed to get server info.' ) ;
@@ -110,4 +115,47 @@ export class ServerService implements OnApplicationBootstrap {
110
115
return AppType . Unknown ;
111
116
}
112
117
}
118
+
119
+ static getPackageType ( buildType : string ) : PackageType {
120
+ if ( buildType === BuildType . Electron ) {
121
+ // Darwin
122
+ if ( process . platform === 'darwin' ) {
123
+ if ( process . env . mas || process [ 'mas' ] ) {
124
+ return PackageType . Mas ;
125
+ }
126
+
127
+ return PackageType . UnknownDarwin ;
128
+ }
129
+
130
+ // Linux
131
+ if ( process . platform === 'linux' ) {
132
+ if ( process . env . APPIMAGE ) {
133
+ return PackageType . AppImage ;
134
+ }
135
+
136
+ if ( process . env . SNAP_INSTANCE_NAME || process . env . SNAP_DATA ) {
137
+ return PackageType . Snap ;
138
+ }
139
+
140
+ if ( process . env . container ) {
141
+ return PackageType . Flatpak ;
142
+ }
143
+
144
+ return PackageType . UnknownLinux ;
145
+ }
146
+
147
+ // Windows
148
+ if ( process . platform === 'win32' ) {
149
+ if ( process . env . windowsStore || process [ 'windowsStore' ] ) {
150
+ return PackageType . WindowsStore ;
151
+ }
152
+
153
+ return PackageType . UnknownWindows ;
154
+ }
155
+
156
+ return PackageType . Unknown ;
157
+ }
158
+
159
+ return undefined ;
160
+ }
113
161
}
0 commit comments