@witchcraft/nuxt-electron 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +1 -1
  2. package/dist/module.d.cts +2 -0
  3. package/dist/module.d.mts +2 -117
  4. package/dist/module.json +1 -1
  5. package/dist/module.mjs +13 -369
  6. package/dist/types.d.mts +12 -2
  7. package/package.json +28 -28
  8. package/src/module.ts +1 -1
  9. package/dist/runtime/components/ElectronWindowControls.d.vue.ts +0 -32
  10. package/dist/runtime/components/ElectronWindowControls.vue +0 -67
  11. package/dist/runtime/components/ElectronWindowControls.vue.d.ts +0 -32
  12. package/dist/runtime/components/WindowControls/CloseButton.d.vue.ts +0 -17
  13. package/dist/runtime/components/WindowControls/CloseButton.vue +0 -54
  14. package/dist/runtime/components/WindowControls/CloseButton.vue.d.ts +0 -17
  15. package/dist/runtime/components/WindowControls/MaximizeButton.d.vue.ts +0 -17
  16. package/dist/runtime/components/WindowControls/MaximizeButton.vue +0 -33
  17. package/dist/runtime/components/WindowControls/MaximizeButton.vue.d.ts +0 -17
  18. package/dist/runtime/components/WindowControls/MinimizeButton.d.vue.ts +0 -17
  19. package/dist/runtime/components/WindowControls/MinimizeButton.vue +0 -40
  20. package/dist/runtime/components/WindowControls/MinimizeButton.vue.d.ts +0 -17
  21. package/dist/runtime/components/WindowControls/PinButton.d.vue.ts +0 -28
  22. package/dist/runtime/components/WindowControls/PinButton.vue +0 -52
  23. package/dist/runtime/components/WindowControls/PinButton.vue.d.ts +0 -28
  24. package/dist/runtime/electron/apiBuilder.d.ts +0 -8
  25. package/dist/runtime/electron/apiBuilder.js +0 -9
  26. package/dist/runtime/electron/createBroadcastHandlers.d.ts +0 -4
  27. package/dist/runtime/electron/createBroadcastHandlers.js +0 -30
  28. package/dist/runtime/electron/createBroadcaster.d.ts +0 -2
  29. package/dist/runtime/electron/createBroadcaster.js +0 -7
  30. package/dist/runtime/electron/createNuxtFileProtocolHandler.d.ts +0 -14
  31. package/dist/runtime/electron/createNuxtFileProtocolHandler.js +0 -20
  32. package/dist/runtime/electron/createWindowControlsApi.d.ts +0 -19
  33. package/dist/runtime/electron/createWindowControlsApi.js +0 -6
  34. package/dist/runtime/electron/createWindowControlsApiHandler.d.ts +0 -4
  35. package/dist/runtime/electron/createWindowControlsApiHandler.js +0 -24
  36. package/dist/runtime/electron/getEventWindow.d.ts +0 -11
  37. package/dist/runtime/electron/getEventWindow.js +0 -8
  38. package/dist/runtime/electron/getPaths.d.ts +0 -27
  39. package/dist/runtime/electron/getPaths.js +0 -33
  40. package/dist/runtime/electron/getPreloadMeta.d.ts +0 -25
  41. package/dist/runtime/electron/getPreloadMeta.js +0 -7
  42. package/dist/runtime/electron/index.d.ts +0 -16
  43. package/dist/runtime/electron/index.js +0 -16
  44. package/dist/runtime/electron/promisifyApi.d.ts +0 -40
  45. package/dist/runtime/electron/promisifyApi.js +0 -41
  46. package/dist/runtime/electron/promisifyReply.d.ts +0 -8
  47. package/dist/runtime/electron/promisifyReply.js +0 -29
  48. package/dist/runtime/electron/registerDevtoolsShortcuts.d.ts +0 -2
  49. package/dist/runtime/electron/registerDevtoolsShortcuts.js +0 -10
  50. package/dist/runtime/electron/static.d.ts +0 -12
  51. package/dist/runtime/electron/static.js +0 -8
  52. package/dist/runtime/electron/types.d.ts +0 -1
  53. package/dist/runtime/electron/types.js +0 -0
  54. package/dist/runtime/electron/useDevDataDir.d.ts +0 -1
  55. package/dist/runtime/electron/useDevDataDir.js +0 -8
  56. package/dist/runtime/electron/useNuxtRuntimeConfig.d.ts +0 -2
  57. package/dist/runtime/electron/useNuxtRuntimeConfig.js +0 -4
  58. package/dist/runtime/utils/isElectron.d.ts +0 -9
  59. package/dist/runtime/utils/isElectron.js +0 -3
