mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-18 08:43:57 +00:00
feat: auto install default false on linux and friend request notification
This commit is contained in:
@@ -4,11 +4,17 @@ import updater from "electron-updater";
|
||||
|
||||
const { autoUpdater } = updater;
|
||||
|
||||
const restartAndInstallUpdate = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||
export const restartAndInstallUpdate = async () => {
|
||||
autoUpdater.removeAllListeners();
|
||||
if (app.isPackaged) {
|
||||
autoUpdater.quitAndInstall(false);
|
||||
}
|
||||
};
|
||||
|
||||
registerEvent("restartAndInstallUpdate", restartAndInstallUpdate);
|
||||
const restartAndInstallUpdateEvent = async (
|
||||
_event: Electron.IpcMainInvokeEvent
|
||||
) => {
|
||||
restartAndInstallUpdate();
|
||||
};
|
||||
|
||||
registerEvent("restartAndInstallUpdate", restartAndInstallUpdateEvent);
|
||||
|
||||
@@ -1,17 +1,35 @@
|
||||
import { registerEvent } from "../register-event";
|
||||
import { HydraApi } from "@main/services";
|
||||
import { publishNewFriendRequestNotification } from "@main/services/notifications";
|
||||
import { UserNotLoggedInError } from "@shared";
|
||||
import type { FriendRequestSync } from "@types";
|
||||
|
||||
interface SyncState {
|
||||
friendsRequest: number | null;
|
||||
}
|
||||
|
||||
const syncState: SyncState = {
|
||||
friendsRequest: null,
|
||||
};
|
||||
|
||||
const syncFriendRequests = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||
return HydraApi.get<FriendRequestSync>(`/profile/friend-requests/sync`).catch(
|
||||
(err) => {
|
||||
return HydraApi.get<FriendRequestSync>(`/profile/friend-requests/sync`)
|
||||
.then((res) => {
|
||||
if (
|
||||
syncState.friendsRequest &&
|
||||
syncState.friendsRequest < res.friendRequestCount
|
||||
) {
|
||||
publishNewFriendRequestNotification();
|
||||
}
|
||||
|
||||
syncState.friendsRequest = res.friendRequestCount;
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err instanceof UserNotLoggedInError) {
|
||||
return { friendRequests: [] };
|
||||
return { friendRequestCount: 0 } as FriendRequestSync;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
registerEvent("syncFriendRequests", syncFriendRequests);
|
||||
|
||||
@@ -12,6 +12,7 @@ import { logger } from "../logger";
|
||||
import { WindowManager } from "../window-manager";
|
||||
import type { Game, UserPreferences } from "@types";
|
||||
import { db, levelKeys } from "@main/level";
|
||||
import { restartAndInstallUpdate } from "@main/events/autoupdater/restart-and-install-update";
|
||||
|
||||
async function downloadImage(url: string | null) {
|
||||
if (!url) return undefined;
|
||||
@@ -72,10 +73,24 @@ export const publishNotificationUpdateReadyToInstall = async (
|
||||
ns: "notifications",
|
||||
}),
|
||||
icon: trayIcon,
|
||||
}).show();
|
||||
})
|
||||
.on("click", () => {
|
||||
restartAndInstallUpdate();
|
||||
})
|
||||
.show();
|
||||
};
|
||||
|
||||
export const publishNewFriendRequestNotification = async () => {};
|
||||
export const publishNewFriendRequestNotification = async () => {
|
||||
new Notification({
|
||||
title: t("new_friend_request", {
|
||||
ns: "notifications",
|
||||
}),
|
||||
body: t("You have received a new friend request", {
|
||||
ns: "notifications",
|
||||
}),
|
||||
icon: trayIcon,
|
||||
});
|
||||
};
|
||||
|
||||
export const publishCombinedNewAchievementNotification = async (
|
||||
achievementCount,
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import updater, { UpdateInfo } from "electron-updater";
|
||||
import { logger, WindowManager } from "@main/services";
|
||||
import { AppUpdaterEvent } from "@types";
|
||||
import { AppUpdaterEvent, UserPreferences } from "@types";
|
||||
import { app } from "electron";
|
||||
import { publishNotificationUpdateReadyToInstall } from "@main/services/notifications";
|
||||
|
||||
const isAutoInstallAvailable =
|
||||
process.platform !== "darwin" && process.env.PORTABLE_EXECUTABLE_FILE == null;
|
||||
import { db, levelKeys } from "@main/level";
|
||||
|
||||
const { autoUpdater } = updater;
|
||||
const sendEventsForDebug = false;
|
||||
@@ -16,7 +14,7 @@ export class UpdateManager {
|
||||
private static checkTick = 0;
|
||||
|
||||
private static mockValuesForDebug() {
|
||||
this.sendEvent({ type: "update-available", info: { version: "1.3.0" } });
|
||||
this.sendEvent({ type: "update-available", info: { version: "3.3.1" } });
|
||||
this.sendEvent({ type: "update-downloaded" });
|
||||
}
|
||||
|
||||
@@ -24,7 +22,27 @@ export class UpdateManager {
|
||||
WindowManager.mainWindow?.webContents.send("autoUpdaterEvent", event);
|
||||
}
|
||||
|
||||
public static checkForUpdates() {
|
||||
private static async isAutoInstallEnabled() {
|
||||
if (process.platform === "darwin") return false;
|
||||
if (process.platform === "win32") {
|
||||
return process.env.PORTABLE_EXECUTABLE_FILE == null;
|
||||
}
|
||||
|
||||
if (process.platform === "linux") {
|
||||
const userPreferences = await db.get<string, UserPreferences>(
|
||||
levelKeys.userPreferences,
|
||||
{
|
||||
valueEncoding: "json",
|
||||
}
|
||||
);
|
||||
|
||||
return userPreferences.enableAutoInstall === true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static async checkForUpdates() {
|
||||
autoUpdater
|
||||
.once("update-available", (info: UpdateInfo) => {
|
||||
this.sendEvent({ type: "update-available", info });
|
||||
@@ -39,6 +57,8 @@ export class UpdateManager {
|
||||
}
|
||||
});
|
||||
|
||||
const isAutoInstallAvailable = await this.isAutoInstallEnabled();
|
||||
|
||||
if (app.isPackaged) {
|
||||
autoUpdater.autoDownload = isAutoInstallAvailable;
|
||||
autoUpdater.checkForUpdates().then((result) => {
|
||||
|
||||
@@ -12,6 +12,7 @@ export function SettingsBehavior() {
|
||||
);
|
||||
|
||||
const [showRunAtStartup, setShowRunAtStartup] = useState(false);
|
||||
const [showAutoInstall, setShowAutoInstall] = useState(true);
|
||||
|
||||
const { updateUserPreferences } = useContext(settingsContext);
|
||||
|
||||
@@ -20,6 +21,7 @@ export function SettingsBehavior() {
|
||||
runAtStartup: false,
|
||||
startMinimized: false,
|
||||
disableNsfwAlert: false,
|
||||
enableAutoInstall: false,
|
||||
seedAfterDownloadComplete: false,
|
||||
showHiddenAchievementsDescription: false,
|
||||
});
|
||||
@@ -34,6 +36,7 @@ export function SettingsBehavior() {
|
||||
runAtStartup: userPreferences.runAtStartup ?? false,
|
||||
startMinimized: userPreferences.startMinimized ?? false,
|
||||
disableNsfwAlert: userPreferences.disableNsfwAlert ?? false,
|
||||
enableAutoInstall: userPreferences.enableAutoInstall ?? false,
|
||||
seedAfterDownloadComplete:
|
||||
userPreferences.seedAfterDownloadComplete ?? false,
|
||||
showHiddenAchievementsDescription:
|
||||
@@ -46,6 +49,10 @@ export function SettingsBehavior() {
|
||||
window.electron.isPortableVersion().then((isPortableVersion) => {
|
||||
setShowRunAtStartup(!isPortableVersion);
|
||||
});
|
||||
|
||||
if (window.electron.platform === "linux") {
|
||||
setShowAutoInstall(true);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleChange = (values: Partial<typeof form>) => {
|
||||
@@ -99,6 +106,16 @@ export function SettingsBehavior() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{showAutoInstall && (
|
||||
<CheckboxField
|
||||
label={t("enable_auto_install")}
|
||||
checked={form.enableAutoInstall}
|
||||
onChange={() => {
|
||||
handleChange({ enableAutoInstall: !form.enableAutoInstall });
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
<CheckboxField
|
||||
label={t("disable_nsfw_alert")}
|
||||
checked={form.disableNsfwAlert}
|
||||
|
||||
@@ -76,6 +76,7 @@ export interface UserPreferences {
|
||||
runAtStartup?: boolean;
|
||||
startMinimized?: boolean;
|
||||
disableNsfwAlert?: boolean;
|
||||
enableAutoInstall?: boolean;
|
||||
seedAfterDownloadComplete?: boolean;
|
||||
showHiddenAchievementsDescription?: boolean;
|
||||
downloadNotificationsEnabled?: boolean;
|
||||
|
||||
Reference in New Issue
Block a user