Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
✨ Adding Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
i1u5 committed Mar 17, 2020
1 parent 38d02ec commit 54a56eb
Show file tree
Hide file tree
Showing 9 changed files with 382 additions and 38 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ jobs:
yarn run dist
- name: Building
run: yarn run build
env:
DSN: ${{ secrets.DSN }}
- name: Building AppImage
run: |
jq -c '.productName = "PreMiD Portable"' ./dist/app/package.json > tmp.$$.json && mv tmp.$$.json ./dist/app/package.json
yarn run build:n-appimage
env:
DSN: ${{ secrets.DSN }}
- name: Release
uses: softprops/action-gh-release@v1
with:
Expand Down Expand Up @@ -74,6 +78,8 @@ jobs:
yarn run dist
- name: Building
run: yarn run build
env:
DSN: ${{ secrets.DSN }}
- name: Release
uses: softprops/action-gh-release@v1
with:
Expand All @@ -91,3 +97,4 @@ jobs:
yarn run build:appimage
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DSN: ${{ secrets.DSN }}
8 changes: 8 additions & 0 deletions @types/PreMiD/ExtensionSettings.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
export default interface ExtensionSettings {
/**
* If it's the first run of the app
*/
firstLaunch: boolean;
/**
* If the user approved to use the automatic crash reporter
*/
improvementProgramme: boolean;
/**
* If extension is enabled
*/
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"typescript": "3.8.3"
},
"dependencies": {
"@sentry/electron": "1.3.0",
"auto-launch": "5.0.5",
"discord-rpc": "github:discordjs/RPC",
"electron-store": "5.1.1",
Expand Down
42 changes: 40 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import "source-map-support/register";
import * as Sentry from "@sentry/electron";

import { app, dialog } from "electron";
import { app, dialog, shell } from "electron";
import { init as initSocket, socket } from "./managers/socketManager";
import { update as initAutoLaunch } from "./managers/launchManager";
import { checkForUpdate } from "./util/updateChecker";
import { TrayManager } from "./managers/trayManager";
import { settings } from "./managers/settingsManager";
import { checkForUpdate } from "./util/updateChecker";

export let trayManager: TrayManager;

Expand All @@ -13,6 +15,32 @@ export let trayManager: TrayManager;
//* When app is ready
export let updateCheckerInterval = null;
app.whenReady().then(async () => {
if (settings.get("firstLaunch")) {
settings.set("firstLaunch", false);
dialog
.showMessageBox({
message: "Welcome to PreMiD!",
detail:
"In order to work, the browser extension is also required, would you like to install it now?",
buttons: ["I already have it", "Show me"],
type: "question",
cancelId: 0,
defaultId: 0,
checkboxLabel: "Also enable automatic crash reporting",
checkboxChecked: true
})
.then(async value => {
if (value.checkboxChecked) await initReporter(true);
switch (value.response) {
case 1:
shell.openExternal("https://premid.app/downloads#ext-downloads");
break;
}
});
} else {
await initReporter();
}

trayManager = new TrayManager();
await initAutoLaunch();
await initSocket();
Expand All @@ -25,6 +53,16 @@ app.whenReady().then(async () => {
}
});

async function initReporter(firstLaunch: boolean = false) {
if (firstLaunch) settings.set("improvementProgramme", true);
if (settings.get("improvementProgramme")) {
console.log("Initializing Sentry...");
Sentry.init({
dsn: process.env.DSN
});
}
}

//* If second instance started, close old one
app.on("second-instance", () => app.exit(0));

Expand Down
6 changes: 5 additions & 1 deletion src/managers/discordManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ class RPCClient {

if (!this.clientReady || !presenceData) return;

presenceData.presenceData.largeImageText += ` App v${app.getVersion()}`;
// Workaround
if(presenceData.presenceData.largeImageText && presenceData.presenceData.largeImageText.includes("PreMiD")) {
presenceData.presenceData.largeImageText = "PreMiD 🐧 v" + app.getVersion();
}

this.client
.setActivity(presenceData.presenceData)
.catch(() => this.destroy());
Expand Down
7 changes: 4 additions & 3 deletions src/managers/settingsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import ExtensionSettings from "../../@types/PreMiD/ExtensionSettings";
//* Export and set default settings
export let settings = new ElectronStore({
defaults: {
autoLaunch: true
firstLaunch: true,
autoLaunch: true,
improvementProgramme: false
}
});

Expand All @@ -16,12 +18,11 @@ export let settings = new ElectronStore({
* @param extensionSettings Settings from extension
*/
export function update(extensionSettings: ExtensionSettings) {
//* remove title if disabled
//* Update autolaunch if updated
//* Save Settings
console.log("Updated settings");
if (settings.get("autoLaunch") != extensionSettings.autoLaunch) {
settings.set("autoLaunch", extensionSettings.autoLaunch);
updateAutoLaunch();
console.log("Updated settings");
}
}
4 changes: 1 addition & 3 deletions src/managers/trayManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import { trayManager } from "..";
import { checkForUpdate, updateProcess } from "../util/updateChecker";
import { connected } from "./socketManager";

let trayIcon = join(__dirname, "../assets/tray/[email protected]");
export class TrayManager {
tray: Tray;

constructor() {
this.tray = new Tray(trayIcon);
this.tray = new Tray(join(__dirname, "../assets/tray/[email protected]"));
this.tray.setToolTip(app.name);

this.tray.on("right-click", () => this.update());
Expand All @@ -19,7 +18,6 @@ export class TrayManager {
this.tray.setContextMenu(
Menu.buildFromTemplate([
{
icon: join(__dirname, "../assets/tray/Icon.png"),
label: `${app.name} v${app.getVersion()}`,
enabled: false
},
Expand Down
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
"removeComments": true,
"esModuleInterop": true,
"inlineSourceMap": true,
"inlineSources": true,
"sourceRoot": "/",
"skipLibCheck": true,
"noUnusedParameters": true,
"noUnusedLocals": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
}
Loading

0 comments on commit 54a56eb

Please sign in to comment.