Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): bump @sentry/electron from 3.0.4 to 5.0.0 #1641

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"test": "jest",
"test:e2e": "playwright test --workers=1",
"compile": "cross-env 'NODE_OPTIONS=\"--max-old-space-size=4096\"' electron-webpack",
"dist:win": "electron-builder --x64 --ia32 --win portable msi nsis",
"dist:mac": "electron-builder --mac --x64 --arm64",
"dist:mac-local": "CSC_IDENTITY_AUTO_DISCOVERY=false electron-builder --mac dmg",
"dist:linux": "electron-builder --linux",
"dist:win": "cross-env ELECTRON_FORCE_IS_PACKAGED=true electron-builder --x64 --ia32 --win portable msi nsis",
"dist:mac": "cross-env ELECTRON_FORCE_IS_PACKAGED=true electron-builder --mac --x64 --arm64",
"dist:mac-local": "cross-env ELECTRON_FORCE_IS_PACKAGED=true CSC_IDENTITY_AUTO_DISCOVERY=false electron-builder --mac dmg",
"dist:linux": "cross-env ELECTRON_FORCE_IS_PACKAGED=true electron-builder --linux",
"lint": "eslint src/",
"lint:fix": "eslint --fix src/",
"lint:test": "eslint -c tests/.eslintrc.json 'tests/**/*.ts*'",
Expand Down Expand Up @@ -96,7 +96,6 @@
"jszip"
]
},
"//build.extraResources": "Static should be set again because it is overwritten",
"build": {
"generateUpdatesFilesForAllChannels": true,
"appId": "fr.gouv.social.fabrique.archifiltre.docs",
Expand Down Expand Up @@ -223,8 +222,8 @@
"csv-stringify": "^5.6.4",
"deep-equal": "2.0.5",
"dotenv": "^16.0.0",
"electron": "^18.3.7",
"electron-builder": "^23.0.3",
"electron": "^18.3.15",
"electron-builder": "^23.6.0",
"electron-webpack": "^2.8.2",
"electron-webpack-ts": "^4.0.1",
"eslint": "^7",
Expand All @@ -246,7 +245,7 @@
"rmfr": "2.0.0",
"sass": "^1.49.9",
"sass-loader": "10",
"semantic-release": "^19.0.3",
"semantic-release": "19.0.5",
"stdio-mock": "^1.1.0",
"ts-jest": "27.1.4",
"tsconfig-paths": "^4.1.0",
Expand All @@ -263,7 +262,7 @@
"@emeraldpay/hashicon-react": "^0.5.1",
"@material-ui/core": "^4.11.4",
"@material-ui/lab": "^4.0.0-alpha.60",
"@sentry/electron": "^3.0.4",
"@sentry/electron": "^5.0.0",
"angular-expressions": "^1.1.4",
"axios": "^0.28.0",
"csv-parse": "^4.15.4",
Expand Down
7 changes: 4 additions & 3 deletions src/common/modules/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function initTracking(): Promise<void> {
await getTrackerProvider().init();
if (IS_MAIN) {
ipcMain.on("tracking.toggle", (_, enable) => {
toggleTracking(enableTracking === enable);
toggleTracking((enableTracking = enable as boolean));
});
}
}
Expand All @@ -26,7 +26,7 @@ export function toggleTracking(enable = !enableTracking): void {
}
}

const provider: TrackerProvider | null = null;
let provider: TrackerProvider | null = null;
function findProvider(name?: ProviderType): TrackerProvider {
const appId = getConfig("appId");
const disabled = !enableTracking;
Expand All @@ -50,5 +50,6 @@ export function getTrackerProvider(): TrackerProvider {
return provider;
}

return findProvider(process.env.TRACKER_PROVIDER as ProviderType);
provider = findProvider(process.env.TRACKER_PROVIDER as ProviderType);
return provider;
}
71 changes: 45 additions & 26 deletions src/common/tracker/provider/PostHogProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { version } from "@common/utils/package";
import type { Integration } from "@sentry/types";
import { totalmem } from "os";
import type FrontPostHog from "posthog-js";
import type NodeJsPostHog from "posthog-node";

Expand All @@ -10,18 +13,26 @@ import { TrackerProvider } from "./TrackerProvider";
const TRACKER_FAKE_HOST = (process.env.TRACKER_FAKE_HREF ?? "").split("//")[1]!;

const DEFAULT_$SET = {
// eslint-disable-next-line @typescript-eslint/naming-convention
$current_url: process.env.TRACKER_FAKE_HREF,
$host: TRACKER_FAKE_HOST,
$pathname: "",
};
const DEFAULT_$SET_ONCE = {
// eslint-disable-next-line @typescript-eslint/naming-convention
$initial_current_url: process.env.TRACKER_FAKE_HREF,
// eslint-disable-next-line @typescript-eslint/naming-convention
$initial_pathname: "",
$pathname: "",
};

function getCommonProperties() {
return {
arch: process.arch,
date: new Date(),
os: process.platform,
ram: totalmem() / 1024 / 1024 / 1024,
version,
};
}

