Skip to content

Commit

Permalink
Merge pull request #66 from wakatime/bugfix/auto-update
Browse files Browse the repository at this point in the history
Check for updates every 30 minutes and at startup
  • Loading branch information
alanhamlett authored Oct 21, 2024
2 parents ae2f45d + 9b40de4 commit 5f1eb15
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ autoUpdater.on("update-downloaded", (res) => {
`Update Downloaded. Downloaded file: ${res.downloadedFile}, Version: ${res.version}, `,
);
autoUpdater.quitAndInstall();
app.relaunch();
});
autoUpdater.on("update-not-available", () => {
Logging.instance().log("Update not available");
Expand Down
18 changes: 12 additions & 6 deletions electron/watchers/wakatime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class Wakatime {
private lastCategory: Category = "coding";
private tray?: Tray | null;
private versionString: string;
private lastCheckedForUpdates: number = 0;

constructor() {
const version = `${getPlatfrom()}-wakatime/${app.getVersion()}`;
Expand All @@ -40,17 +41,14 @@ export class Wakatime {
Logging.instance().activateLoggingToFile();
}

Logging.instance().log("Starting WakaTime");

if (PropertiesManager.autoUpdateEnabled && !isDev) {
Logging.instance().log("Auto Update Enabled");
autoUpdater.checkForUpdatesAndNotify();
}
Logging.instance().log(`Starting WakaTime v${app.getVersion()}`);

if (SettingsManager.shouldRegisterAsLogInItem()) {
SettingsManager.registerAsLogInItem();
}

this.checkForUpdates();

Dependencies.installDependencies();

AppsManager.instance()
Expand Down Expand Up @@ -194,6 +192,7 @@ export class Wakatime {
}

await this.fetchToday();
this.checkForUpdates();
}

public async fetchToday() {
Expand Down Expand Up @@ -244,6 +243,13 @@ export class Wakatime {
}
}

public async checkForUpdates() {
if (!PropertiesManager.autoUpdateEnabled || isDev) return;
if (this.lastCheckedForUpdates + 600 * 1000 > Date.now()) return;

autoUpdater.checkForUpdatesAndNotify();
}

pluginString(appData?: AppData, windowInfo?: WindowInfo) {
const appName = windowInfo?.info.name || appData?.name;
if (!appName) {
Expand Down

0 comments on commit 5f1eb15

Please sign in to comment.