2
0
mirror of https://github.com/frappe/books.git synced 2024-12-22 02:49:03 +00:00

feat: toggler removed from sidebar and added a field to enable dark mode in Settings > System > Theme

This commit is contained in:
pu-raihan 2024-08-20 18:17:46 +05:30
parent f15b1cfe13
commit a38073835d
11 changed files with 317 additions and 138 deletions

View File

@ -36,7 +36,6 @@ export type ConfigMap = {
lastSelectedFilePath: null | string; lastSelectedFilePath: null | string;
language: string language: string
deviceId: string deviceId: string
darkMode: boolean
}; };
export interface ConfigFile { export interface ConfigFile {

View File

@ -117,6 +117,14 @@
"fieldtype": "Data", "fieldtype": "Data",
"readOnly": true, "readOnly": true,
"hidden": true "hidden": true
},
{
"fieldname": "darkMode",
"label": "Dark mode",
"fieldtype": "Check",
"default": "false",
"description": "Sets the theme of the app.",
"section": "Theme"
} }
], ],
"quickEditFields": [ "quickEditFields": [
@ -126,4 +134,4 @@
"displayPrecision", "displayPrecision",
"hideGetStarted" "hideGetStarted"
] ]
} }

View File

@ -23,7 +23,6 @@
class="flex-1" class="flex-1"
:darkMode="darkMode" :darkMode="darkMode"
@change-db-file="showDbSelector" @change-db-file="showDbSelector"
@toggle-darkmode="toggleDMode"
/> />
<DatabaseSelector <DatabaseSelector
v-if="activeScreen === 'DatabaseSelector'" v-if="activeScreen === 'DatabaseSelector'"
@ -70,7 +69,7 @@ import { Search } from './utils/search';
import { Shortcuts } from './utils/shortcuts'; import { Shortcuts } from './utils/shortcuts';
import { routeTo } from './utils/ui'; import { routeTo } from './utils/ui';
import { useKeys } from './utils/vueUtils'; import { useKeys } from './utils/vueUtils';
import { toggleDarkMode } from 'src/utils/theme'; import { setDarkMode } from 'src/utils/theme';
enum Screen { enum Screen {
Desk = 'Desk', Desk = 'Desk',
@ -136,7 +135,9 @@ export default defineComponent({
}, },
async mounted() { async mounted() {
await this.setInitialScreen(); await this.setInitialScreen();
this.darkMode = fyo.config.get('darkMode') as boolean; const { darkMode } = await fyo.doc.getDoc('SystemSettings');
setDarkMode(!!darkMode);
this.darkMode = !!darkMode;
}, },
methods: { methods: {
async setInitialScreen(): Promise<void> { async setInitialScreen(): Promise<void> {
@ -260,10 +261,6 @@ export default defineComponent({
this.searcher = null; this.searcher = null;
this.companyName = ''; this.companyName = '';
}, },
toggleDMode(): void {
toggleDarkMode();
this.darkMode = fyo.config.get('darkMode');
},
}, },
}); });

View File

