Skip to content

Commit

Permalink
fix: Fix autoupdate and telemetry issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Oct 23, 2023
1 parent 68c4f61 commit d3668d0
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 28 deletions.
1 change: 0 additions & 1 deletion xmcl-electron-app/esbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import pluginWorker from './plugins/esbuild.worker.plugin'
import pluginVueDevtools from './plugins/esbuild.devtool.plugin'
import pluginNode from './plugins/esbuild.node.plugin'
import plugin7Zip from './plugins/esbuild.native.plugin'
import pluginPrint from './plugins/esbuild.print.plugin'
import pluginStatic from './plugins/esbuild.static.plugin'
import pluginJsdetect from './plugins/esbuild.jschardet.plugin'
import { yamlPlugin } from 'esbuild-plugin-yaml'
Expand Down
12 changes: 0 additions & 12 deletions xmcl-electron-app/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,3 @@ import ElectronLauncherApp from './ElectronLauncherApp'
gracefulify(fs)

new ElectronLauncherApp().start()

// import '@xmcl/runtime/native.test'
// import * as keytar from 'keytar'
// import * as util from '@xmcl/windows-utils'
// import NodeChannel from 'node-datachannel'
// console.log('good')
// console.log(keytar)
// console.log(NodeChannel)
// console.log(util)
// NodeChannel.initLogger('Error', (l, m) => {
// console.log(l, m)
// })
4 changes: 2 additions & 2 deletions xmcl-electron-app/main/utils/updater.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AZURE_CDN, AZURE_MS_CDN, IS_DEV } from '@/constant'
import { AZURE_CDN, AZURE_MS_CDN, HAS_DEV_SERVER } from '@/constant'
import { ChecksumNotMatchError, download } from '@xmcl/file-transfer'
import { DownloadTask } from '@xmcl/installer'
import { BaseService } from '@xmcl/runtime'
Expand Down Expand Up @@ -281,7 +281,7 @@ export class ElectronUpdater implements LauncherAppUpdater {
}