@@ -1,67 +0,0 @@
1
- <template>
2
- <ClientOnly>
3
- <div
4
- v-if="isElectron()"
5
- :class="twMerge(`
6
- flex
7
- items-center
8
- gap-2
9
- `, $attrs.class)"
10
- v-bind="{ ...$attrs, class: void 0 }"
11
- :style="`
12
- --electron-wc-size:${props.buttonSize};
13
- --electron-wc-border:${props.borderWidth};
14
- --electron-wc-rounded:${props.borderRadius};
15
- --electron-wc-diagonal:calc((var(--electron-wc-size) - var(--electron-wc-border)/2)*sqrt(2));
16
- `"
17
- >
18
- <template
19
- v-for="button in buttonsOrder"
20
- :key="button"
21
- >
22
- <component
23
- :is="componentsMap[button]"
24
- @action="actionHandler($event)"
25
- />
26
- </template>
27
- </div>
28
- </ClientOnly>
29
- </template>
30
-
31
- <script setup>
32
- import { computed, useAttrs } from "vue";
33
- import CloseButton from "./WindowControls/CloseButton.vue";
34
- import MaximizeButton from "./WindowControls/MaximizeButton.vue";
35
- import MinimizeButton from "./WindowControls/MinimizeButton.vue";
36
- import PinButton from "./WindowControls/PinButton.vue";
37
- import { twMerge } from "#imports";
38
- import { isElectron } from "../utils/isElectron.js";
39
- const $attrs = useAttrs();
40
- const props = defineProps({
41
- borderWidth: { type: String, required: false, default: "2px" },
42
- buttonSize: { type: String, required: false, default: "15px" },
43
- borderRadius: { type: String, required: false, default: "1.5px" },
44
- components: { type: Object, required: false },
45
- buttonsOrder: { type: Array, required: false, default: () => ["PinButton", "MinimizeButton", "MaximizeButton", "CloseButton"] },
46
- handler: { type: Function, required: false }
47
- });
48
- const componentsMap = computed(() => ({
49
- CloseButton,
50
- MinimizeButton,
51
- MaximizeButton,
52
- PinButton,
53
- ...props.components
54
- }));
55
- const actionHandler = computed(() => {
56
- if (!isElectron()) return void 0;
57
- if (!props.handler) {
58
- const defaultHandlerPath = window.electron?.api?.ui?.windowAction;
59
- if (defaultHandlerPath) {
60
- return defaultHandlerPath;
61
- } else {
62
- console.warn("No ElectronWindowControls handler specified and could not find default handler at `window.electron.api.ui.windowAction`");
63
- }
64
- }
65
- return props.handler;
66
- });
67
- </script>
@@ -1,32 +0,0 @@
1
- import { type Component } from "vue";
2
- import type { WindowControlsApi } from "../electron/types.js";
3
- type __VLS_Props = {
4
- borderWidth?: string;
5
- buttonSize?: string;
6
- borderRadius?: string;
7
- /**
8
- *
9
- * Replace any of the default buttons with your own components.
10
- *
11
- * Note that you can get the existing button components (import from `/components/WIndowControls/[name]`) and pass a slot to change the icon then pass your new component here.
12
- *
13
- * If using a completely custom component, it must emit an `action` event with the action name as the value.
14
- *
15
- * This wrapper component sets the following css variables if you need them:
16
- * `--electron-wc-size`
17
- * `--electron-wc-border`
18
- * `--electron-wc-rounded`
19
- * `--electron-wc-diagonal` (useful for creating the close cross)
20
- */
21
- components?: Partial<Record<"CloseButton" | "MinimizeButton" | "MaximizeButton" | "PinButton", Component>>;
22
- buttonsOrder?: ("CloseButton" | "MinimizeButton" | "MaximizeButton" | "PinButton")[];
23
- handler?: WindowControlsApi;
24
- };
25
- declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
26
- borderWidth: string;
27
- buttonSize: string;
28
- borderRadius: string;
29
- buttonsOrder: ("CloseButton" | "MinimizeButton" | "MaximizeButton" | "PinButton")[];
30
- }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
31
- declare const _default: typeof __VLS_export;
32
- export default _default;
@@ -1,17 +0,0 @@
1
- declare var __VLS_10: {};
2
- type __VLS_Slots = {} & {
3
- default?: (props: typeof __VLS_10) => any;
4
- };
5
- declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
6
- action: (action: "close") => any;
7
- }, string, import("vue").PublicProps, Readonly<{}> & Readonly<{
8
- onAction?: ((action: "close") => any) | undefined;
9
- }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
10
- declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
11
- declare const _default: typeof __VLS_export;
12
- export default _default;
13
- type __VLS_WithSlots<T, S> = T & {
14
- new (): {
15
- $slots: S;
16
- };
17
- };
@@ -1,54 +0,0 @@
1
- <template>
2
- <WButton
3
- :border="false"
4
- aria-label="Close"
5
- class="
6
- p-0
7
- [&:hover_.default-icon:after]:bg-accent-500
8
- [&:hover_.default-icon:before]:bg-accent-500
9
- [&:hover_.default-icon:after]:shadow-xs
10
- [&:hover_.default-icon:after]:shadow-fg/50
11
- [&:hover_.default-icon:before]:shadow-xs
12
- [&:hover_.default-icon:before]:shadow-fg/50
13
-
14
- "
15
- @click="emit('action', 'close')"
16
- >
17
- <slot>
18
- <div
19
- class="
20
- default-icon
21
- relative
22
- w-[calc(var(--electron-wc-size)-var(--electron-wc-border)/2)]
23
- h-[calc(var(--electron-wc-size)-var(--electron-wc-border)/2)]
24
- before:absolute
25
- before:content-['']
26
- before:left-0
27
- before:rotate-45
28
- before:origin-left
29
- before:top-[calc(var(--electron-wc-border)/-2)]
30
- before:w-[var(--electron-wc-diagonal)]
31
- before:h-[var(--electron-wc-border)]
32
- before:rounded-(--electron-wc-rounded)
33
- before:bg-fg
34
- dark:before:bg-bg
35
- after:absolute
36
- after:content-['']
37
- after:origin-top
38
- after:right-[calc(var(--electron-wc-border)/-2)]
39
- after:top-0
40
- after:rotate-[45deg]
41
- after:h-[var(--electron-wc-diagonal)]
42
- after:w-[var(--electron-wc-border)]
43
- after:bg-fg
44
- after:rounded-(--electron-wc-rounded)
45
- dark:after:bg-bg
46
- "
47
- />
48
- </slot>
49
- </WButton>
50
- </template>
51
-
52
- <script setup>
53
- const emit = defineEmits(["action"]);
54
- </script>
@@ -1,17 +0,0 @@
1
- declare var __VLS_10: {};
2
- type __VLS_Slots = {} & {
3
- default?: (props: typeof __VLS_10) => any;
4
- };
5
- declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
6
- action: (action: "close") => any;
7
- }, string, import("vue").PublicProps, Readonly<{}> & Readonly<{
8
- onAction?: ((action: "close") => any) | undefined;
9
- }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
10
- declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
11
- declare const _default: typeof __VLS_export;
12
- export default _default;
13
- type __VLS_WithSlots<T, S> = T & {
14
- new (): {
15
- $slots: S;
16
- };
17
- };
@@ -1,17 +0,0 @@
1
- declare var __VLS_10: {};
2
- type __VLS_Slots = {} & {
3
- default?: (props: typeof __VLS_10) => any;
4
- };
5
- declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
6
- action: (action: "toggleMaximize") => any;
7
- }, string, import("vue").PublicProps, Readonly<{}> & Readonly<{
8
- onAction?: ((action: "toggleMaximize") => any) | undefined;
9
- }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
10
- declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
11
- declare const _default: typeof __VLS_export;
12
- export default _default;
13
- type __VLS_WithSlots<T, S> = T & {
14
- new (): {
15
- $slots: S;
16
- };
17
- };
@@ -1,33 +0,0 @@
1
- <template>
2
- <WButton
3
- :border="false"
4
- aria-label="Toggle Maximize"
5
- class="
6
- p-0
7
- [&:hover_.default-icon]:border-accent-500
8
- [&:hover_.default-icon]:shadow-xs
9
- [&:hover_.default-icon]:shadow-fg/50
10
-
11
- "
12
- @click="emit('action', 'toggleMaximize')"
13
- >
14
- <slot>
15
- <div
16
- class="
17
- default-icon
18
- border-fg
19
- dark:border-bg
20
- hover:border-accent-500
21
- border-[length:var(--electron-wc-border)]
22
- rounded-(--electron-wc-rounded)
23
- w-[var(--electron-wc-size)]
24
- h-[var(--electron-wc-size)]
25
- "
26
- />
27
- </slot>
28
- </WButton>
29
- </template>
30
-
31
- <script setup>
32
- const emit = defineEmits(["action"]);
33
- </script>
@@ -1,17 +0,0 @@
1
- declare var __VLS_10: {};
2
- type __VLS_Slots = {} & {
3
- default?: (props: typeof __VLS_10) => any;
4
- };
5
- declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
6
- action: (action: "toggleMaximize") => any;
7
- }, string, import("vue").PublicProps, Readonly<{}> & Readonly<{
8
- onAction?: ((action: "toggleMaximize") => any) | undefined;
9
- }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
10
- declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
11
- declare const _default: typeof __VLS_export;
12
- export default _default;
13
- type __VLS_WithSlots<T, S> = T & {
14
- new (): {
15
- $slots: S;
16
- };
17
- };
@@ -1,17 +0,0 @@
1
- declare var __VLS_10: {};
2
- type __VLS_Slots = {} & {
3
- default?: (props: typeof __VLS_10) => any;
4
- };
5
- declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
6
- action: (action: "minimize") => any;
7
- }, string, import("vue").PublicProps, Readonly<{}> & Readonly<{
8
- onAction?: ((action: "minimize") => any) | undefined;
9
- }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
10
- declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
11
- declare const _default: typeof __VLS_export;
12
- export default _default;
13
- type __VLS_WithSlots<T, S> = T & {
14
- new (): {
15
- $slots: S;
16
- };
17
- };
@@ -1,40 +0,0 @@
1
- <template>
2
- <WButton
3
- :border="false"
4
- aria-label="Minimize"
5
- class="
6
- p-0
7
- [&:hover_.default-icon:after]:bg-accent-500
8
- [&:hover_.default-icon:after]:shadow-xs
9
- [&:hover_.default-icon:after]:shadow-fg/50
10
- "
11
- @click="emit('action', 'minimize')"
12
- >
13
- <slot>
14
- <div
15
- class="
16
- default-icon
17
- border-fg
18
- dark:border-bg
19
- w-[var(--electron-wc-size)]
20
- h-[var(--electron-wc-size)]
21
- relative
22
- after:absolute
23
- after:content-['']
24
- after:bottom-0
25
- after:left-0
26
- after:w-[var(--electron-wc-size)]
27
- after:h-[var(--electron-wc-border)]
28
- after:rounded-(--electron-wc-rounded)
29
- after:bg-fg
30
- dark:after:bg-bg
31
-
32
- "
33
- />
34
- </slot>
35
- </WButton>
36
- </template>
37
-
38
- <script setup>
39
- const emit = defineEmits(["action"]);
40
- </script>
@@ -1,17 +0,0 @@
1
- declare var __VLS_10: {};
2
- type __VLS_Slots = {} & {
3
- default?: (props: typeof __VLS_10) => any;
4
- };
5
- declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
6
- action: (action: "minimize") => any;
7
- }, string, import("vue").PublicProps, Readonly<{}> & Readonly<{
8
- onAction?: ((action: "minimize") => any) | undefined;
9
- }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
10
- declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
11
- declare const _default: typeof __VLS_export;
12
- export default _default;
13
- type __VLS_WithSlots<T, S> = T & {
14
- new (): {
15
- $slots: S;
16
- };
17
- };
@@ -1,28 +0,0 @@
1
- type __VLS_ModelProps = {
2
- /**
3
- * If there is a `window.electron.on` api that allows listening to events and main sends an `always-on-top-changed`, it will update the state of the pin.
4
- */
5
- modelValue?: boolean;
6
- };
7
- declare var __VLS_10: {
8
- alwaysOnTop: any;
9
- };
10
- type __VLS_Slots = {} & {
11
- default?: (props: typeof __VLS_10) => any;
12
- };
13
- declare const __VLS_base: import("vue").DefineComponent<__VLS_ModelProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
14
- "update:modelValue": (value: boolean) => any;
15
- } & {
16
- action: (action: "togglePin") => any;
17
- }, string, import("vue").PublicProps, Readonly<__VLS_ModelProps> & Readonly<{
18
- onAction?: ((action: "togglePin") => any) | undefined;
19
- "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
20
- }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
21
- declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
22
- declare const _default: typeof __VLS_export;
23
- export default _default;
24
- type __VLS_WithSlots<T, S> = T & {
25
- new (): {
26
- $slots: S;
27
- };
28
- };
@@ -1,52 +0,0 @@
1
- <template>
2
- <WButton
3
- aria-label="Toggle Always On Top"
4
- auto-title-from-aria
5
- :border="false"
6
- :class="twMerge(
7
- `
8
- p-0
9
- hover:text-accent-500
10
- `,
11
- alwaysOnTop && `
12
- [&_.default-icon_svg]:drop-shadow-[0_1px_1px_rgba(0,0,0,0.5)]
13
- `,
14
- !alwaysOnTop && `
15
- text-neutral-400
16
- dark:text-neutral-600
17
- `
18
- )"
19
-
20
- @click="emit('action', 'togglePin')"
21
- >
22
- <slot v-bind="{ alwaysOnTop }">
23
- <WIcon
24
- :class="
25
- twMerge(
26
- `
27
- default-icon
28
- w-[var(--electron-wc-size)]
29
- h-[var(--electron-wc-size)]
30
- flex items-center justify-center
31
- scale-105
32
- `
33
- )
34
- "
35
- >
36
- <iOcticonPin16/>
37
- </WIcon>
38
- </slot>
39
- </WButton>
40
- </template>
41
-
42
- <script setup>
43
- import { twMerge } from "#imports";
44
- import iOcticonPin16 from "~icons/octicon/pin-16";
45
- const emit = defineEmits(["action"]);
46
- const alwaysOnTop = defineModel({ type: Boolean, ...{ default: false } });
47
- if (import.meta.client && window?.electron?.on) {
48
- window.electron.on("always-on-top-changed", (val) => {
49
- alwaysOnTop.value = val;
50
- });
51
- }
52
- </script>
@@ -1,28 +0,0 @@
1
- type __VLS_ModelProps = {
2
- /**
3
- * If there is a `window.electron.on` api that allows listening to events and main sends an `always-on-top-changed`, it will update the state of the pin.
4
- */
5
- modelValue?: boolean;
6
- };
7
- declare var __VLS_10: {
8
- alwaysOnTop: any;
9
- };
10
- type __VLS_Slots = {} & {
11
- default?: (props: typeof __VLS_10) => any;
12
- };
13
- declare const __VLS_base: import("vue").DefineComponent<__VLS_ModelProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
14
- "update:modelValue": (value: boolean) => any;
15
- } & {
16
- action: (action: "togglePin") => any;
17
- }, string, import("vue").PublicProps, Readonly<__VLS_ModelProps> & Readonly<{
18
- onAction?: ((action: "togglePin") => any) | undefined;
19
- "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
20
- }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
21
- declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
22
- declare const _default: typeof __VLS_export;
23
- export default _default;
24
- type __VLS_WithSlots<T, S> = T & {
25
- new (): {
26
- $slots: S;
27
- };
28
- };
@@ -1,8 +0,0 @@
1
- import type { DeepPartial } from "@alanscodelog/utils";
2
- import type { IpcRenderer } from "electron";
3
- /**
4
- * Helper for building an api object.
5
- *
6
- * @experimental
7
- */
8
- export declare function apiBuilder<TPreloadMeta extends Record<string, any>, TRawApi extends Record<string, any> = Record<string, any>, TBuilders extends ((meta: DeepPartial<TPreloadMeta>, ipcRenderer: IpcRenderer) => any)[] = ((meta: DeepPartial<TPreloadMeta>, ipcRenderer: IpcRenderer) => any)[], TBuilderOutput extends ReturnType<TBuilders[number]> = ReturnType<TBuilders[number]>>(ipcRenderer: IpcRenderer, api: TRawApi, meta: TPreloadMeta, builders: TBuilders): TRawApi & TBuilderOutput;
@@ -1,9 +0,0 @@
1
- import defu from "defu";
2
- export function apiBuilder(ipcRenderer, api, meta, builders) {
3
- const resolutions = [];
4
- resolutions.push(api);
5
- for (const builder of builders) {
6
- resolutions.push(builder(meta, ipcRenderer));
7
- }
8
- return defu(...resolutions.reverse());
9
- }
@@ -1,4 +0,0 @@
1
- export declare function createBroadcastHandlers<TEvents extends Record<string, (...args: any) => any>>(key: string): {
2
- on: <T extends keyof TEvents>(event: T, listener: TEvents[T]) => void;
3
- off: <T extends keyof TEvents>(event: T, listener: TEvents[T]) => void;
4
- };
@@ -1,30 +0,0 @@
1
- import { ipcRenderer } from "electron";
2
- export function createBroadcastHandlers(key) {
3
- const listeners = /* @__PURE__ */ new Map();
4
- ipcRenderer.on(key, (_e, eventName, ...args) => {
5
- const cbs = listeners.get(eventName);
6
- if (cbs) {
7
- for (const cb of cbs) {
8
- cb(...args);
9
- }
10
- }
11
- });
12
- function on(event, listener) {
13
- const cbs = listeners.get(event);
14
- if (cbs) {
15
- cbs.push(listener);
16
- } else {
17
- listeners.set(event, [listener]);
18
- }
19
- }
20
- function off(event, listener) {
21
- const cbs = listeners.get(event);
22
- if (cbs) {
23
- cbs.splice(cbs.indexOf(listener), 1);
24
- }
25
- }
26
- return {
27
- on,
28
- off
29
- };
30
- }
@@ -1,2 +0,0 @@
1
- import type { BrowserWindow } from "electron";
2
- export declare function createBroadcaster<TEvents extends Record<string, (...args: any) => any>>(key: string, getWindows: () => BrowserWindow[]): <T extends keyof TEvents>(event: T, ...args: Parameters<TEvents[T]>) => void;
@@ -1,7 +0,0 @@
1
- export function createBroadcaster(key, getWindows) {
2
- return function broadcast(event, ...args) {
3
- for (const win of getWindows()) {
4
- win.webContents.send(key, event, ...args);
5
- }
6
- };
7
- }
@@ -1,14 +0,0 @@
1
- export declare function createNuxtFileProtocolHandler(session: Electron.Session, basePath: string,
2
- /**
3
- * If any route starts with one of these keys, it will get rerouted to the given value.
4
- *
5
- * At least `/api` should be added for a basic nuxt app to work correctly.
6
- *
7
- *
8
- * ```ts
9
- * routeProxies: {
10
- * "/api": "http://localhost:3000/api",
11
- * }
12
- * ```
13
- */
14
- routeProxies: Record<string, string>): void;
@@ -1,20 +0,0 @@
1
- import { keys } from "@alanscodelog/utils/keys";
2
- import { net } from "electron";
3
- import path from "node:path";
4
- export function createNuxtFileProtocolHandler(session, basePath, routeProxies) {
5
- const routeProxyKeys = keys(routeProxies);
6
- session.protocol.handle("file", async (request) => {
7
- const url = decodeURIComponent(request.url.slice(7));
8
- const newUrl = path.isAbsolute(url) ? path.resolve(basePath, url.slice(1)) : path.resolve(basePath, url);
9
- const proxyKey = routeProxyKeys.find((key) => url.startsWith(key));
10
- if (proxyKey) {
11
- const proxyUrl = routeProxies[proxyKey];
12
- return net.fetch(proxyUrl + url);
13
- }
14
- const res = await net.fetch(`file://${newUrl}`, {
15
- // avoid infinite loop
16
- bypassCustomProtocolHandlers: true
17
- }).catch((err) => new Response(err, { status: 404 }));
18
- return res;
19
- });
20
- }
@@ -1,19 +0,0 @@
1
- import type { IpcRenderer } from "electron";
2
- import type { WindowControlsApi } from "./types.js";
3
- /**
4
- * Creates the apis to control the window from the preload script / client.
5
- *
6
- * ```ts
7
- * // the default handler expects it to exist under `electron.api.ui.windowAction`
8
- * // but you can configure it to use a different path
9
- * constextBridge.exposeInMainWorld("electron", {
10
- * api: {
11
- * ui: {
12
- * ...createWindowControlsApi("windowAction")
13
- * }
14
- * }
15
- * })
16
- * ```
17
- */
18
- export declare function createWindowControlsApi(ipcRenderer: IpcRenderer, name: string): Record<string, WindowControlsApi>;
19
- export declare const windowControlsMessageKey = "window-control-action";
@@ -1,6 +0,0 @@
1
- import { promisifyApi } from "./promisifyApi.js";
2
- const key = "window-control-action";
3
- export function createWindowControlsApi(ipcRenderer, name) {
4
- return promisifyApi(ipcRenderer, name, key);
5
- }
6
- export const windowControlsMessageKey = key;
@@ -1,4 +0,0 @@
1
- import type { BrowserWindow } from "electron";
2
- export declare function createWindowControlsApiHandler(
3
- /** Mostly for logging. Does not replace the action. */
4
- cb?: (win: BrowserWindow | undefined, action: "close" | "minimize" | "toggleMaximize" | "togglePin") => void): void;
@@ -1,24 +0,0 @@
1
- import { windowControlsMessageKey } from "./createWindowControlsApi.js";
2
- import { promisifyReply } from "./promisifyReply.js";
3
- export function createWindowControlsApiHandler(cb) {
4
- promisifyReply(windowControlsMessageKey, async (win, action) => {
5
- switch (action) {
6
- case "close":
7
- win?.close();
8
- break;
9
- case "minimize":
10
- win?.minimize();
11
- break;
12
- case "toggleMaximize":
13
- console.log(win?.isMaximized());
14
- win?.isMaximized() ? win?.unmaximize() : win?.maximize();
15
- break;
16
- case "togglePin":
17
- win?.setAlwaysOnTop(!win?.isAlwaysOnTop());
18
- break;
19
- default:
20
- throw new Error(`Invalid action: ${action}`);
21
- }
22
- cb?.(win, action);
23
- });
24
- }
@@ -1,11 +0,0 @@
1
- import { BrowserWindow } from "electron";
2
- /**
3
- * Gets the window that sent the event if it exists, otherwise tries to use the focused window.
4
- *
5
- * Set `defaultToFocused` to false to only use the sender window.
6
- *
7
- * Returns undefined if no window is found.
8
- */
9
- export declare function getEventWindow(e: Electron.IpcMainEvent, { defaultToFocused }?: {
10
- defaultToFocused?: boolean | undefined;
11
- }): BrowserWindow | undefined;
@@ -1,8 +0,0 @@
1
- import { BrowserWindow } from "electron";
2
- export function getEventWindow(e, { defaultToFocused = true } = {}) {
3
- const senderWindow = BrowserWindow.fromId(e.sender.id);
4
- if (defaultToFocused) {
5
- return senderWindow ?? BrowserWindow.getFocusedWindow() ?? void 0;
6
- }
7
- return senderWindow ?? void 0;
8
- }