@ -1,33 +1,69 @@
<template> <template>
<div> <div>
<svg ref="chartSvg" :viewBox="`0 0 ${viewBoxWidth} ${viewBoxHeight}`" xmlns="http://www.w3.org/2000/svg"> <svg
ref="chartSvg"
:viewBox="`0 0 ${viewBoxWidth} ${viewBoxHeight}`"
xmlns="http://www.w3.org/2000/svg"
>
<!-- x Grid Lines --> <!-- x Grid Lines -->
<path v-if="drawXGrid" :d="xGrid" :stroke="gridColor" :stroke-width="gridThickness" stroke-linecap="round" <path
fill="transparent" /> v-if="drawXGrid"
:d="xGrid"
:stroke="gridColor"
:stroke-width="gridThickness"
stroke-linecap="round"
fill="transparent"
/>
<!-- zero line --> <!-- zero line -->
<path v-if="drawZeroLine" :d="zLine" :stroke="zeroLineColor" :stroke-width="gridThickness" stroke-linecap="round" <path
fill="transparent" /> v-if="drawZeroLine"
:d="zLine"
:stroke="zeroLineColor"
:stroke-width="gridThickness"
stroke-linecap="round"
fill="transparent"
/>
<!-- Axis --> <!-- Axis -->
<path v-if="drawAxis" :d="axis" :stroke-width="axisThickness" :stroke="axisColor" fill="transparent" /> <path
v-if="drawAxis"
:d="axis"
:stroke-width="axisThickness"
:stroke="axisColor"
fill="transparent"
/>
<!-- x Labels --> <!-- x Labels -->
<template v-if="xLabels.length > 0"> <template v-if="xLabels.length > 0">
<text v-for="(i, j) in count" :key="j + '-xlabels'" :style="fontStyle" :y="viewBoxHeight - <text
axisPadding + v-for="(i, j) in count"
yLabelOffset + :key="j + '-xlabels'"
fontStyle.fontSize / 2 - :style="fontStyle"
bottom :y="
" :x="xs[i - 1]" text-anchor="middle"> viewBoxHeight -
axisPadding +
yLabelOffset +
fontStyle.fontSize / 2 -
bottom
"
:x="xs[i - 1]"
text-anchor="middle"
>
{{ j % skipXLabel === 0 ? formatX(xLabels[i - 1] || '') : '' }} {{ j % skipXLabel === 0 ? formatX(xLabels[i - 1] || '') : '' }}
</text> </text>
</template> </template>
<!-- y Labels --> <!-- y Labels -->
<template v-if="yLabelDivisions > 0"> <template v-if="yLabelDivisions > 0">
<text v-for="(i, j) in yLabelDivisions + 1" :key="j + '-ylabels'" :style="fontStyle" :y="yScalerLocation(i - 1)" <text
:x="axisPadding - xLabelOffset + left" text-anchor="end"> v-for="(i, j) in yLabelDivisions + 1"
:key="j + '-ylabels'"
:style="fontStyle"
:y="yScalerLocation(i - 1)"
:x="axisPadding - xLabelOffset + left"
text-anchor="end"
>
{{ yScalerValue(i - 1) }} {{ yScalerValue(i - 1) }}
</text> </text>
</template> </template>
@ -37,21 +73,64 @@
<rect x="0" y="0" :width="viewBoxWidth" :height="z" /> <rect x="0" y="0" :width="viewBoxWidth" :height="z" />
</clipPath> </clipPath>
<clipPath id="negative-rect-clip"> <clipPath id="negative-rect-clip">
<rect x="0" :y="z" :width="viewBoxWidth" :height="viewBoxHeight - z" /> <rect
x="0"
:y="z"
:width="viewBoxWidth"
:height="viewBoxHeight - z"
/>
</clipPath> </clipPath>
</defs> </defs>
<rect v-for="(rec, i) in positiveRects" :key="i + 'prec'" :rx="radius" :ry="radius" :x="rec.x" :y="rec.y" <rect
:width="width" :height="rec.height" :fill="rec.color" clip-path="url(#positive-rect-clip)" v-for="(rec, i) in positiveRects"
@mouseenter="() => create(rec.xi, rec.yi)" @mousemove="update" @mouseleave="destroy" /> :key="i + 'prec'"
:rx="radius"
:ry="radius"
:x="rec.x"
:y="rec.y"
:width="width"
:height="rec.height"
:fill="rec.color"
clip-path="url(#positive-rect-clip)"
@mouseenter="() => create(rec.xi, rec.yi)"
@mousemove="update"
@mouseleave="destroy"
/>
<rect v-for="(rec, i) in negativeRects" :key="i + 'nrec'" :rx="radius" :ry="radius" :x="rec.x" :y="rec.y" <rect
:width="width" :height="rec.height" :fill="rec.color" clip-path="url(#negative-rect-clip)" v-for="(rec, i) in negativeRects"
@mouseenter="() => create(rec.xi, rec.yi)" @mousemove="update" @mouseleave="destroy" /> :key="i + 'nrec'"
:rx="radius"
:ry="radius"
:x="rec.x"
:y="rec.y"
:width="width"
:height="rec.height"
:fill="rec.color"
clip-path="url(#negative-rect-clip)"
@mouseenter="() => create(rec.xi, rec.yi)"
@mousemove="update"
@mouseleave="destroy"
/>
</svg> </svg>
<Tooltip ref="tooltip" :offset="15" placement="top" <Tooltip
class="text-sm shadow-md px-2 py-1 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-200 border-s-4" ref="tooltip"
:style="{ borderColor: activeColor }"> :offset="15"
placement="top"
class="
text-sm
shadow-md
px-2
py-1
bg-white
dark:bg-gray-900
text-gray-900
dark:text-gray-200
border-s-4
"
:style="{ borderColor: activeColor }"
>
<div class="flex flex-col justify-center items-center"> <div class="flex flex-col justify-center items-center">
<p> <p>
{{ xi > -1 ? formatX(xLabels[xi]) : '' }} {{ xi > -1 ? formatX(xLabels[xi]) : '' }}
@ -127,7 +206,7 @@ export default {
this.padding + this.padding +
this.left + this.left +
(i * (this.viewBoxWidth - this.left - 2 * this.padding)) / (i * (this.viewBoxWidth - this.left - 2 * this.padding)) /
(this.count - 1 || 1) // The "or" one (1) prevents accidentally dividing by 0 (this.count - 1 || 1) // The "or" one (1) prevents accidentally dividing by 0
); );
}, },
z() { z() {
@ -146,8 +225,9 @@ export default {
return Math.max(...this.points.flat()); return Math.max(...this.points.flat());
}, },
axis() { axis() {
return `M ${this.axisPadding + this.left} ${this.axisPadding} V ${this.viewBoxHeight - this.axisPadding - this.bottom return `M ${this.axisPadding + this.left} ${this.axisPadding} V ${
} H ${this.viewBoxWidth - this.axisPadding}`; this.viewBoxHeight - this.axisPadding - this.bottom
} H ${this.viewBoxWidth - this.axisPadding}`;
}, },
padding() { padding() {
return this.axisPadding + this.pointsPadding; return this.axisPadding + this.pointsPadding;
@ -235,7 +315,7 @@ export default {
return ( return (
((this.yLabelDivisions - i) * ((this.yLabelDivisions - i) *
(this.viewBoxHeight - this.padding * 2 - this.bottom)) / (this.viewBoxHeight - this.padding * 2 - this.bottom)) /
this.yLabelDivisions + this.yLabelDivisions +
this.padding this.padding
); );
}, },

View File

@ -1,30 +1,60 @@
<template> <template>
<div> <div>
<svg ref="chartSvg" :viewBox="`0 0 ${viewBoxWidth} ${viewBoxHeight}`" xmlns="http://www.w3.org/2000/svg" <svg
@mousemove="update"> ref="chartSvg"
:viewBox="`0 0 ${viewBoxWidth} ${viewBoxHeight}`"
xmlns="http://www.w3.org/2000/svg"
@mousemove="update"
>
<!-- x Grid Lines --> <!-- x Grid Lines -->
<path v-if="drawXGrid" :d="xGrid" :stroke="gridColor" :stroke-width="gridThickness" stroke-linecap="round" <path
fill="transparent" /> v-if="drawXGrid"
:d="xGrid"
:stroke="gridColor"
:stroke-width="gridThickness"
stroke-linecap="round"
fill="transparent"
/>
<!-- Axis --> <!-- Axis -->
<path v-if="drawAxis" :d="axis" :stroke-width="axisThickness" :stroke="axisColor" fill="transparent" /> <path
v-if="drawAxis"
:d="axis"
:stroke-width="axisThickness"
:stroke="axisColor"
fill="transparent"
/>
<!-- x Labels --> <!-- x Labels -->
<template v-if="drawLabels && xLabels.length > 0"> <template v-if="drawLabels && xLabels.length > 0">
<text v-for="(i, j) in count" :key="j + '-xlabels'" :style="fontStyle" :y="viewBoxHeight - <text
axisPadding + v-for="(i, j) in count"
yLabelOffset + :key="j + '-xlabels'"
fontStyle.fontSize / 2 - :style="fontStyle"
bottom :y="
" :x="xs[i - 1]" text-anchor="middle"> viewBoxHeight -
axisPadding +
yLabelOffset +
fontStyle.fontSize / 2 -
bottom
"
:x="xs[i - 1]"
text-anchor="middle"
>
{{ formatX(xLabels[i - 1] || '') }} {{ formatX(xLabels[i - 1] || '') }}
</text> </text>
</template> </template>
<!-- y Labels --> <!-- y Labels -->
<template v-if="drawLabels && yLabelDivisions > 0"> <template v-if="drawLabels && yLabelDivisions > 0">
<text v-for="(i, j) in yLabelDivisions + 1" :key="j + '-ylabels'" :style="fontStyle" :y="yScalerLocation(i - 1)" <text
:x="axisPadding - xLabelOffset + left" text-anchor="end"> v-for="(i, j) in yLabelDivisions + 1"
:key="j + '-ylabels'"
:style="fontStyle"
:y="yScalerLocation(i - 1)"
:x="axisPadding - xLabelOffset + left"
text-anchor="end"
>
{{ yScalerValue(i - 1) }} {{ yScalerValue(i - 1) }}
</text> </text>
</template> </template>
@ -38,28 +68,68 @@
</linearGradient> </linearGradient>
<mask v-for="(i, j) in num" :id="'rect-mask-' + i" :key="j + '-mask'"> <mask v-for="(i, j) in num" :id="'rect-mask-' + i" :key="j + '-mask'">
<rect x="0" :y="gradY(j)" :height="viewBoxHeight - gradY(j)" width="100%" fill="url('#grad')" /> <rect
x="0"
:y="gradY(j)"
:height="viewBoxHeight - gradY(j)"
width="100%"
fill="url('#grad')"
/>
</mask> </mask>
</defs> </defs>
<g v-for="(i, j) in num" :key="j + '-gpath'"> <g v-for="(i, j) in num" :key="j + '-gpath'">
<!-- Gradient Paths --> <!-- Gradient Paths -->
<path stroke-linejoin="round" :d="getGradLine(i - 1)" :stroke-width="thickness" stroke-linecap="round" <path
:fill="colors[i - 1] || getRandomColor()" :mask="`url('#rect-mask-${i}')`" /> stroke-linejoin="round"
:d="getGradLine(i - 1)"
:stroke-width="thickness"
stroke-linecap="round"
:fill="colors[i - 1] || getRandomColor()"
:mask="`url('#rect-mask-${i}')`"
/>
<!-- Lines --> <!-- Lines -->
<path stroke-linejoin="round" :d="getLine(i - 1)" :stroke="colors[i - 1] || getRandomColor()" <path
:stroke-width="thickness" stroke-linecap="round" fill="transparent" /> stroke-linejoin="round"
:d="getLine(i - 1)"
:stroke="colors[i - 1] || getRandomColor()"
:stroke-width="thickness"
stroke-linecap="round"
fill="transparent"
/>
</g> </g>
<!-- Tooltip Reference --> <!-- Tooltip Reference -->
<circle v-if="xi > -1 && yi > -1" r="12" :cx="cx" :cy="cy" :fill="colors[yi]" style=" <circle
v-if="xi > -1 && yi > -1"
r="12"
:cx="cx"
:cy="cy"
:fill="colors[yi]"
style="
filter: brightness(115%) drop-shadow(0px 2px 3px rgba(0, 0, 0, 0.25)); filter: brightness(115%) drop-shadow(0px 2px 3px rgba(0, 0, 0, 0.25));
" /> "
/>
</svg> </svg>
<Tooltip v-if="showTooltip" ref="tooltip" :offset="15" placement="top" <Tooltip
class="text-sm shadow-md px-2 py-1 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-200 border-s-4" v-if="showTooltip"
:style="{ borderColor: colors[yi] }"> ref="tooltip"
:offset="15"
placement="top"
class="
text-sm
shadow-md
px-2
py-1
bg-white
dark:bg-gray-900
text-gray-900
dark:text-gray-200
border-s-4
"
:style="{ borderColor: colors[yi] }"
>
<div class="flex flex-col justify-center items-center"> <div class="flex flex-col justify-center items-center">
<p> <p>
{{ xi > -1 ? formatX(xLabels[xi]) : '' }} {{ xi > -1 ? formatX(xLabels[xi]) : '' }}
@ -133,7 +203,7 @@ export default {
this.padding + this.padding +
this.left + this.left +
(i * (this.viewBoxWidth - this.left - 2 * this.padding)) / (i * (this.viewBoxWidth - this.left - 2 * this.padding)) /
(this.count - 1 || 1) // The "or" one (1) prevents accidentally dividing by 0 (this.count - 1 || 1) // The "or" one (1) prevents accidentally dividing by 0
); );
}, },
ys() { ys() {
@ -144,7 +214,7 @@ export default {
(p) => (p) =>
this.padding + this.padding +
(1 - (p - min) / (max - min)) * (1 - (p - min) / (max - min)) *
(this.viewBoxHeight - 2 * this.padding - this.bottom) (this.viewBoxHeight - 2 * this.padding - this.bottom)
) )
); );
}, },
@ -158,8 +228,9 @@ export default {
return Math.max(...this.points.flat()); return Math.max(...this.points.flat());
}, },
axis() { axis() {
return `M ${this.axisPadding + this.left} ${this.axisPadding} V ${this.viewBoxHeight - this.axisPadding - this.bottom return `M ${this.axisPadding + this.left} ${this.axisPadding} V ${
} H ${this.viewBoxWidth - this.axisPadding}`; this.viewBoxHeight - this.axisPadding - this.bottom
} H ${this.viewBoxWidth - this.axisPadding}`;
}, },
padding() { padding() {
return this.axisPadding + this.pointsPadding; return this.axisPadding + this.pointsPadding;
@ -200,7 +271,7 @@ export default {
return ( return (
((this.yLabelDivisions - i) * ((this.yLabelDivisions - i) *
(this.viewBoxHeight - this.padding * 2 - this.bottom)) / (this.viewBoxHeight - this.padding * 2 - this.bottom)) /
this.yLabelDivisions + this.yLabelDivisions +
this.padding this.padding
); );
}, },

View File

@ -1,26 +1,68 @@
<template> <template>
<div class="relative bg-white dark:bg-gray-900 border dark:border-gray-800 flex-center overflow-hidden group" :class="{ <div
rounded: size === 'form', class="
'w-20 h-20 rounded-full': size !== 'small' && size !== 'form', relative
'w-12 h-12 rounded-full': size === 'small', bg-white
}" :title="df?.label" :style="imageSizeStyle"> dark:bg-gray-900
border
dark:border-gray-800
flex-center
overflow-hidden
group
"
:class="{
rounded: size === 'form',
'w-20 h-20 rounded-full': size !== 'small' && size !== 'form',
'w-12 h-12 rounded-full': size === 'small',
}"
:title="df?.label"
:style="imageSizeStyle"
>
<img v-if="value" :src="value" /> <img v-if="value" :src="value" />
<div v-else :class="[!isReadOnly ? 'group-hover:opacity-90' : '']"> <div v-else :class="[!isReadOnly ? 'group-hover:opacity-90' : '']">
<div v-if="letterPlaceholder" <div
class="flex h-full items-center justify-center text-gray-400 dark:text-gray-600 font-semibold w-full text-4xl select-none"> v-if="letterPlaceholder"
class="
flex
h-full
items-center
justify-center
text-gray-400
dark:text-gray-600
font-semibold
w-full
text-4xl
select-none
"
>
{{ letterPlaceholder }} {{ letterPlaceholder }}
</div> </div>
<svg v-else class="w-6 h-6 text-gray-300 dark:text-gray-600" viewBox="0 0 24 21" <svg
xmlns="http://www.w3.org/2000/svg"> v-else
class="w-6 h-6 text-gray-300 dark:text-gray-600"
viewBox="0 0 24 21"
xmlns="http://www.w3.org/2000/svg"
>
<path <path
d="M21 3h-4l-2-3H9L7 3H3a3 3 0 00-3 3v12a3 3 0 003 3h18a3 3 0 003-3V6a3 3 0 00-3-3zm-9 14a5 5 0 110-10 5 5 0 010 10z" d="M21 3h-4l-2-3H9L7 3H3a3 3 0 00-3 3v12a3 3 0 003 3h18a3 3 0 003-3V6a3 3 0 00-3-3zm-9 14a5 5 0 110-10 5 5 0 010 10z"
fill="currentColor" fill-rule="nonzero" /> fill="currentColor"
fill-rule="nonzero"
/>
</svg> </svg>
</div> </div>
<div class="hidden w-full h-full absolute justify-center items-end" :class="[!isReadOnly ? 'group-hover:flex' : '']" <div
style="background: rgba(0, 0, 0, 0.2); backdrop-filter: blur(2px)"> class="hidden w-full h-full absolute justify-center items-end"
<button class="bg-gray-100 dark:bg-gray-800 p-0.5 rounded mb-1" @click="handleClick"> :class="[!isReadOnly ? 'group-hover:flex' : '']"
<FeatherIcon :name="shouldClear ? 'x' : 'upload'" class="w-4 h-4 text-gray-600 dark:text-gray-400" /> style="background: rgba(0, 0, 0, 0.2); backdrop-filter: blur(2px)"
>
<button
class="bg-gray-100 dark:bg-gray-800 p-0.5 rounded mb-1"
@click="handleClick"
>
<FeatherIcon
:name="shouldClear ? 'x' : 'upload'"
class="w-4 h-4 text-gray-600 dark:text-gray-400"
/>
</button> </button>
</div> </div>
</div> </div>