export class PostHogProvider extends TrackerProvider<
typeof FrontPostHog,
NodeJsPostHog
Expand Down Expand Up @@ -51,30 +62,30 @@ export class PostHogProvider extends TrackerProvider<
this.tracker.capture({
distinctId: this.appId,
event: "$identify",
properties: getCommonProperties(),
});
this.inited = true;
} else {
return new Promise<void>(
(resolve) =>
void import("posthog-js").then(({ default: frontPostHog }) => {
this.hijackPostHog(frontPostHog);
frontPostHog.init(process.env.TRACKER_POSTHOG_API_KEY, {
/* eslint-disable @typescript-eslint/naming-convention */
api_host: process.env.TRACKER_POSTHOG_URL,
autocapture: false,
capture_pageview: false,
disable_session_recording: true,
loaded: (posthog) => {
this.tracker = posthog;
this.tracker.identify(this.appId);
this.inited = true;
resolve();
},
/* eslint-enable @typescript-eslint/naming-convention */
});
})
);
return;
}

return new Promise<void>(
(resolve) =>
void import("posthog-js").then(({ default: frontPostHog }) => {
this.hijackPostHog(frontPostHog);
frontPostHog.init(process.env.TRACKER_POSTHOG_API_KEY, {
api_host: process.env.TRACKER_POSTHOG_URL,
autocapture: false,
capture_pageview: false,
disable_session_recording: true,
loaded: (posthog) => {
this.tracker = posthog;
this.tracker.identify(this.appId, getCommonProperties());
this.inited = true;
resolve();
},
});
})
);
}

public async uninit(): Promise<void> {
Expand All @@ -101,7 +112,13 @@ export class PostHogProvider extends TrackerProvider<

public track<TEvent extends TrackEvent>(...args: TrackArgs<TEvent>): void {
const [event, properties] = args;
if (!this.tracker || this.disabled) return;
if (!this.tracker || this.disabled) {
disabled: this.disabled,
tracker: this.tracker,
});
return;
}

if (this.isMain(this.tracker)) {
this.tracker.capture({
distinctId: this.appId,
Expand All @@ -111,12 +128,15 @@ export class PostHogProvider extends TrackerProvider<
} else {
this.tracker.capture(event, properties);
}
console.log(`Event ${event} tracked successfully`);
}

public enable(): void {
if (!this.tracker) return;
if (!this.isMain(this.tracker)) {
this.tracker.opt_in_capturing();
const optInProperties = getCommonProperties();
this.tracker.capture("$opt_in", optInProperties);
}
super.enable();
}
Expand All @@ -139,7 +159,6 @@ export class PostHogProvider extends TrackerProvider<
const originalCaptureFn = posthog.capture.bind(posthog);
const hijack = {
$set: DEFAULT_$SET,
// eslint-disable-next-line @typescript-eslint/naming-convention
$set_once: DEFAULT_$SET_ONCE,
...DEFAULT_$SET,
};
Expand Down
2 changes: 1 addition & 1 deletion src/common/tracker/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type TrackErrorId = string & { readonly _trackErrorId?: never };
* Tracking Plan props representation.
*/
export interface TrackCoreEventProps {
"App Closed": { date: Date };
"App Closed": { date: Date; version: string };
"App First Opened": {
arch: string;
date: Date;
Expand Down
20 changes: 6 additions & 14 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,18 @@ const askBeforeLeaving = () => {
}
event.preventDefault();
const language = getLanguage();
let title = "";
let message = "";
let detail = "";
let no = "";
let yes = "";
let title = "Bye bye!";
let message = "Are you sure you want to leave?";
let detail = "All data that has not been saved will be permanently lost!";
let no = "No";
let yes = "Yes";
if (language === "fr") {
title = "Bye bye !";
message = "Êtes-vous sûr•e de vouloir quitter ?";
detail =
"Toutes les données qui n'ont pas été sauvegardées seront perdues définitivement !";
no = "Non";
yes = "Oui";
} else {
title = "Bye bye!";
message = "Are you sure you want to leave?";
detail = "All data that has not been saved will be permanently lost!";
no = "No";
yes = "Yes";
}
const options = {
buttons: [no, yes],
Expand Down Expand Up @@ -174,8 +168,6 @@ void app.whenReady().then(() => {
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on("ready", async () => {
// -- init all "modules"
// TODO: do real modules
await initNewUserConfig();
await initTracking();
loadHash();
Expand Down Expand Up @@ -221,7 +213,7 @@ app.on("activate", async () => {

app.on("will-quit", async (event) => {
event.preventDefault();
getTrackerProvider().track("App Closed", { date: new Date() });
getTrackerProvider().track("App Closed", { date: new Date(), version });
await sleep(1000);
process.exit();
});
Expand Down
4 changes: 3 additions & 1 deletion webpack.main.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ require("dotenv").config();

module.exports =
/** @param {import("webpack").Configuration} config */ function (config) {
const isProd = config.mode === "production";

const workers = glob
.sync("./src/main/**/*.worker.ts")
.map((filePath) => {
Expand All @@ -17,7 +19,7 @@ module.exports =
return acc;
}, {});

if (config.mode === "production") {
if (isProd) {
for (const plugin of config.plugins) {
if (plugin instanceof webpack.BannerPlugin) {
plugin.options.exclude = /(preload|\.worker)\.js$/i;
Expand Down
4 changes: 3 additions & 1 deletion webpack.renderer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ require("dotenv").config();

module.exports =
/** @param {import("webpack").Configuration} config */ function (config) {
const isProd = config.mode === "production";

const workers = glob
.sync("./src/renderer/**/*.fork.ts")
.map((filePath) => {
Expand Down Expand Up @@ -46,7 +48,7 @@ module.exports =
// }
// });

if (config.mode === "production") {
if (isProd) {
if (!config.plugins?.length) {
config.plugins = [];
}
Expand Down
Loading
Loading