Skip to content

Commit

Permalink
feat(#122): start minimized added
Browse files Browse the repository at this point in the history
  • Loading branch information
Venipa committed Feb 2, 2025
1 parent 7ca59a8 commit 7721286
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 45 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ytmdesktop2",
"version": "0.14.5",
"version": "0.14.6",
"private": false,
"author": "Venipa <[email protected]>",
"main": "./out/main/index.js",
Expand Down
3 changes: 2 additions & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ const runApp = async function () {
await waitMs(); // next tick
mainWindow = await createRootWindow();
await waitMs(); // next tick
mainWindow.main.show();
const startupService = serviceCollection.getProvider("startup")
if (!startupService.isEnabled || !startupService.isInitialMinimized) mainWindow.main.show();
serviceCollection.providers.forEach((p) => p.__registerWindows(mainWindow));
serviceCollection.exec("AfterInit");
});
Expand Down
1 change: 1 addition & 0 deletions src/main/plugins/settingsProvider.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const defaultSettings = {
beta: false,
autoupdate: true,
autostart: true,
autostartMinimized: true,
getstarted: true,
enableDev: false,
minimizeTrayOverride: false,
Expand Down
6 changes: 6 additions & 0 deletions src/main/plugins/startupProvider.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ export default class StartupProvider extends BaseProvider implements AfterInit,
get settingsInstance(): SettingsProvider {
return this.getProvider("settings");
}
get isEnabled() {
return !!this.settingsInstance.instance?.app?.autostart
}
get isInitialMinimized() {
return !!this.settingsInstance.instance?.app?.autostartMinimized
}
constructor(private app: App) {
super("startup");
app.commandLine.appendSwitch("disable-http-cache");
Expand Down
66 changes: 26 additions & 40 deletions src/renderer/src/views/settings/generic-settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,21 @@
</div>
</div>
<div class="px-3 flex flex-col gap-4 mt-4">
<settings-checkbox config-key="app.autostart"> Enable Autostart </settings-checkbox>
<div
:class="[
'flex flex-col gap-y-1 border -mx-3 px-3',
appAutostartEnabled
? 'border-gray-500 bg-gray-800 transition-all duration-150 ease-in-out pt-1.5 pb-2.5 rounded-lg'
: 'border-gray-500/0 bg-gray-800/0 mt-1.5',
]"
>
<settings-checkbox config-key="app.autostart"> Enable Autostart </settings-checkbox>
<template v-if="appAutostartEnabled">
<settings-checkbox config-key="app.autostartMinimized">
Start minimized
</settings-checkbox>
</template>
</div>
<settings-checkbox config-key="app.autoupdate"> Enable Autoupdate </settings-checkbox>
<settings-checkbox config-key="app.enableStatisticsAndErrorTracing">
<div class="flex flex-col">
Expand Down Expand Up @@ -108,48 +122,20 @@
</div>
</template>

<script>
<script lang="ts" setup>
import SettingsCheckbox from "@renderer/components/SettingsCheckbox.vue";
import SettingsInput from "@renderer/components/SettingsInput.vue";
import { defineComponent, ref } from "vue";
import { refIpcSetting } from "@shared/utils/Ipc";
const [getStartedEnabled] = refIpcSetting("app.getstarted");
const [apiEnabledSetting] = refIpcSetting("api.enabled");
const [appAutostartEnabled] = refIpcSetting("app.autostart");
const getStartedEnabled = ref(!!window.settings.get("app.getstarted"));
const apiEnabledSetting = ref(!!window.settings.get("api.enabled"));
const apiPortSetting = ref(window.settings.get("api.port") ?? 13091);
const errorReportingEnabled = ref(window.settings.get("app.enableStatisticsAndErrorTracing"));
let subscribers = [];
subscribers.push(
ipcRenderer.on("settingsProvider.change", (ev, key, value) => {
if (key === "api.enabled" && value !== apiEnabledSetting.value)
apiEnabledSetting.value = !!value;
if (key === "api.port" && value !== apiPortSetting.value) apiPortSetting.value = value;
if (key === "app.enableStatisticsAndErrorTracing") errorReportingEnabled.value = !!value;
}),
);
export default defineComponent({
components: { SettingsCheckbox, SettingsInput },
setup() {
return {
getStartedEnabled,
apiPortSetting,
apiEnabledSetting,
errorReportingEnabled,
};
},
unmounted() {
if (subscribers) {
subscribers.filter((x) => typeof x === "function").forEach(window.ipcRenderer.off);
subscribers = [];
}
},
methods: {
disableGetStarted() {
window.api.settingsProvider.update("app.getstarted", false).then((v) => {
this.getStartedEnabled = v;
});
},
},
});
const disableGetStarted = () => {
window.api.settingsProvider.update("app.getstarted", false).then((v) => {
getStartedEnabled.value = v;
});
};
</script>

<style></style>
8 changes: 5 additions & 3 deletions src/shared/utils/Ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { onBeforeMount, onMounted, onUnmounted, Ref, ref } from "vue";
type Map<T, R> =
| ((item: T, name: string, prev: any) => T)
| ((item: T, name: string, prev: any) => R);
type Trigger<T> = ((item: T, prev: T) => void)
type Trigger<T> = (item: T, prev: T) => void;
type IpcHandler = (ev: IpcRendererEvent, ...args: any[]) => void;
type RefReturn<R> = [Ref<R>, (val: R) => void];
type RefIpcOptions<T, R> = {
Expand Down Expand Up @@ -56,7 +56,7 @@ export function refIpc<T, R = T>(
});
return [state, (val: R) => (state.value = val)];
}
export function refIpcSetting<T = any>(key: string) {
export function refIpcSetting<T = any>(key: string, defaultValue?: T) {
const refVal = refIpc("SERVER_SETTINGS_CHANGE", {
mapper: ([skey, value]) => {
if (skey === key) return value as T;
Expand All @@ -66,7 +66,9 @@ export function refIpcSetting<T = any>(key: string) {
ignoreUndefined: true,
});
onMounted(() => {
window.api.settingsProvider.get(key, null).then(refVal[1]);
window.api.settingsProvider
.get(key, null)
.then((initialValue) => refVal[1](initialValue ?? defaultValue ?? null));
});
return refVal;
}
Expand Down

0 comments on commit 7721286

Please sign in to comment.