View File

@ -1,18 +1,43 @@
<template> <template>
<div class="px-4 flex justify-between items-center h-row-largest flex-shrink-0 dark:bg-gray-875" :class="[ <div
border ? 'border-b dark:border-gray-800' : '', class="
platform !== 'Windows' ? 'window-drag' : '', px-4
]"> flex
justify-between
items-center
h-row-largest
flex-shrink-0
dark:bg-gray-875
"
:class="[
border ? 'border-b dark:border-gray-800' : '',
platform !== 'Windows' ? 'window-drag' : '',
]"
>
<Transition name="spacer"> <Transition name="spacer">
<div v-if="!showSidebar && platform === 'Mac' && languageDirection !== 'rtl'" class="h-full" <div
:class="spacerClass" /> v-if="!showSidebar && platform === 'Mac' && languageDirection !== 'rtl'"
class="h-full"
:class="spacerClass"
/>
</Transition> </Transition>
<div class="flex items-center window-no-drag gap-4 me-auto" <div
:class="platform === 'Mac' && languageDirection === 'rtl' ? 'me-18' : ''"> class="flex items-center window-no-drag gap-4 me-auto"
:class="platform === 'Mac' && languageDirection === 'rtl' ? 'me-18' : ''"
>
<!-- Nav Group --> <!-- Nav Group -->
<PageHeaderNavGroup /> <PageHeaderNavGroup />
<h1 v-if="title" class="text-xl font-semibold select-none whitespace-nowrap dark:text-white"> <h1
v-if="title"
class="
text-xl
font-semibold
select-none
whitespace-nowrap
dark:text-white
"
>
{{ title }} {{ title }}
</h1> </h1>
@ -23,8 +48,10 @@
</div> </div>
<!-- Right (regular) Slot --> <!-- Right (regular) Slot -->
<div class="flex items-stretch window-no-drag gap-2 ms-auto" <div
:class="platform === 'Mac' && languageDirection === 'rtl' ? 'me-18' : ''"> class="flex items-stretch window-no-drag gap-2 ms-auto"
:class="platform === 'Mac' && languageDirection === 'rtl' ? 'me-18' : ''"
>
<slot /> <slot />
</div> </div>
</div> </div>