async installUpdateAndQuit(updateInfo: ReleaseInfo): Promise<void> {
if (IS_DEV) {
if (HAS_DEV_SERVER) {
this.logger.log('Currently is development environment. Skip to install update')
return
}
Expand Down
1 change: 0 additions & 1 deletion xmcl-electron-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
},
"scripts": {
"build": "cross-env NODE_ENV=development tsx build.ts",
"build:appx": "cross-env NODE_ENV=production env BUILD_TARGET=appx npm run build",
"build:all": "cross-env NODE_ENV=production cross-env BUILD_TARGET=production npm run build",
"build:dir": "cross-env BUILD_TARGET=dir npm run build",
"postinstall": "electron-rebuild --only better-sqlite3",
Expand Down
6 changes: 6 additions & 0 deletions xmcl-keystone-ui/src/assets/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ a {
display: inline;
}

.markdown-body img {
height: auto;
max-width: 100%;
vertical-align: middle;
}

/* Curseforge */

.project-description {
Expand Down
2 changes: 1 addition & 1 deletion xmcl-runtime/lib/app/LauncherApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export class LauncherApp extends EventEmitter {
}

protected async onEngineReady() {
this.logger.log(`cwd: ${process.cwd()}`)
this.logger.log(`cwd: ${process.cwd()}. env: ${process.env.NODE_ENV}`)

// start the app
let app: InstalledAppManifest
Expand Down
1 change: 1 addition & 0 deletions xmcl-runtime/lib/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export const IS_DEV = process.env.NODE_ENV === 'development'
export const LAUNCHER_NAME = 'xmcl'
export const AZURE_CDN = 'https://xmcl-release.azureedge.net/releases'
export const RESOURCE_FILE_VERSION = 2
export const HAS_DEV_SERVER = !!process.env.HAS_DEV_SERVER
2 changes: 1 addition & 1 deletion xmcl-runtime/lib/entities/telemetry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InjectionKey } from '../util/objectRegistry'

export const APP_INSIGHT_KEY = '294f3664-8208-4963-a2b0-62405ff9d48e'
export const APP_INSIGHT_KEY = 'InstrumentationKey=294f3664-8208-4963-a2b0-62405ff9d48e;IngestionEndpoint=https://eastasia-0.in.applicationinsights.azure.com/;LiveEndpoint=https://eastasia.livediagnostics.monitor.azure.com/'

class _StackFrame {
// regex to match stack frames from ie/chrome/ff
Expand Down
19 changes: 13 additions & 6 deletions xmcl-runtime/lib/plugins/pluginTelemetry.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { PartialResourceHash, Resource, ResourceDomain, ResourceMetadata } from '@xmcl/runtime-api'
import { Contracts } from 'applicationinsights'
import type { Contracts } from 'applicationinsights'
import { randomUUID } from 'crypto'
import { LauncherAppPlugin } from '../app/LauncherApp'
import { IS_DEV } from '../constant'
import { kClientToken } from '../entities/clientToken'
import { kSettings } from '../entities/settings'
import { APP_INSIGHT_KEY, parseStack } from '../entities/telemetry'
import { LaunchService } from '../services/LaunchService'
import { NatService } from '../services/NatService'
import { ResourceService } from '../services/ResourceService'
import { UserService } from '../services/UserService'
import { NatService } from '../services/NatService'

export const pluginTelemetry: LauncherAppPlugin = async (app) => {
if (IS_DEV) {
return
}
process.env.APPLICATIONINSIGHTS_CONFIGURATION_CONTENT = '{}'
const appInsight = await import('applicationinsights')
const contract = new appInsight.Contracts.ContextTagKeys()

Expand All @@ -37,6 +35,15 @@ export const pluginTelemetry: LauncherAppPlugin = async (app) => {
tags[contract.applicationVersion] = IS_DEV ? '0.0.0' : `${app.version}#${app.build}`
tags[contract.operationParentId] = 'root'

appInsight.defaultClient.trackEvent({
name: 'app-start',
properties: { },
})

app.registryDisposer(async () => {
appInsight.defaultClient.flush()
})

app.on('engine-ready', async () => {
const settings = await app.registry.get(kSettings)
app.registry.getOrCreate(NatService).then(async (service) => {
Expand Down Expand Up @@ -99,7 +106,7 @@ export const pluginTelemetry: LauncherAppPlugin = async (app) => {
})

const createExceptionDetails = (msg?: string, name?: string, stack?: string) => {
const d = new Contracts.ExceptionDetails()
const d = new appInsight.Contracts.ExceptionDetails()
d.message = msg?.substring(0, 32768) || ''
d.typeName = name?.substring(0, 1024) || ''
d.parsedStack = parseStack(stack) as any
Expand Down
4 changes: 2 additions & 2 deletions xmcl-runtime/lib/plugins/pluginWorker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFile, writeFile } from 'fs/promises'
import { Worker } from 'worker_threads'
import { LauncherAppPlugin } from '../app/LauncherApp'
import { IS_DEV } from '../constant'
import { HAS_DEV_SERVER } from '../constant'
import { EncodingWorker, kEncodingWorker } from '../entities/encodingWorker'
import { kResourceWorker, ResourceWorker, WorkerResponse } from '../entities/resourceWorker'
import { checksum } from '../util/fs'
Expand All @@ -11,7 +11,7 @@ import createEncodingWorker, { path as encodingWorkerPath } from '../workers/enc
export const pluginWorker: LauncherAppPlugin = async (app) => {
const logger = app.getLogger('WorkerManager')
const checkUpdate = async (path: string) => {
if (!IS_DEV) {
if (!HAS_DEV_SERVER) {
logger.log('Try to update worker js as this is PROD')
const workerJsPath = path.replace('.unpacked', '')
const asarWorkerJsPath = path
Expand Down
4 changes: 2 additions & 2 deletions xmcl-runtime/lib/services/BaseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import os, { freemem, totalmem } from 'os'
import { join } from 'path'
import { LauncherApp } from '../app/LauncherApp'
import { LauncherAppKey } from '../app/utils'
import { IS_DEV } from '../constant'
import { HAS_DEV_SERVER } from '../constant'
import { kClientToken } from '../entities/clientToken'
import { PathResolver, kGameDataPath } from '../entities/gameDataPath'
import { kSettings } from '../entities/settings'
Expand Down Expand Up @@ -88,7 +88,7 @@ export class BaseService extends AbstractService implements IBaseService {
*/
@Singleton()
async checkUpdate() {
if (IS_DEV) return
if (HAS_DEV_SERVER) return
try {
const settings = await this.getSettings()
this.log('Check update')
Expand Down

0 comments on commit d3668d0

Please sign in to comment.