View File

@ -107,29 +107,8 @@
</div> </div>
</div> </div>
<!-- Report Issue, DB Switcher and Darkmode Switcher --> <!-- Report Issue and DB Switcher -->
<div class="window-no-drag flex flex-col gap-2 py-2 px-4"> <div class="window-no-drag flex flex-col gap-2 py-2 px-4">
<button
class="
flex
text-sm text-gray-600
dark:text-gray-500
hover:text-gray-800
dark:hover:text-gray-400
gap-1
items-center
"
@click="$emit('toggle-darkmode')"
>
<feather-icon
:name="darkMode ? 'sun' : 'moon'"
class="h-4 w-4 flex-shrink-0"
/>
<p>
{{ t`Dark Mode` }}
</p>
</button>
<button <button
class=" class="
flex flex

View File

@ -17,7 +17,6 @@ import { toggleSidebar } from 'src/utils/ui';
" "
:darkMode="darkMode" :darkMode="darkMode"
@change-db-file="$emit('change-db-file')" @change-db-file="$emit('change-db-file')"
@toggle-darkmode="$emit('toggle-darkmode')"
/> />
</Transition> </Transition>
@ -89,7 +88,7 @@ export default defineComponent({
props: { props: {
darkMode: { type: Boolean, default: false }, darkMode: { type: Boolean, default: false },
}, },
emits: ['change-db-file', 'toggle-darkmode'], emits: ['change-db-file'],
}); });
</script> </script>

View File

@ -11,7 +11,6 @@ import registerIpcRendererListeners from './renderer/registerIpcRendererListener
import router from './router'; import router from './router';
import { stringifyCircular } from './utils'; import { stringifyCircular } from './utils';
import { setLanguageMap } from './utils/language'; import { setLanguageMap } from './utils/language';
import { setDarkMode } from './utils/theme';
// eslint-disable-next-line @typescript-eslint/no-floating-promises // eslint-disable-next-line @typescript-eslint/no-floating-promises
(async () => { (async () => {
@ -21,8 +20,6 @@ import { setDarkMode } from './utils/theme';
} }
fyo.store.language = language || 'English'; fyo.store.language = language || 'English';
setDarkMode();
registerIpcRendererListeners(); registerIpcRendererListeners();
const { isDevelopment, platform, version } = await ipc.getEnv(); const { isDevelopment, platform, version } = await ipc.getEnv();

View File

@ -1,24 +1,4 @@
import { fyo } from 'src/initFyo'; export function setDarkMode(darkMode: boolean): void {
export function toggleDarkMode(): void {
const darkMode = fyo.config.get('darkMode');
if (darkMode) {
document.documentElement.classList.remove('dark');
fyo.config.set('darkMode', false);
return;
}
document.documentElement.classList.add('dark');
fyo.config.set('darkMode', true);
}
export function setDarkMode(): void {
let darkMode = fyo.config.get('darkMode');
/* Fetching system theme */
if (darkMode === undefined) {
darkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
fyo.config.set('darkMode', darkMode);
}
if (darkMode) { if (darkMode) {
document.documentElement.classList.add('dark'); document.documentElement.classList.add('dark');
return; return;