├── .gitignore ├── .hlint.yaml ├── .stylish-haskell.yaml ├── LICENSE.md ├── README.md ├── TODO.md ├── ghcjs-electron.cabal └── src ├── GHCJS ├── Array.hs ├── Callback.hs ├── Electron.hs ├── Electron │ ├── Accelerator.hs │ ├── App.hs │ ├── AutoUpdater.hs │ ├── BrowserWindow.hs │ ├── BrowserWindowProxy.hs │ ├── ClientRequest.hs │ ├── Clipboard.hs │ ├── ContentTracing.hs │ ├── Cookies.hs │ ├── CrashReporter.hs │ ├── Debugger.hs │ ├── DesktopCapturer.hs │ ├── Dialog.hs │ ├── DownloadItem.hs │ ├── GlobalShortcut.hs │ ├── IPCMain.hs │ ├── IPCRenderer.hs │ ├── IncomingMessage.hs │ ├── Locales.hs │ ├── Menu.hs │ ├── MenuItem.hs │ ├── NativeImage.hs │ ├── Net.hs │ ├── PowerMonitor.hs │ ├── PowerSaveBlocker.hs │ ├── Process.hs │ ├── Protocol.hs │ ├── Remote.hs │ ├── Screen.hs │ ├── Session.hs │ ├── Shell.hs │ ├── SystemPreferences.hs │ ├── Tray.hs │ ├── Types.hs │ ├── Utility.hs │ ├── WebContents.hs │ ├── WebFrame.hs │ ├── WebRequest.hs │ └── Window.hs └── Node │ ├── Buffer.hs │ ├── Console.hs │ ├── Crypto.hs │ ├── Crypto │ ├── Certificate.hs │ ├── Cipher.hs │ ├── Decipher.hs │ ├── DiffieHellman.hs │ ├── ECDH.hs │ ├── HMAC.hs │ ├── Hash.hs │ ├── Sign.hs │ └── Verify.hs │ ├── DNS.hs │ ├── Error.hs │ ├── EventEmitter.hs │ └── Stream.hs └── Tests.hs /.gitignore: -------------------------------------------------------------------------------- 1 | /dist/ 2 | /cabal-dev/ 3 | /.virtualenv/ 4 | /.hpc/ 5 | /.hsenv/ 6 | /.cabal-sandbox/ 7 | cabal.sandbox.config 8 | cabal.config 9 | *.o 10 | *.hi 11 | *.chi 12 | *.chs.h 13 | *.dyn_o 14 | *.dyn_hi 15 | *.prof 16 | *.aux 17 | *.hp 18 | *.tix 19 | default.nix 20 | shell.nix 21 | scratchpad.hs 22 | *~ 23 | [#]*[#] 24 | .\#* 25 | data/ 26 | result 27 | guest 28 | *.qcow2 29 | TAGS 30 | tags 31 | -------------------------------------------------------------------------------- /.hlint.yaml: -------------------------------------------------------------------------------- 1 | # ############################## 2 | # ## HLint configuration file ## 3 | # ############################## 4 | 5 | - ignore: {name: Use camelCase} 6 | 7 | # ### Specify additional command line arguments 8 | # 9 | # - arguments: [--color, --cpp-simple, -XQuasiQuotes] 10 | # 11 | # ### Control which extensions/flags/modules/functions can be used 12 | # 13 | # - extensions: 14 | # # All extensions are banned by default 15 | # - default: false 16 | # # Only these listed extensions can be used 17 | # - name: [PatternGuards, ViewPatterns] 18 | # # CPP can only be used in a given module 19 | # - {name: CPP, within: CrossPlatform} 20 | # 21 | # - flags: 22 | # - {name: -w, within: []} # -w is allowed nowhere 23 | # 24 | # - modules: 25 | # # if you import Data.Set qualified, it must be as 'Set' 26 | # - {name: [Data.Set, Data.HashSet], as: Set} 27 | # # Certain modules are banned entirely 28 | # - {name: Control.Arrow, within: []} 29 | # 30 | # - functions: 31 | # # unsafePerformIO can only appear in no modules 32 | # - {name: unsafePerformIO, within: []} 33 | # 34 | # ### Add custom hints for this project 35 | # 36 | # # Suggest replacing "wibbleMany [myvar]" with "wibbleOne myvar" 37 | # - error: {lhs: "wibbleMany [x]", rhs: wibbleOne x} 38 | # 39 | # ### Turn on hints that are off by default 40 | # 41 | # # Ban "module X(module X) where", to require a real export list 42 | # - warn: {name: Use explicit module export list} 43 | # 44 | # # Replace a $ b $ c with a . b $ c 45 | # - group: {name: dollar, enabled: true} 46 | # 47 | # # Generalise map to fmap, ++ to <> 48 | # - group: {name: generalise, enabled: true} 49 | # 50 | # ### Ignore some builtin hints 51 | # 52 | # # Ignore hints globally 53 | # - ignore: {name: Use let} 54 | # # Ignore hints within certain modules 55 | # - ignore: {name: Use const, within: SpecialModule} 56 | # 57 | # ### Define some custom infix operators 58 | # 59 | # - fixity: infixr 3 ~^#^~ 60 | -------------------------------------------------------------------------------- /.stylish-haskell.yaml: -------------------------------------------------------------------------------- 1 | steps: 2 | # Align imports 3 | - imports: 4 | align: global 5 | list_padding: 17 6 | long_list_align: new_line 7 | 8 | # Align and remove redundant language pragmas 9 | - language_pragmas: 10 | style: vertical 11 | align: true 12 | remove_redundant: true 13 | 14 | # Align records 15 | - simple_align: 16 | cases: true 17 | top_level_patterns: false 18 | records: true 19 | 20 | # Replace each tab by two spaces 21 | - tabs: 22 | spaces: 2 23 | 24 | # Remove trailing whitespace 25 | - trailing_whitespace: {} 26 | 27 | # Max number of columns per line 28 | columns: 80 29 | 30 | # Replace CR-LF by LF 31 | newline: lf 32 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright © 2017 Remy Goldschmidt 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ghcjs-electron 2 | 3 | GHCJS FFI bindings to the [Electron API][electron]. 4 | 5 | [electron]: https://electron.atom.io/docs/api 6 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | # Implemented modules 2 | 3 | - [x] Accelerator 4 | - [x] App 5 | - [ ] AutoUpdater 6 | - [ ] BrowserWindow 7 | - [x] BrowserWindowProxy 8 | - [ ] ClientRequest 9 | - [x] Clipboard 10 | - [x] ContentTracing 11 | - [ ] Cookies 12 | - [x] CrashReporter 13 | - [x] Debugger 14 | - [ ] DesktopCapturer 15 | - [x] Dialog 16 | - [ ] DownloadItem 17 | - [x] GlobalShortcut 18 | - [x] IPCMain 19 | - [x] IPCRenderer 20 | - [ ] IncomingMessage 21 | - [x] Locales 22 | - [ ] Menu 23 | - [ ] MenuItem 24 | - [ ] NativeImage 25 | - [ ] Net 26 | - [ ] PowerMonitor 27 | - [x] PowerSaveBlocker 28 | - [ ] Process 29 | - [ ] Protocol 30 | - [ ] Remote 31 | - [ ] Screen 32 | - [ ] Session 33 | - [x] Shell 34 | - [ ] SystemPreferences 35 | - [x] Tray 36 | - [ ] WebContents 37 | - [ ] WebFrame 38 | - [ ] WebRequest 39 | - [x] Window 40 | -------------------------------------------------------------------------------- /ghcjs-electron.cabal: -------------------------------------------------------------------------------- 1 | name: ghcjs-electron 2 | author: Remy Goldschmidt 3 | version: 0.0.1 4 | stability: Experimental 5 | build-type: Simple 6 | cabal-version: >= 1.10 7 | category: Web, JavaScript, Bindings 8 | copyright: 2017 Remy Goldschmidt 9 | maintainer: taktoa@gmail.com 10 | homepage: https://github.com/taktoa/ghcjs-electron 11 | bug-reports: https://github.com/taktoa/ghcjs-electron/issues 12 | license: MIT 13 | license-file: LICENSE.md 14 | extra-source-files: README.md 15 | synopsis: GHCJS FFI bindings to the Electron API. 16 | description: GHCJS FFI bindings to the Electron API. 17 | 18 | source-repository head 19 | type: git 20 | location: https://github.com/taktoa/ghcjs-electron.git 21 | 22 | library 23 | build-depends: base == 4.* 24 | , text == 1.2.* 25 | , stm == 2.4.* 26 | , vinyl == 0.5.* 27 | , containers == 0.5.* 28 | , ghcjs-prim 29 | , ghcjs-base 30 | -- , transformers == 0.5.* 31 | -- , mtl == 2.2.* 32 | -- , bytestring == 0.10.* 33 | -- , lens == 4.15.* 34 | -- , process == 1.4.* 35 | -- , data-default == 0.7.* 36 | -- , semigroups == 0.18.* 37 | -- , containers == 0.5.* 38 | -- , pipes == 4.3.* 39 | -- , vector == 0.11.* 40 | -- , deepseq == 1.4.* 41 | default-language: Haskell2010 42 | exposed-modules: GHCJS.Electron 43 | , GHCJS.Electron.Types 44 | , GHCJS.Electron.Utility 45 | -- Node modules 46 | , GHCJS.Node.Buffer 47 | , GHCJS.Node.Console 48 | , GHCJS.Node.Crypto 49 | , GHCJS.Node.Crypto.Certificate 50 | , GHCJS.Node.Crypto.Cipher 51 | , GHCJS.Node.Crypto.Decipher 52 | , GHCJS.Node.Crypto.DiffieHellman 53 | , GHCJS.Node.Crypto.ECDH 54 | , GHCJS.Node.Crypto.Hash 55 | , GHCJS.Node.Crypto.HMAC 56 | , GHCJS.Node.Crypto.Sign 57 | , GHCJS.Node.Crypto.Verify 58 | , GHCJS.Node.DNS 59 | , GHCJS.Node.Error 60 | , GHCJS.Node.EventEmitter 61 | , GHCJS.Node.Stream 62 | -- Electron modules 63 | , GHCJS.Electron.Accelerator 64 | , GHCJS.Electron.App 65 | , GHCJS.Electron.AutoUpdater 66 | , GHCJS.Electron.BrowserWindow 67 | , GHCJS.Electron.BrowserWindowProxy 68 | , GHCJS.Electron.ClientRequest 69 | , GHCJS.Electron.Clipboard 70 | , GHCJS.Electron.ContentTracing 71 | , GHCJS.Electron.Cookies 72 | , GHCJS.Electron.CrashReporter 73 | , GHCJS.Electron.Debugger 74 | , GHCJS.Electron.DesktopCapturer 75 | , GHCJS.Electron.Dialog 76 | , GHCJS.Electron.DownloadItem 77 | , GHCJS.Electron.GlobalShortcut 78 | , GHCJS.Electron.IncomingMessage 79 | , GHCJS.Electron.IPCMain 80 | , GHCJS.Electron.IPCRenderer 81 | , GHCJS.Electron.Locales 82 | , GHCJS.Electron.Menu 83 | , GHCJS.Electron.MenuItem 84 | , GHCJS.Electron.NativeImage 85 | , GHCJS.Electron.Net 86 | , GHCJS.Electron.PowerMonitor 87 | , GHCJS.Electron.PowerSaveBlocker 88 | , GHCJS.Electron.Process 89 | , GHCJS.Electron.Protocol 90 | , GHCJS.Electron.Remote 91 | , GHCJS.Electron.Screen 92 | , GHCJS.Electron.Session 93 | , GHCJS.Electron.Shell 94 | , GHCJS.Electron.SystemPreferences 95 | -- , GHCJS.Electron.TouchBar 96 | -- , GHCJS.Electron.TouchBar.Button 97 | -- , GHCJS.Electron.TouchBar.ColorPicker 98 | -- , GHCJS.Electron.TouchBar.Group 99 | -- , GHCJS.Electron.TouchBar.Label 100 | -- , GHCJS.Electron.TouchBar.Popover 101 | -- , GHCJS.Electron.TouchBar.Scrubber 102 | -- , GHCJS.Electron.TouchBar.SegmentedControl 103 | -- , GHCJS.Electron.TouchBar.Slider 104 | -- , GHCJS.Electron.TouchBar.Spacer 105 | , GHCJS.Electron.Tray 106 | , GHCJS.Electron.WebContents 107 | , GHCJS.Electron.WebFrame 108 | , GHCJS.Electron.WebRequest 109 | , GHCJS.Electron.Window 110 | other-modules: GHCJS.Array 111 | , GHCJS.Callback 112 | ghc-options: -Wall -g 113 | -fno-warn-type-defaults 114 | -fno-warn-unused-do-bind 115 | -fno-warn-unused-imports 116 | hs-source-dirs: src 117 | 118 | test-suite tests 119 | build-depends: base == 4.* 120 | , hspec == 2.4.* 121 | , ghcjs-electron 122 | , ghcjs-base 123 | type: exitcode-stdio-1.0 124 | default-language: Haskell2010 125 | ghc-options: -fhpc -Wall 126 | main-is: src/Tests.hs 127 | -------------------------------------------------------------------------------- /src/GHCJS/Array.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveGeneric #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Array 5 | ( Array (..) 6 | ) where 7 | 8 | import GHCJS.Types 9 | 10 | import GHC.Generics 11 | 12 | -- | FIXME: doc 13 | newtype Array t 14 | = MkArray JSVal 15 | deriving (Generic) 16 | -------------------------------------------------------------------------------- /src/GHCJS/Callback.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | {-# LANGUAGE FlexibleInstances #-} 3 | {-# LANGUAGE FunctionalDependencies #-} 4 | {-# LANGUAGE JavaScriptFFI #-} 5 | {-# LANGUAGE MultiParamTypeClasses #-} 6 | {-# LANGUAGE TypeOperators #-} 7 | {-# LANGUAGE UndecidableInstances #-} 8 | 9 | -- | FIXME: doc 10 | module GHCJS.Callback 11 | ( module GHCJS.Callback -- FIXME: specific import list 12 | , module Exported 13 | ) where 14 | 15 | import Control.Monad (join) 16 | 17 | import GHCJS.Foreign.Callback as Exported 18 | import GHCJS.Marshal 19 | import GHCJS.Marshal.Pure 20 | import GHCJS.Types (IsJSVal, JSVal) 21 | import Unsafe.Coerce 22 | 23 | class (~~>) x y | y -> x 24 | 25 | instance (IO ()) ~~> (IO ()) 26 | 27 | instance (PFromJSVal a, b ~~> b') => (JSVal -> b) ~~> (a -> b') 28 | 29 | class CallbackCoerce x y 30 | instance (x ~~> y) => CallbackCoerce x y 31 | 32 | coerceCallback :: (x ~~> y) => Callback x -> Callback y 33 | coerceCallback = unsafeCoerce 34 | 35 | makeAsyncCallback0 :: IO () -> IO (Callback (IO ())) 36 | makeAsyncCallback0 m = fmap coerceCallback (asyncCallback m) 37 | 38 | makeAsyncCallback1 :: (PFromJSVal a) 39 | => (a -> IO ()) -> IO (Callback (a -> IO ())) 40 | makeAsyncCallback1 f = let f' x = f (pFromJSVal x) 41 | in fmap coerceCallback (asyncCallback1 f') 42 | 43 | makeAsyncCallback2 :: (PFromJSVal a, PFromJSVal b) 44 | => (a -> b -> IO ()) -> IO (Callback (a -> b -> IO ())) 45 | makeAsyncCallback2 f = let f' x y = f (pFromJSVal x) (pFromJSVal y) 46 | in fmap coerceCallback (asyncCallback2 f') 47 | 48 | makeAsyncCallback3 :: (PFromJSVal a, PFromJSVal b, PFromJSVal c) 49 | => (a -> b -> c -> IO ()) 50 | -> IO (Callback (a -> b -> c -> IO ())) 51 | makeAsyncCallback3 f = let f' x y z 52 | = f (pFromJSVal x) (pFromJSVal y) (pFromJSVal z) 53 | in fmap coerceCallback (asyncCallback3 f') 54 | -------------------------------------------------------------------------------- /src/GHCJS/Electron.hs: -------------------------------------------------------------------------------- 1 | module GHCJS.Electron where 2 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/Accelerator.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveGeneric #-} 2 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} 3 | {-# LANGUAGE JavaScriptFFI #-} 4 | {-# LANGUAGE LambdaCase #-} 5 | {-# LANGUAGE OverloadedStrings #-} 6 | 7 | -- | FIXME: doc 8 | module GHCJS.Electron.Accelerator 9 | ( module Exported 10 | , module GHCJS.Electron.Accelerator 11 | ) where 12 | 13 | import Control.Arrow 14 | import Control.Monad 15 | 16 | import Data.Char (isDigit) 17 | import Data.Maybe 18 | 19 | import GHCJS.Electron.Types 20 | import GHCJS.Electron.Types as Exported (Accelerator) 21 | import GHCJS.Types 22 | 23 | import Data.Text (Text) 24 | import qualified Data.Text as T 25 | 26 | import GHC.Generics (Generic) 27 | 28 | -- | Compile a 'KeyQuery' to a list of 'Accelerator's. 29 | runKeyQuery :: KeyQuery -> [Accelerator] 30 | runKeyQuery = undefined -- FIXME: implement 31 | 32 | -- | Represents a particular subset of the set of all key combinations. 33 | newtype KeyQuery 34 | = MkKeyQuery 35 | { _keyCombinations :: [KeyCombination] } 36 | deriving (Eq, Show, Read, Generic, Monoid) 37 | 38 | simpleKQ :: [KeyModifier] -> KeyCode -> KeyQuery 39 | simpleKQ modifier key = MkKeyQuery [MkKeyCombination key modifier] 40 | 41 | -- | A combination of a key and a modifier. 42 | data KeyCombination 43 | = MkKeyCombination 44 | { _kcCode :: !KeyCode 45 | , _kcModifiers :: [KeyModifier] 46 | } 47 | deriving (Eq, Show, Read, Generic) 48 | 49 | -- | A key modifier. 50 | data KeyModifier 51 | = KeyModAlt 52 | -- ^ This is bound to the "Alt" key on PC keyboards, and it is bound 53 | -- to the "Alt/Option" key on Mac keyboards. 54 | | KeyModAltGr 55 | -- ^ This is bound to the "AltGr" key on international PC keyboards. 56 | | KeyModCommand 57 | -- ^ This is bound to the "Command ⌘" key on Mac keyboards. 58 | | KeyModControl 59 | -- ^ This is bound to the "Ctrl" key on PC keyboards, and it is bound 60 | -- to the "Control" key on Mac keyboards. 61 | | KeyModShift 62 | -- ^ This is bound to the "Shift" key on both PC and Mac keyboards. 63 | | KeyModSuper 64 | -- ^ This is bound to the "Windows ⊞" key on PC keyboards, and it is bound 65 | -- to the "Command ⌘" key on Mac keyboards. 66 | deriving (Eq, Show, Read, Generic) 67 | 68 | -- | FIXME: doc 69 | keyModToAccelerator :: KeyModifier -> Text 70 | keyModToAccelerator KeyModCommand = "Command" 71 | keyModToAccelerator KeyModControl = "Control" 72 | keyModToAccelerator KeyModAlt = "Alt" 73 | keyModToAccelerator KeyModAltGr = "AltGr" 74 | keyModToAccelerator KeyModShift = "Shift" 75 | keyModToAccelerator KeyModSuper = "Super" 76 | 77 | -- | A key code. 78 | data KeyCode 79 | = KeyCodeLetter !KeyCodeLetter 80 | | KeyCodeDigit !KeyCodeDigit 81 | | KeyCodeSymbol !KeyCodeSymbol 82 | | KeyCodeFunction !KeyCodeFunction 83 | | KeyCodeNavigation !KeyCodeNavigation 84 | | KeyCodeSpecial !KeyCodeSpecial 85 | | KeyCodeMisc !KeyCodeMisc 86 | deriving (Eq, Show, Read, Generic) 87 | 88 | -- | FIXME: doc 89 | keyCodeToAccelerator :: KeyCode -> Text 90 | keyCodeToAccelerator = go >>> fromMaybe (error "This should not happen.") 91 | where 92 | go :: KeyCode -> Maybe Text 93 | go (KeyCodeLetter kcl) = goLetter kcl 94 | go (KeyCodeDigit kcd) = goDigit kcd 95 | go (KeyCodeSymbol kcs) = goSymbol kcs 96 | go (KeyCodeFunction kcf) = goFunction kcf 97 | go (KeyCodeNavigation kcn) = goNavigation kcn 98 | go (KeyCodeSpecial kcs) = goSpecial kcs 99 | go (KeyCodeMisc kcm) = goMisc kcm 100 | 101 | goLetter :: KeyCodeLetter -> Maybe Text 102 | goDigit :: KeyCodeDigit -> Maybe Text 103 | goSymbol :: KeyCodeSymbol -> Maybe Text 104 | goFunction :: KeyCodeFunction -> Maybe Text 105 | goNavigation :: KeyCodeNavigation -> Maybe Text 106 | goSpecial :: KeyCodeSpecial -> Maybe Text 107 | goMisc :: KeyCodeMisc -> Maybe Text 108 | 109 | goLetter = stripKey >=> checkLen 1 1 110 | goDigit = stripKey >=> checkLen 1 1 111 | goSymbol = \case KeyBacktick -> pure "`" 112 | KeySemicolon -> pure ";" 113 | KeyQuote -> pure "'" 114 | KeyOBracket -> pure "[" 115 | KeyCBracket -> pure "]" 116 | KeyBackslash -> pure "\\" 117 | KeySlash -> pure "/" 118 | KeyPeriod -> pure "." 119 | KeyComma -> pure "," 120 | KeyHyphen -> pure "-" 121 | KeyEquals -> pure "=" 122 | goFunction = stripKey >=> \key -> do guard (T.all isDigit key) 123 | checkLen 1 2 key 124 | goNavigation = stripKey >=> checkLen 0 10 125 | goSpecial = \case KeyMediaNext -> pure "MediaNextTrack" 126 | KeyMediaPrev -> pure "MediaPreviousTrack" 127 | KeyMediaStop -> pure "MediaStop" 128 | KeyMediaPlay -> pure "MediaPlayPause" 129 | KeyVolumeUp -> pure "VolumeUp" 130 | KeyVolumeDown -> pure "VolumeDown" 131 | KeyVolumeMute -> pure "VolumeMute" 132 | goMisc = stripKey >=> checkLen 0 12 133 | 134 | checkLen :: Int -> Int -> Text -> Maybe Text 135 | checkLen minLen maxLen t = do 136 | guard (T.length t >= minLen) 137 | guard (T.length t <= maxLen) 138 | pure t 139 | 140 | stripKey :: (Show s) => s -> Maybe Text 141 | stripKey x = do let shown = T.pack (show x) 142 | guard (T.take 3 shown == "Key") 143 | pure $ T.drop 3 shown 144 | 145 | -- | Key codes that represent letters. 146 | data KeyCodeLetter 147 | = KeyA | KeyB | KeyC | KeyD | KeyE | KeyF | KeyG | KeyH | KeyI | KeyJ 148 | | KeyK | KeyL | KeyM | KeyN | KeyO | KeyP | KeyQ | KeyR | KeyS | KeyT 149 | | KeyU | KeyV | KeyW | KeyX | KeyY | KeyZ 150 | deriving (Eq, Enum, Bounded, Show, Read, Generic) 151 | 152 | -- | Key codes that represent digits. 153 | data KeyCodeDigit 154 | = Key0 | Key1 | Key2 | Key3 | Key4 | Key5 | Key6 | Key7 | Key8 | Key9 155 | deriving (Eq, Enum, Bounded, Show, Read, Generic) 156 | 157 | -- | Key codes that represent symbols. 158 | data KeyCodeSymbol 159 | = KeyBacktick -- ^ The backtick/tilde key. 160 | | KeySemicolon -- ^ The semicolon/colon key. 161 | | KeyQuote -- ^ The single/double quote key. 162 | | KeyOBracket -- ^ The open-square/curly bracket key. 163 | | KeyCBracket -- ^ The close-square/curly bracket key. 164 | | KeyBackslash -- ^ The backslash/pipe key. 165 | | KeySlash -- ^ The slash/question mark key. 166 | | KeyPeriod -- ^ The period/greater-than key. 167 | | KeyComma -- ^ The comma/less-than key. 168 | | KeyHyphen -- ^ The hyphen/underscore key. 169 | | KeyEquals -- ^ The equals/plus key. 170 | deriving (Eq, Enum, Bounded, Show, Read, Generic) 171 | 172 | -- | Key codes corresponding to the F1-F24 keys ("function" keys). 173 | data KeyCodeFunction 174 | = KeyF1 | KeyF2 | KeyF3 | KeyF4 | KeyF5 | KeyF6 175 | | KeyF7 | KeyF8 | KeyF9 | KeyF10 | KeyF11 | KeyF12 176 | | KeyF13 | KeyF14 | KeyF15 | KeyF16 | KeyF17 | KeyF18 177 | | KeyF19 | KeyF20 | KeyF21 | KeyF22 | KeyF23 | KeyF24 178 | deriving (Eq, Enum, Bounded, Show, Read, Generic) 179 | 180 | -- | Key codes corresponding to the arrow keys, page up/down, home, and end. 181 | data KeyCodeNavigation 182 | = KeyUp | KeyDown | KeyLeft | KeyRight 183 | | KeyPageUp | KeyPageDown | KeyHome | KeyEnd 184 | deriving (Eq, Enum, Bounded, Show, Read, Generic) 185 | 186 | -- | Key codes corresponding to special keys, like @XF86AudioPlayPause@. 187 | data KeyCodeSpecial 188 | = KeyMediaNext 189 | | KeyMediaPrev 190 | | KeyMediaStop 191 | | KeyMediaPlay 192 | | KeyVolumeUp 193 | | KeyVolumeDown 194 | | KeyVolumeMute 195 | deriving (Eq, Enum, Bounded, Show, Read, Generic) 196 | 197 | -- | Other various key codes. 198 | data KeyCodeMisc 199 | = KeySpace | KeyTab | KeyBackspace | KeyDelete | KeyEnter 200 | | KeyInsert | KeyEscape | KeyPrintScreen 201 | deriving (Eq, Enum, Bounded, Show, Read, Generic) 202 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/App.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.App 5 | ( module Exported 6 | , module GHCJS.Electron.App 7 | ) where 8 | 9 | import GHCJS.Electron.Types 10 | import GHCJS.Electron.Types as Exported (App (..)) 11 | import GHCJS.Types 12 | 13 | -- | Get the current 'App' as returned by @require("electron").app@. 14 | foreign import javascript safe 15 | "$r = require('electron').app;" 16 | getApp :: IO App 17 | 18 | -- | Try to close all windows. The before-quit event will first be emitted. 19 | -- If all windows are successfully closed, the will-quit event will be emitted 20 | -- and by default the application would be terminated. 21 | -- 22 | -- This method guarantees all beforeunload and unload handlers are correctly 23 | -- executed. It is possible that a window cancels the quitting by returning 24 | -- false in beforeunload handler. 25 | foreign import javascript safe 26 | "$1.quit();" 27 | unsafeQuit :: App -> IO () 28 | 29 | -- | Quit the application directly; it will not try to close all windows so 30 | -- cleanup code will not run. 31 | foreign import javascript safe 32 | "$1.terminate();" 33 | unsafeTerminate :: App -> IO () 34 | 35 | -- | Returns the current application directory. 36 | foreign import javascript safe 37 | "$1.getAppPath();" 38 | unsafeGetAppPath :: App -> IO Path 39 | 40 | -- | Get a special path with the given name. 41 | foreign import javascript safe 42 | "$r = $1.getPath($2);" 43 | unsafeGetPath :: App 44 | -> JSString 45 | -- ^ Should be one of the following: 46 | -- @"home"@, @"appData"@, @"userData"@, @"cache"@, 47 | -- @"userCache"@, @"temp"@, @"userDesktop"@, @"exe"@, 48 | -- @"module"@ 49 | -> IO Path 50 | -- ^ The path associated with the given name. 51 | 52 | -- | Overrides the path to a special directory or file associated with name. 53 | -- If the path specifies a directory that does not exist, the directory will 54 | -- be created by this method. On failure an Error would throw. 55 | -- 56 | -- By default web pages' cookies and caches will be stored under userData 57 | -- directory, if you want to change this location, you have to override the 58 | -- userData path before the ready event of app module gets emitted. 59 | foreign import javascript safe 60 | "$1.setPath($2, $3);" 61 | unsafeSetPath :: App 62 | -> JSString 63 | -- ^ Should be one of the following: 64 | -- @"home"@, @"appData"@, @"userData"@, @"cache"@, 65 | -- @"userCache"@, @"temp"@, @"userDesktop"@, @"exe"@, 66 | -- @"module"@ 67 | -> Path 68 | -- ^ A file path to set; will be created if it does not exist. 69 | -> IO () 70 | 71 | -- | Returns the version of loaded application. 72 | -- If no version is found in the application's @package.json@, then the 73 | -- version of current bundle or executable is returned instead. 74 | foreign import javascript safe 75 | "$r = $1.getVersion();" 76 | unsafeGetVersion :: App -> IO JSString 77 | 78 | -- | Returns the name of the loaded application. 79 | -- Usually the @name@ field of @package.json@ is a short lowercase string, 80 | -- according to the NPM module specification, so usually you should also 81 | -- specify the @productName@ field, which is your application's full 82 | -- capitalized name, and it will be preferred over @name@ by Electron. 83 | foreign import javascript safe 84 | "$r = $1.getName();" 85 | unsafeGetName :: App -> IO JSString 86 | 87 | -- | Given a URL, calls the given callback with the proxy used for that URL. 88 | foreign import javascript safe 89 | "$1.resolveProxy($2, $3);" 90 | unsafeResolveProxy :: App 91 | -> URL 92 | -- ^ The URL to resolve. 93 | -> Callback (Proxy -> IO ()) 94 | -- ^ The callback to call once the URL is resolved. 95 | -> IO () 96 | 97 | -- | Adds the given path to the recent documents list. 98 | -- This list is managed by the system; on Windows you can visit the list from 99 | -- the taskbar; on Mac OS you can visit it from the dock menu. 100 | foreign import javascript safe 101 | "$1.addRecentDocument($2);" 102 | unsafeAddRecent :: App 103 | -> Path 104 | -- ^ A path to add to the recent documents list. 105 | -> IO () 106 | 107 | -- | Clear the recent documents list. 108 | foreign import javascript safe 109 | "$1.clearRecentDocuments();" 110 | unsafeClearRecent :: App -> IO () 111 | 112 | -- | Adds tasks to the Tasks category of JumpList on Windows. 113 | -- This API is /only/ available on Windows. 114 | foreign import javascript safe 115 | "$1.setUserTasks($2);" 116 | unsafeSetUserTasks :: App 117 | -> JSVal 118 | -- ^ A list of tasks to which the user tasks will be set. 119 | -> IO () 120 | 121 | -- | FIXME: doc 122 | foreign import javascript safe 123 | "$r = $1.dock;" 124 | unsafeGetDock :: App -> IO BrowserWindow 125 | 126 | -- | FIXME: doc 127 | -- FIXME: may not make sense. 128 | foreign import javascript safe 129 | "$1.dock = $2;" 130 | unsafeSetDock :: App -> BrowserWindow -> IO () 131 | 132 | -- | FIXME: doc 133 | foreign import javascript safe 134 | "$r = $1.commandLine;" 135 | unsafeGetCommandLine :: App -> IO CommandLine 136 | 137 | -- | FIXME: doc 138 | -- FIXME: may not make sense. 139 | foreign import javascript safe 140 | "$1.commandLine = $2;" 141 | unsafeSetCommandLine :: App -> CommandLine -> IO () 142 | 143 | -- | This method makes your application a "Single Instance Application" instead 144 | -- of allowing multiple instances of your app to run. 145 | -- In other words, this will ensure that at most one instance of your 146 | -- application is running at any time, and launching a new instance will 147 | -- simply signal this instance and exit. 148 | -- NOTE: callback type is @(args: string[], workingDirectory: string) => bool@ 149 | -- FIXME: what does the callback do? what does the returned boolean mean? 150 | foreign import javascript safe 151 | "$r = $1.makeSingleInstance($2);" 152 | unsafeMakeSingleInstance :: App 153 | -> Callback (Array JSString -> JSString -> IO Bool) 154 | -- ^ FIXME: doc 155 | -> IO Bool 156 | 157 | -- | FIXME: doc 158 | foreign import javascript safe 159 | "$1.setAppUserModelId($2);" 160 | unsafeSetUserModelId :: App 161 | -> JSString 162 | -- ^ FIXME: doc 163 | -> IO () 164 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/AutoUpdater.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.AutoUpdater where 5 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/BrowserWindow.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.BrowserWindow where 5 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/BrowserWindowProxy.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | -- | The BrowserWindowProxy object is returned from window.open and provides 3 | -- limited functionality with the child window. 4 | module GHCJS.Electron.BrowserWindowProxy 5 | ( module Exported 6 | , module GHCJS.Electron.BrowserWindowProxy 7 | ) where 8 | 9 | import GHCJS.Electron.Types as Exported (BrowserWindowProxy) 10 | import GHCJS.Types 11 | 12 | -- | Removes focus from the child window. 13 | foreign import javascript safe 14 | "$1.blur();" 15 | browserBlur :: BrowserWindowProxy 16 | -> IO () 17 | 18 | -- | Forcefully closes the child window without calling its unload event. 19 | foreign import javascript safe 20 | "$1.close();" 21 | browserClose :: BrowserWindowProxy 22 | -> IO () 23 | 24 | -- | Evaluates the code in the child window. 25 | foreign import javascript safe 26 | "$1.eval($2);" 27 | browserEval :: BrowserWindowProxy 28 | -> JSString 29 | -- ^ code 30 | -> IO () 31 | 32 | -- | Focuses the child window (brings the window to front). 33 | foreign import javascript safe 34 | "$1.focus();" 35 | browserFocus :: BrowserWindowProxy 36 | -> IO () 37 | 38 | -- | Invokes the print dialog on the child window. 39 | foreign import javascript safe 40 | "$1.print();" 41 | browserPrint :: BrowserWindowProxy 42 | -> IO () 43 | 44 | -- | Send a message to the child window with the specified origin or use "*" 45 | -- for no origin preference. 46 | foreign import javascript safe 47 | "$1.postMessage($2, $3);" 48 | browserPostMessage :: BrowserWindowProxy 49 | -> JSString 50 | -- ^ message 51 | -> JSString 52 | -- ^ targetOrigin 53 | -> IO () 54 | 55 | -- | Check if the child window has been closed. 56 | foreign import javascript safe 57 | "$r = $1.closed;" 58 | browserIsClosed :: BrowserWindowProxy 59 | -> IO Bool 60 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/ClientRequest.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.ClientRequest where 5 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/Clipboard.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.Clipboard 5 | ( module Exported 6 | , module GHCJS.Electron.Clipboard 7 | ) where 8 | 9 | import GHCJS.Electron.Types 10 | import GHCJS.Electron.Types as Exported () 11 | import GHCJS.Types 12 | 13 | -- | Get the clipboard object for a given clipboard object. 14 | foreign import javascript safe 15 | "$r = { type: $1, obj: require('electron').clipboard };" 16 | unsafeGetClipboard :: JSString 17 | -- ^ A clipboard type, e.g.: @"selection"@, @"clipboard"@. 18 | -> IO Clipboard 19 | -- ^ A clipboard object. 20 | 21 | -- | Get the type of a given clipboard object. 22 | foreign import javascript safe 23 | "$r = $1.type;" 24 | unsafeClipboardType :: Clipboard 25 | -- ^ A clipboard object. 26 | -> IO JSString 27 | -- ^ A clipboard type, e.g.: @"selection"@, @"clipboard"@. 28 | 29 | -- | Get the current clipboard as plain text. 30 | foreign import javascript safe 31 | "$r = $1.obj.readText($1.type);" 32 | unsafeReadText :: Clipboard -- ^ The clipboard object. 33 | -> IO JSString -- ^ The text in the clipboard. 34 | 35 | -- | Set the clipboard to the given plain text string. 36 | foreign import javascript safe 37 | "$1.obj.writeText($2, $1.type);" 38 | unsafeWriteText :: Clipboard -- ^ The clipboard object. 39 | -> JSString -- ^ The contents to set the clipboard to. 40 | -> IO () 41 | 42 | -- | Get the current clipboard as an HTML string. 43 | foreign import javascript safe 44 | "$r = $1.obj.readHTML($1.type);" 45 | unsafeReadHTML :: Clipboard -- ^ The clipboard object. 46 | -> IO HTML -- ^ The HTML in the clipboard. 47 | 48 | -- | Set the clipboard to the given HTML string. 49 | foreign import javascript safe 50 | "$1.obj.writeHTML($2, $1.type);" 51 | unsafeWriteHTML :: Clipboard -- ^ The clipboard object. 52 | -> HTML -- ^ The contents to set the clipboard to. 53 | -> IO () 54 | 55 | -- | Get the image content in the clipboard as an 'Image'/@NativeImage@. 56 | foreign import javascript safe 57 | "$r = $1.obj.readImage($1.type);" 58 | unsafeReadImage :: Clipboard -- ^ The clipboard object. 59 | -> IO Image -- ^ The clipboard image content. 60 | 61 | -- | Set the image content in the clipboard to the given 'Image'/@NativeImage@. 62 | foreign import javascript safe 63 | "$1.obj.writeImage($2, $1.type);" 64 | unsafeWriteImage :: Clipboard -- ^ The clipboard object. 65 | -> Image -- ^ The contents to set the clipboard to. 66 | -> IO () 67 | 68 | -- | Get the current clipboard as RTF. 69 | foreign import javascript safe 70 | "$r = $1.obj.readRTF($1.type);" 71 | unsafeReadRTF :: Clipboard -- ^ The clipboard object. 72 | -> IO RTF -- ^ The RTF in the clipboard. 73 | 74 | -- | Set the clipboard to the given RTF string. 75 | foreign import javascript safe 76 | "$1.obj.writeRTF($2, $1.type);" 77 | unsafeWriteRTF :: Clipboard -- ^ The clipboard object. 78 | -> RTF -- ^ The contents to set the clipboard to. 79 | -> IO () 80 | 81 | -- | Returns a 'JSVal' that is a JavaScript object with the following keys: 82 | -- * @title@, which maps to the name of the bookmark in the clipboard. 83 | -- * @url@, which maps to the URL of the bookmark in the clipboard. 84 | -- This function only works on Windows and Mac OS. 85 | foreign import javascript safe 86 | "$1.obj.readBookmark();" 87 | unsafeReadBookmark :: Clipboard -- ^ The clipboard object. 88 | -> IO Bookmark -- ^ The resultant bookmark object. 89 | 90 | -- | Writes a bookmark with the given title and URL into the given clipboard. 91 | -- This function only works on Windows and Mac OS. 92 | foreign import javascript safe 93 | "$1.obj.writeBookmark($2, $3, $1.type);" 94 | unsafeWriteBookmark :: Clipboard -- ^ The clipboard object. 95 | -> JSString -- ^ The bookmark title. 96 | -> URL -- ^ The bookmark URL. 97 | -> IO () 98 | 99 | -- not implemented: clipboard.readFindText 100 | -- reason: Mac OS only and uses synchronous IPC 101 | 102 | -- not implemented: clipboard.writeFindText 103 | -- reason: Mac OS only and uses synchronous IPC 104 | 105 | -- | Clear the current clipboard state. 106 | foreign import javascript safe 107 | "$1.obj.clear($1.type);" 108 | unsafeClear :: Clipboard -- ^ The clipboard object. 109 | -> IO () 110 | 111 | -- | Get the supported formats for the given clipboard. 112 | foreign import javascript safe 113 | "$1.obj.availableFormats($1.type);" 114 | unsafeAvailableFormats :: Clipboard -- ^ The clipboard object. 115 | -> IO (Array JSString) 116 | -- ^ An array of supported format strings. 117 | 118 | -- not implemented: clipboard.has 119 | -- reason: subsumed by availableFormats 120 | 121 | -- not implemented: clipboard.read 122 | -- reason: experimental and not very useful 123 | 124 | -- not implemented: clipboard.readBuffer 125 | -- reason: experimental and not very useful 126 | 127 | -- not implemented: clipboard.write 128 | -- reason: not very useful 129 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/ContentTracing.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | A wrapper over the Electron content tracing API, as documented 4 | -- . 5 | -- 6 | -- Note: You should not use this module until the @ready@ event of the 7 | -- app module has been emitted. 8 | module GHCJS.Electron.ContentTracing 9 | ( ContentTracing (..) 10 | , unsafeGetContentTracing 11 | , unsafeGetCategories 12 | , unsafeStartRecording, unsafeStopRecording 13 | , unsafeStartMonitoring, unsafeStopMonitoring 14 | , unsafeCaptureMonitoringSnapshot 15 | ) where 16 | 17 | import GHCJS.Electron.Types 18 | 19 | -- | A @contentTracing@ object. 20 | newtype ContentTracing 21 | = MkContentTracing JSVal 22 | 23 | -- | Get the current global 'ContentTracing' object as returned by 24 | -- @require("electron").contentTracing@. 25 | foreign import javascript safe 26 | "$r = require('electron').contentTracing;" 27 | unsafeGetContentTracing :: IO ContentTracing 28 | 29 | -- | Get a set of category groups. Note that the category groups can change as 30 | -- new code paths are reached. 31 | -- 32 | -- Once all child processes have acknowledged the @getCategories@ request the 33 | -- callback is invoked with an array of category group strings. 34 | foreign import javascript safe 35 | "$1.getCategories($2);" 36 | unsafeGetCategories :: ContentTracing 37 | -> Callback (Array JSString -> IO ()) 38 | -> IO () 39 | 40 | -- | Start recording on all processes. 41 | -- 42 | -- Recording begins immediately locally and asynchronously on child processes 43 | -- as soon as they receive the EnableRecording request. The callback will be 44 | -- called once all child processes have acknowledged the @startRecording@ 45 | -- request. 46 | -- 47 | -- == @categoryFilter@ 48 | -- 49 | -- The @categoryFilter@ is a glob string representing a filter on the category 50 | -- groups that should be traced. A filter can have an optional @-@ prefix to 51 | -- exclude category groups that contain a matching category. Having both 52 | -- included and excluded category patterns in the same list is not supported. 53 | -- 54 | -- Examples: 55 | -- 56 | -- * @"test_MyTest*"@ 57 | -- * @"test_MyTest*,test_OtherStuff"@ 58 | -- * @"-excluded_category1,-excluded_category2"@ 59 | -- 60 | -- == @traceOptions@ 61 | -- 62 | -- The @traceOptions@ is a string representing the kind of tracing enabled. 63 | -- It is a comma-delimited list where each element is one of the following: 64 | -- 65 | -- * @record-until-full@ 66 | -- * @record-continuously@ 67 | -- * @trace-to-console@ 68 | -- * @enable-sampling@ 69 | -- * @enable-systrace@ 70 | -- 71 | -- The first three options (@record-until-full@, @record-continuously@, and 72 | -- @trace-to-console@) represent the trace recording mode and are therefore 73 | -- mutually exclusive. The default recording mode is @record-until-full@. 74 | -- 75 | -- Sampling and systrace default to being disabled. 76 | foreign import javascript safe 77 | "$1.startRecording({categoryFilter: $2, traceOptions: $3}, $4);" 78 | unsafeStartRecording :: ContentTracing 79 | -> JSString 80 | -- ^ @categoryFilter@ 81 | -> JSString 82 | -- ^ @traceOptions@ 83 | -> Callback (IO ()) 84 | -> IO () 85 | 86 | -- | Stop recording on all processes. 87 | -- 88 | -- Child processes typically cache trace data and only rarely flush and send 89 | -- trace data back to the main process. This helps to minimize the runtime 90 | -- overhead of tracing since sending trace data over IPC can be an expensive 91 | -- operation. So, to end tracing, we must asynchronously ask all child 92 | -- processes to flush any pending trace data. 93 | -- 94 | -- Once all child processes have acknowledged the @stopRecording@ request, the 95 | -- given callback will be called with the path of the file that contains the 96 | -- traced data. 97 | -- 98 | -- Trace data will be written into the given path if it is not @null@ or into 99 | -- a temporary file otherwise. The actual file path will be passed to callback 100 | -- if it's not null. 101 | foreign import javascript safe 102 | "$1.stopRecording($2, $3);" 103 | unsafeStopRecording :: ContentTracing 104 | -> Path 105 | -> Callback (Path -> IO ()) 106 | -> IO () 107 | 108 | -- | Start monitoring on all processes. 109 | -- 110 | -- Monitoring begins immediately locally and asynchronously on child processes 111 | -- as soon as they receive the @startMonitoring@ request. 112 | -- 113 | -- Once all child processes have acknowledged the @startMonitoring@ request 114 | -- the given callback will be called. 115 | -- 116 | -- The semantics of the @categoryFilter@ and @traceOptions@ parameters are 117 | -- described in the documentation for 'unsafeStartRecording'. 118 | foreign import javascript safe 119 | "$1.startMonitoring({categoryFilter: $2, traceOptions: $3}, $4);" 120 | unsafeStartMonitoring :: ContentTracing 121 | -> JSString 122 | -- ^ @categoryFilter@ 123 | -> JSString 124 | -- ^ @traceOptions@ 125 | -> Callback (IO ()) 126 | -> IO () 127 | 128 | -- | Stop recording on all processes. 129 | -- 130 | -- Once all child processes have acknowledged the @stopMonitoring@ request the 131 | -- given callback is called. 132 | foreign import javascript safe 133 | "$1.stopMonitoring($2);" 134 | unsafeStopMonitoring :: ContentTracing 135 | -> Callback (IO ()) 136 | -> IO () 137 | 138 | -- | Get the current monitoring traced data. 139 | -- 140 | -- Child processes typically cache trace data and only rarely flush and send 141 | -- trace data back to the main process. This is because it may be an expensive 142 | -- operation to send the trace data over IPC and we would like to avoid 143 | -- unneeded runtime overhead from tracing. So, to end tracing, we must 144 | -- asynchronously ask all child processes to flush any pending trace data. 145 | -- 146 | -- Once all child processes have acknowledged the @captureMonitoringSnapshot@ 147 | -- request the given callback will be called with the path of the file that 148 | -- contains the traced data. 149 | foreign import javascript safe 150 | "$1.captureMonitoringSnapshot($2, $3);" 151 | unsafeCaptureMonitoringSnapshot :: ContentTracing 152 | -> Path 153 | -> Callback (Path -> IO ()) 154 | -> IO () 155 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/Cookies.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.Cookies where 5 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/CrashReporter.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | A wrapper over the Electron crash reporter API, as documented 4 | -- . 5 | -- 6 | -- After 'start' is called a crash reporter process will be spawned such that 7 | -- if a crash occurs, a POST request with mimetype @multipart/form-data@ will 8 | -- be sent to the @submitURL@. It has the following fields: 9 | -- 10 | -- * @ver@: a string representing the version of Electron running 11 | -- * @platform@: a string representing the current platform, e.g.: @"win32"@. 12 | -- * @process_type@: either @"main"@ or @"renderer"@. 13 | -- * @guid@: a string that is a globally unique identifier for this system. 14 | -- * @_version@: the version specified in @package.json@ as a string. 15 | -- * @_productName@: the product name specified in the 'CrashReporterOptions'. 16 | -- * @prod@: the name of the underlying product (should be @"Electron"@). 17 | -- * @_companyName@: the company name specified in the 'CrashReporterOptions'. 18 | -- * @upload_file_minidump@: a Windows minidump file. 19 | -- 20 | -- If the @_extraData@ field of the 'CrashReporterOptions' object given to 21 | -- the 'start' function had any fields, each key-value pair @key: value@ 22 | -- will be added to the POST request as a field named @key@ with contents 23 | -- equal to the serialization of @value@. 24 | module GHCJS.Electron.CrashReporter where 25 | 26 | import Data.Text (Text) 27 | import qualified Data.Text as Text 28 | 29 | import GHCJS.Electron.Types 30 | 31 | import JavaScript.Object 32 | 33 | -- | FIXME: doc 34 | newtype CrashReporter 35 | = MkCrashReporter JSVal 36 | 37 | -- | FIXME: doc 38 | data CrashReport 39 | = MkCrashReport 40 | { _date :: Text 41 | , _ID :: Int 42 | } 43 | 44 | -- | FIXME: doc 45 | data CrashReporterOptions 46 | = MkCrashReporterOptions 47 | { _companyName :: Maybe Text 48 | -- ^ The company name to provide with the crash report. 49 | , _submitURL :: Text 50 | -- ^ Crash reports will be sent as POST requests to this URL. 51 | , _productName :: Maybe Text 52 | -- ^ The product name. If not provided, defaults to @app.getName()@. 53 | , _uploadToServer :: Bool 54 | -- ^ Whether crash reports should be sent to the server. 55 | , _ignoreSystemHandler :: Bool 56 | -- ^ Should the system crash handler be ignored? 57 | , _extraData :: Object 58 | -- ^ An arbitrary JSON object to send with the crash report. 59 | } 60 | 61 | -- | FIXME: doc 62 | start :: CrashReporterOptions -> IO CrashReporter 63 | start = undefined -- FIXME: implement 64 | 65 | -- | Get the canonical 'CrashReporter' object, i.e.: the value of 66 | -- @require('electron').crashReporter@. 67 | foreign import javascript safe 68 | "$r = require('electron').crashReporter;" 69 | getCrashReporter :: IO CrashReporter 70 | -- ^ A crash reporter object. 71 | 72 | -- | Start the crash reporter with the given options. 73 | foreign import javascript safe 74 | "$1.start($2);" 75 | unsafeStart :: CrashReporter 76 | -- ^ The crash reporter object to use. 77 | -> JSVal 78 | -- ^ An options object. 79 | -> IO () 80 | 81 | -- | Returns the latest crash report. If no crash reports have been sent or the 82 | -- crash reporter has not been started, @null@ is returned instead. 83 | foreign import javascript safe 84 | "$r = $1.getLastCrashReport();" 85 | unsafeGetLastCrashReport :: CrashReporter 86 | -- ^ The crash reporter object to use. 87 | -> IO JSVal -- Maybe CrashReport 88 | -- ^ The last crash report if there is one. 89 | 90 | -- | Returns a list of all uploaded crash reports to date. 91 | foreign import javascript safe 92 | "$r = $1.getUploadedReports();" 93 | unsafeGetUploadedReports :: CrashReporter 94 | -- ^ The crash reporter object to use. 95 | -> IO (Array CrashReport) 96 | -- ^ All uploaded crash reports. 97 | 98 | -- not implemented: crashReporter.getUploadToServer 99 | -- reason: Linux/Mac OS only and unnecessary 100 | 101 | -- not implemented: crashReporter.setUploadToServer 102 | -- reason: Linux/Mac OS only and unnecessary 103 | 104 | -- not implemented: crashReporter.setExtraParameter 105 | -- reason: Mac OS only and probably unnecessary 106 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/Debugger.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | A wrapper over the Electron debugging API, as documented 4 | -- . 5 | -- 6 | -- Up-to-date documentation on the Chrome DevTools Protocol can be seen 7 | -- . 8 | module GHCJS.Electron.Debugger 9 | ( Debugger (..) 10 | , unsafeGetDebugger 11 | , unsafeAttach 12 | , unsafeAttachWithVersion 13 | , unsafeDetach 14 | , unsafeSendCommand 15 | ) where 16 | 17 | import Data.Text (Text) 18 | 19 | import GHCJS.Types 20 | 21 | import GHCJS.Electron.Types 22 | 23 | import JavaScript.Object 24 | 25 | -- | An Electron @debugger@ object. 26 | newtype Debugger 27 | = MkDebugger JSVal 28 | 29 | -- data DebuggerEvent 30 | -- = DebuggerDetach 31 | -- { event :: !Event 32 | -- , reason :: !Text 33 | -- } 34 | -- | DebuggerMessage 35 | -- { event :: !Event 36 | -- , method :: !Text 37 | -- , params :: !Object 38 | -- } 39 | 40 | -- | Get the 'Debugger' object for a given 'BrowserWindow'. 41 | foreign import javascript safe 42 | "$r = $1.webContents.debugger;" 43 | unsafeGetDebugger :: BrowserWindow -> IO Debugger 44 | 45 | -- | Attaches the given 'Debugger' to the @webContents@. 46 | foreign import javascript safe 47 | "$1.attach();" 48 | unsafeAttach :: Debugger -> IO () 49 | 50 | -- | Attaches the given 'Debugger' to the @webContents@. 51 | foreign import javascript safe 52 | "$1.attach($2);" 53 | unsafeAttachWithVersion :: Debugger 54 | -> JSString 55 | -- ^ The requested debugging protocol version. 56 | -> IO () 57 | 58 | -- | Detaches the given 'Debugger' from the @webContents@. 59 | foreign import javascript safe 60 | "$1.detach();" 61 | unsafeDetach :: Debugger -> IO () 62 | 63 | -- | Send the given command to the debugging target. 64 | -- 65 | -- Up-to-date documentation on the Chrome DevTools Protocol can be seen 66 | -- . 67 | foreign import javascript safe 68 | "$1.sendCommand($2, $3, $4);" 69 | unsafeSendCommand :: Debugger 70 | -> JSString 71 | -- ^ The method name (as defined in the Chrome DevTools 72 | -- Protocol) to call. 73 | -> Object 74 | -- ^ A JSON object containing request parameters. 75 | -> Callback (JSVal -> JSVal -> IO ()) 76 | -- ^ The callback that will be run when the method returns. 77 | -- 78 | -- The first parameter of the callback contains any 79 | -- relevant error information, and the second parameter 80 | -- contains any returned data. 81 | -> IO () 82 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/DesktopCapturer.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.DesktopCapturer where 5 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/Dialog.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.Dialog 5 | ( module Exported 6 | , module GHCJS.Electron.Dialog 7 | ) where 8 | 9 | import GHCJS.Electron.Types 10 | import GHCJS.Electron.Types as Exported (Dialog (..)) 11 | import GHCJS.Types 12 | 13 | -- FIXME: replace these "Options object"s with proper type definitions. 14 | 15 | -- | Get the value of @require('electron').dialog@. 16 | foreign import javascript safe 17 | "$r = require('electron').dialog;" 18 | getDialog :: IO Dialog 19 | 20 | -- | Show an "open file" dialog to the user. 21 | foreign import javascript safe 22 | "$1.showOpenDialog($2, $3);" 23 | dialogShowOpen :: Dialog 24 | -> BrowserWindow -- ^ Window on which to open the dialog. 25 | -> JSVal -- ^ Options object. 26 | -> IO (Array Path) -- ^ An array of file paths from the user. 27 | 28 | -- | Show an "save file" dialog to the user. 29 | foreign import javascript safe 30 | "$1.showSaveDialog($2, $3);" 31 | dialogShowSave :: Dialog 32 | -> BrowserWindow -- ^ Window on which to open the dialog. 33 | -> JSVal -- ^ Options object. 34 | -> IO Path -- ^ The file path chosen for saving. 35 | 36 | -- | This function shows a message box. Note that it will block the process 37 | -- until the message box is closed. 38 | foreign import javascript safe 39 | "$1.showMessageBox($2, $3);" 40 | dialogShowMessageBox :: Dialog 41 | -> BrowserWindow -- ^ Window on which to open the box. 42 | -> JSVal -- ^ Options object. 43 | -> IO Int -- ^ The index of the clicked button. 44 | 45 | -- | Display a modal dialog box for error message reporting. 46 | -- 47 | -- If this is called before the GUI is ready, the message may be emitted 48 | -- @stderr@ instead, especially on Linux. To mitigate this, avoid using 49 | -- this function before the @ready@ event when running on Linux. 50 | foreign import javascript safe 51 | "$1.showErrorBox($2, $3);" 52 | dialogShowErrorBox :: Dialog 53 | -> JSString -- ^ The title to display in the error box. 54 | -> JSString -- ^ The text content of the error box. 55 | -> IO () 56 | 57 | -- | This function displays a modal dialog that shows a message and certificate 58 | -- information, and gives the user the option of trusting/importing the shown 59 | -- certificate. 60 | -- 61 | -- NOTE: this function only works on Mac OS 62 | foreign import javascript safe 63 | "$1.showCertificateTrustDialog($2, $3, $4);" 64 | dialogCertDialog :: Dialog 65 | -> BrowserWindow -- ^ Window on which to open the box. 66 | -> JSVal -- ^ Options object. 67 | -> Callback (IO ()) -- ^ A callback to run once done. 68 | -> IO () 69 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/DownloadItem.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.DownloadItem where 5 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/GlobalShortcut.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | A wrapper over the Electron global shortcut API, as documented 4 | -- . 5 | module GHCJS.Electron.GlobalShortcut 6 | ( module Exported 7 | , unsafeGetGlobalShortcut 8 | , unsafeRegister 9 | , unsafeUnregister 10 | , unsafeUnregisterAll 11 | , unsafeIsRegistered 12 | ) where 13 | 14 | import GHCJS.Electron.Types 15 | 16 | import GHCJS.Electron.Types as Exported (GlobalShortcut (..)) 17 | 18 | -- | Get the canonical 'GlobalShortcut' object, i.e.: the value of 19 | -- @require('electron').globalShortcut@. 20 | foreign import javascript safe 21 | "$r = require('electron').globalShortcut;" 22 | unsafeGetGlobalShortcut :: IO GlobalShortcut 23 | 24 | -- | Register a callback for the given 'Accelerator'. 25 | foreign import javascript safe 26 | "$1.register($2, $3);" 27 | unsafeRegister :: GlobalShortcut 28 | -> Accelerator 29 | -> Callback () 30 | -> IO () 31 | 32 | -- | Deregister any callbacks registered to the given 'Accelerator'. 33 | foreign import javascript safe 34 | "$1.unregister($2);" 35 | unsafeUnregister :: GlobalShortcut 36 | -> Accelerator 37 | -> IO () 38 | 39 | -- | Deregister all global shortcut callbacks. 40 | foreign import javascript safe 41 | "$1.unregisterAll();" 42 | unsafeUnregisterAll :: GlobalShortcut 43 | -> IO () 44 | 45 | -- | Check if the given 'Accelerator' is has been registered. 46 | foreign import javascript safe 47 | "$1.isRegistered($2);" 48 | unsafeIsRegistered :: GlobalShortcut 49 | -> Accelerator 50 | -> IO Bool 51 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/IPCMain.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.IPCMain 5 | ( module Exported 6 | , module GHCJS.Electron.IPCMain 7 | ) where 8 | 9 | import GHCJS.Electron.Types 10 | import GHCJS.Electron.Types as Exported () 11 | import GHCJS.Types 12 | 13 | -- | Get the global 'IPCMain' object. 14 | foreign import javascript safe 15 | "$r = require('electron').ipcMain;" 16 | getIPCMain :: IO IPCMain 17 | 18 | -- | Listen for the given event and run the given callback whenever it occurs. 19 | foreign import javascript safe 20 | "$1.on($2, $3);" 21 | ipcMainListenerOn :: IPCMain 22 | -> JSString 23 | -> Callback (Event -> Any -> ()) 24 | -> IO () 25 | 26 | -- | Listen for the given event and run the given callback exactly once; 27 | -- i.e.: the callback will be run precisely the first time the event occurs 28 | -- after this function is run. 29 | foreign import javascript safe 30 | "$1.once($2, $3);" 31 | ipcMainListenerOnce :: IPCMain 32 | -> JSString 33 | -> Callback (Event -> Any -> ()) 34 | -> IO () 35 | 36 | -- | Remove all listeners on the given 'IPCMain'. 37 | foreign import javascript safe 38 | "$1.removeAllListeners();" 39 | ipcMainRemoveAllListeners :: IPCMain -> IO () 40 | 41 | -- | Remove all listeners for the given event on the given 'IPCMain'. 42 | foreign import javascript safe 43 | "$1.removeAllListeners($2);" 44 | ipcMainRemoveAllListenersOnEvent :: IPCMain -> JSString -> IO () 45 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/IPCRenderer.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | {-# LANGUAGE MultiParamTypeClasses #-} 3 | 4 | -- | A wrapper over the Electron renderer IPC API, as documented 5 | -- . 6 | module GHCJS.Electron.IPCRenderer 7 | ( module GHCJS.Electron.IPCRenderer -- FIXME: specific export list 8 | ) where 9 | 10 | import GHCJS.Node.EventEmitter 11 | 12 | import GHCJS.Electron.Types 13 | 14 | import GHCJS.Array 15 | 16 | import JavaScript.JSON.Types (Value) 17 | 18 | -- | Get the canonical 'IPCRenderer' object, i.e.: the value of 19 | -- @require('electron').ipcRenderer@. 20 | foreign import javascript safe 21 | "$r = require('electron').ipcRenderer;" 22 | unsafeGetIPCRenderer :: IO IPCRenderer 23 | 24 | data IPCEvent -- FIXME: implement 25 | 26 | instance IsEventEmitter IPCEvent IPCRenderer where 27 | toEventEmitter (MkIPCRenderer val) = pure (MkEventEmitter val) 28 | 29 | -- | Send a message to the main process asynchronously via a named channel. 30 | -- The message comes with an arbitrary array of arguments. 31 | foreign import javascript safe 32 | "(function(obj) { obj.send.apply(obj, [$2] + $3); })($1);" 33 | unsafeSend :: IPCRenderer 34 | -> Channel 35 | -- ^ The channel on which a message will be asynchronously sent 36 | -- to the main process. 37 | -> Array Value 38 | -- ^ The data associated with the message. 39 | -> IO () 40 | 41 | -- | Send a message to the main process synchronously via a named channel. 42 | -- The message comes with an arbitrary array of arguments. 43 | -- 44 | -- The main process handles it by listening for channel with @ipcMain@ module, 45 | -- and replies by setting @event.returnValue@. 46 | -- 47 | -- Note: Sending a synchronous message will block the whole renderer process, 48 | -- unless you know what you are doing you should probably never use this 49 | -- function. 50 | foreign import javascript safe 51 | "$r = (function(obj) { obj.sendSync.apply(obj, [$2] + $3); })($1);" 52 | unsafeSendSync :: IPCRenderer 53 | -> Channel 54 | -- ^ The channel on which a message will be synchronously sent 55 | -- to the main process. 56 | -> Array Value 57 | -- ^ The data associated with the message. 58 | -> IO Value 59 | -- ^ The returned value. 60 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/IncomingMessage.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.IncomingMessage where 5 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/Locales.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveDataTypeable #-} 2 | {-# LANGUAGE DeriveGeneric #-} 3 | {-# LANGUAGE JavaScriptFFI #-} 4 | {-# LANGUAGE OverloadedStrings #-} 5 | 6 | -- | A wrapper over the Electron locale API, as documented 7 | -- . 8 | module GHCJS.Electron.Locales 9 | ( LocaleID, Locale (..), LocaleData (..) 10 | , getLocaleID, getLocale, toLocaleData, parseLocale, localeMap 11 | ) where 12 | 13 | import Data.Maybe (fromJust) 14 | 15 | import Data.Map.Strict (Map) 16 | import qualified Data.Map.Strict as Map 17 | 18 | import Data.Text (Text) 19 | import qualified Data.Text as Text 20 | 21 | import Data.JSString (JSString) 22 | import qualified Data.JSString as JSString 23 | 24 | import Data.Data (Data) 25 | import GHC.Generics (Generic) 26 | 27 | foreign import javascript safe 28 | "$r = require('electron').app.getLocale();" 29 | appGetLocale :: IO JSString 30 | 31 | -- | Get the current 'LocaleID'. 32 | getLocaleID :: IO LocaleID 33 | getLocaleID = Text.pack . JSString.unpack <$> appGetLocale 34 | 35 | -- | Get the current 'Locale'. 36 | getLocale :: IO (Maybe Locale) 37 | getLocale = parseLocale <$> getLocaleID 38 | 39 | -- | Get the 'LocaleData' corresponding to the given 'Locale'. 40 | toLocaleData :: Locale -> LocaleData 41 | toLocaleData = fromJust . flip Map.lookup localeMap 42 | 43 | -- | Get the 'Locale' corresponding to the given IETF language tag, assuming 44 | -- that such a 'Locale' exists in the 'localeMap'. 45 | parseLocale :: LocaleID -> Maybe Locale 46 | parseLocale = flip Map.lookup 47 | (Map.fromList ((\(loc, ld) -> (_localeDataID ld, loc)) 48 | <$> Map.toList localeMap)) 49 | 50 | -- | An IETF language tag, as specified in RFC 5646 and RFC 4647. 51 | type LocaleID = Text 52 | 53 | -- | A 'LocaleData' contains two pieces of information: 54 | -- 1. The locale ID, as an IETF language tag. 55 | -- 2. The name of the locale, as English text. 56 | data LocaleData 57 | = MkLocaleData 58 | { _localeDataID :: !LocaleID 59 | , _localeDataName :: !Text 60 | } 61 | deriving (Eq, Ord, Show, Generic) 62 | 63 | -- | The type of locales. 64 | data Locale 65 | = Locale_AF -- ^ Afrikaans 66 | | Locale_AN -- ^ Aragonese 67 | | Locale_AR_AE -- ^ Arabic (U.A.E.) 68 | | Locale_AR_IQ -- ^ Arabic (Iraq) 69 | | Locale_AR -- ^ Arabic (Standard) 70 | | Locale_AR_BH -- ^ Arabic (Bahrain) 71 | | Locale_AR_DZ -- ^ Arabic (Algeria) 72 | | Locale_AR_EG -- ^ Arabic (Egypt) 73 | | Locale_AR_JO -- ^ Arabic (Jordan) 74 | | Locale_AR_KW -- ^ Arabic (Kuwait) 75 | | Locale_AR_LB -- ^ Arabic (Lebanon) 76 | | Locale_AR_LY -- ^ Arabic (Libya) 77 | | Locale_AR_MA -- ^ Arabic (Morocco) 78 | | Locale_AR_OM -- ^ Arabic (Oman) 79 | | Locale_AR_QA -- ^ Arabic (Qatar) 80 | | Locale_AR_SA -- ^ Arabic (Saudi Arabia) 81 | | Locale_AR_SY -- ^ Arabic (Syria) 82 | | Locale_AR_TN -- ^ Arabic (Tunisia) 83 | | Locale_AR_YE -- ^ Arabic (Yemen) 84 | | Locale_AS -- ^ Assamese 85 | | Locale_AST -- ^ Asturian 86 | | Locale_AZ -- ^ Azerbaijani 87 | | Locale_BE -- ^ Belarusian 88 | | Locale_BG -- ^ Bulgarian 89 | | Locale_BN -- ^ Bengali 90 | | Locale_BR -- ^ Breton 91 | | Locale_BS -- ^ Bosnian 92 | | Locale_CA -- ^ Catalan 93 | | Locale_CE -- ^ Chechen 94 | | Locale_CH -- ^ Chamorro 95 | | Locale_CO -- ^ Corsican 96 | | Locale_CR -- ^ Cree 97 | | Locale_CS -- ^ Czech 98 | | Locale_CV -- ^ Chuvash 99 | | Locale_DA -- ^ Danish 100 | | Locale_DE -- ^ German (Standard) 101 | | Locale_DE_AT -- ^ German (Austria) 102 | | Locale_DE_CH -- ^ German (Switzerland) 103 | | Locale_DE_DE -- ^ German (Germany) 104 | | Locale_DE_LI -- ^ German (Liechtenstein) 105 | | Locale_DE_LU -- ^ German (Luxembourg) 106 | | Locale_EL -- ^ Greek 107 | | Locale_EN_AU -- ^ English (Australia) 108 | | Locale_EN_BZ -- ^ English (Belize) 109 | | Locale_EN -- ^ English 110 | | Locale_EN_CA -- ^ English (Canada) 111 | | Locale_EN_GB -- ^ English (United Kingdom) 112 | | Locale_EN_IE -- ^ English (Ireland) 113 | | Locale_EN_JM -- ^ English (Jamaica) 114 | | Locale_EN_NZ -- ^ English (New Zealand) 115 | | Locale_EN_PH -- ^ English (Philippines) 116 | | Locale_EN_TT -- ^ English (Trinidad & Tobago) 117 | | Locale_EN_US -- ^ English (United States) 118 | | Locale_EN_ZA -- ^ English (South Africa) 119 | | Locale_EN_ZW -- ^ English (Zimbabwe) 120 | | Locale_EO -- ^ Esperanto 121 | | Locale_ET -- ^ Estonian 122 | | Locale_EU -- ^ Basque 123 | | Locale_FA -- ^ Farsi 124 | | Locale_FA_IR -- ^ Persian/Iran 125 | | Locale_FI -- ^ Finnish 126 | | Locale_FJ -- ^ Fijian 127 | | Locale_FO -- ^ Faeroese 128 | | Locale_FR_CH -- ^ French (Switzerland) 129 | | Locale_FR_FR -- ^ French (France) 130 | | Locale_FR_LU -- ^ French (Luxembourg) 131 | | Locale_FR_MC -- ^ French (Monaco) 132 | | Locale_FR -- ^ French (Standard) 133 | | Locale_FR_BE -- ^ French (Belgium) 134 | | Locale_FR_CA -- ^ French (Canada) 135 | | Locale_FUR -- ^ Friulian 136 | | Locale_FY -- ^ Frisian 137 | | Locale_GA -- ^ Irish 138 | | Locale_GD_IE -- ^ Gaelic (Irish) 139 | | Locale_GD -- ^ Gaelic (Scots) 140 | | Locale_GL -- ^ Galacian 141 | | Locale_GU -- ^ Gujurati 142 | | Locale_HE -- ^ Hebrew 143 | | Locale_HI -- ^ Hindi 144 | | Locale_HR -- ^ Croatian 145 | | Locale_HT -- ^ Haitian 146 | | Locale_HU -- ^ Hungarian 147 | | Locale_HY -- ^ Armenian 148 | | Locale_ID -- ^ Indonesian 149 | | Locale_IS -- ^ Icelandic 150 | | Locale_IT_CH -- ^ Italian (Switzerland) 151 | | Locale_IT -- ^ Italian (Standard) 152 | | Locale_IU -- ^ Inuktitut 153 | | Locale_JA -- ^ Japanese 154 | | Locale_KA -- ^ Georgian 155 | | Locale_KK -- ^ Kazakh 156 | | Locale_KM -- ^ Khmer 157 | | Locale_KN -- ^ Kannada 158 | | Locale_KO -- ^ Korean 159 | | Locale_KO_KP -- ^ Korean (North Korea) 160 | | Locale_KO_KR -- ^ Korean (South Korea) 161 | | Locale_KS -- ^ Kashmiri 162 | | Locale_KY -- ^ Kirghiz 163 | | Locale_LA -- ^ Latin 164 | | Locale_LB -- ^ Luxembourgish 165 | | Locale_LT -- ^ Lithuanian 166 | | Locale_LV -- ^ Latvian 167 | | Locale_MI -- ^ Maori 168 | | Locale_MK -- ^ FYRO Macedonian 169 | | Locale_ML -- ^ Malayalam 170 | | Locale_MO -- ^ Moldavian 171 | | Locale_MR -- ^ Marathi 172 | | Locale_MS -- ^ Malay 173 | | Locale_MT -- ^ Maltese 174 | | Locale_MY -- ^ Burmese 175 | | Locale_NB -- ^ Norwegian (Bokmal) 176 | | Locale_NE -- ^ Nepali 177 | | Locale_NG -- ^ Ndonga 178 | | Locale_NL -- ^ Dutch (Standard) 179 | | Locale_NL_BE -- ^ Dutch (Belgian) 180 | | Locale_NN -- ^ Norwegian (Nynorsk) 181 | | Locale_NO -- ^ Norwegian 182 | | Locale_NV -- ^ Navajo 183 | | Locale_OC -- ^ Occitan 184 | | Locale_OM -- ^ Oromo 185 | | Locale_OR -- ^ Oriya 186 | | Locale_SQ -- ^ Albanian 187 | | Locale_TLH -- ^ Klingon 188 | | Locale_ZH_TW -- ^ Chinese (Taiwan) 189 | | Locale_ZH -- ^ Chinese 190 | | Locale_ZH_CN -- ^ Chinese (PRC) 191 | | Locale_ZH_HK -- ^ Chinese (Hong Kong) 192 | | Locale_ZH_SG -- ^ Chinese (Singapore) 193 | deriving (Eq, Ord, Show, Enum, Bounded, Data, Generic) 194 | 195 | -- | This allows you to get the 'LocaleData' associated with a given 'Locale'. 196 | -- 197 | -- Note that 'localeMap' should satisfy the following law: 198 | -- 199 | -- >>> sort (Map.keys localeMap) == [minBound .. maxBound] 200 | -- 201 | -- In other words, every constructor of Locale should have a corresponding value 202 | -- in this finite map; thus making 'Map.lookup' a total function. 203 | localeMap :: Map Locale LocaleData 204 | localeMap = Map.fromList 205 | [ Locale_AF ~> ld "af" "Afrikaans" 206 | , Locale_AN ~> ld "an" "Aragonese" 207 | , Locale_AR_AE ~> ld "ar-AE" "Arabic (U.A.E.)" 208 | , Locale_AR_IQ ~> ld "ar-IQ" "Arabic (Iraq)" 209 | , Locale_AR ~> ld "ar" "Arabic (Standard)" 210 | , Locale_AR_BH ~> ld "ar-BH" "Arabic (Bahrain)" 211 | , Locale_AR_DZ ~> ld "ar-DZ" "Arabic (Algeria)" 212 | , Locale_AR_EG ~> ld "ar-EG" "Arabic (Egypt)" 213 | , Locale_AR_JO ~> ld "ar-JO" "Arabic (Jordan)" 214 | , Locale_AR_KW ~> ld "ar-KW" "Arabic (Kuwait)" 215 | , Locale_AR_LB ~> ld "ar-LB" "Arabic (Lebanon)" 216 | , Locale_AR_LY ~> ld "ar-LY" "Arabic (Libya)" 217 | , Locale_AR_MA ~> ld "ar-MA" "Arabic (Morocco)" 218 | , Locale_AR_OM ~> ld "ar-OM" "Arabic (Oman)" 219 | , Locale_AR_QA ~> ld "ar-QA" "Arabic (Qatar)" 220 | , Locale_AR_SA ~> ld "ar-SA" "Arabic (Saudi Arabia)" 221 | , Locale_AR_SY ~> ld "ar-SY" "Arabic (Syria)" 222 | , Locale_AR_TN ~> ld "ar-TN" "Arabic (Tunisia)" 223 | , Locale_AR_YE ~> ld "ar-YE" "Arabic (Yemen)" 224 | , Locale_AS ~> ld "as" "Assamese" 225 | , Locale_AST ~> ld "ast" "Asturian" 226 | , Locale_AZ ~> ld "az" "Azerbaijani" 227 | , Locale_BE ~> ld "be" "Belarusian" 228 | , Locale_BG ~> ld "bg" "Bulgarian" 229 | , Locale_BN ~> ld "bn" "Bengali" 230 | , Locale_BR ~> ld "br" "Breton" 231 | , Locale_BS ~> ld "bs" "Bosnian" 232 | , Locale_CA ~> ld "ca" "Catalan" 233 | , Locale_CE ~> ld "ce" "Chechen" 234 | , Locale_CH ~> ld "ch" "Chamorro" 235 | , Locale_CO ~> ld "co" "Corsican" 236 | , Locale_CR ~> ld "cr" "Cree" 237 | , Locale_CS ~> ld "cs" "Czech" 238 | , Locale_CV ~> ld "cv" "Chuvash" 239 | , Locale_DA ~> ld "da" "Danish" 240 | , Locale_DE ~> ld "de" "German (Standard)" 241 | , Locale_DE_AT ~> ld "de-AT" "German (Austria)" 242 | , Locale_DE_CH ~> ld "de-CH" "German (Switzerland)" 243 | , Locale_DE_DE ~> ld "de-DE" "German (Germany)" 244 | , Locale_DE_LI ~> ld "de-LI" "German (Liechtenstein)" 245 | , Locale_DE_LU ~> ld "de-LU" "German (Luxembourg)" 246 | , Locale_EL ~> ld "el" "Greek" 247 | , Locale_EN_AU ~> ld "en-AU" "English (Australia)" 248 | , Locale_EN_BZ ~> ld "en-BZ" "English (Belize)" 249 | , Locale_EN ~> ld "en" "English" 250 | , Locale_EN_CA ~> ld "en-CA" "English (Canada)" 251 | , Locale_EN_GB ~> ld "en-GB" "English (United Kingdom)" 252 | , Locale_EN_IE ~> ld "en-IE" "English (Ireland)" 253 | , Locale_EN_JM ~> ld "en-JM" "English (Jamaica)" 254 | , Locale_EN_NZ ~> ld "en-NZ" "English (New Zealand)" 255 | , Locale_EN_PH ~> ld "en-PH" "English (Philippines)" 256 | , Locale_EN_TT ~> ld "en-TT" "English (Trinidad & Tobago)" 257 | , Locale_EN_US ~> ld "en-US" "English (United States)" 258 | , Locale_EN_ZA ~> ld "en-ZA" "English (South Africa)" 259 | , Locale_EN_ZW ~> ld "en-ZW" "English (Zimbabwe)" 260 | , Locale_EO ~> ld "eo" "Esperanto" 261 | , Locale_ET ~> ld "et" "Estonian" 262 | , Locale_EU ~> ld "eu" "Basque" 263 | , Locale_FA ~> ld "fa" "Farsi" 264 | , Locale_FA_IR ~> ld "fa-IR" "Persian/Iran" 265 | , Locale_FI ~> ld "fi" "Finnish" 266 | , Locale_FJ ~> ld "fj" "Fijian" 267 | , Locale_FO ~> ld "fo" "Faeroese" 268 | , Locale_FR_CH ~> ld "fr-CH" "French (Switzerland)" 269 | , Locale_FR_FR ~> ld "fr-FR" "French (France)" 270 | , Locale_FR_LU ~> ld "fr-LU" "French (Luxembourg)" 271 | , Locale_FR_MC ~> ld "fr-MC" "French (Monaco)" 272 | , Locale_FR ~> ld "fr" "French (Standard)" 273 | , Locale_FR_BE ~> ld "fr-BE" "French (Belgium)" 274 | , Locale_FR_CA ~> ld "fr-CA" "French (Canada)" 275 | , Locale_FUR ~> ld "fur" "Friulian" 276 | , Locale_FY ~> ld "fy" "Frisian" 277 | , Locale_GA ~> ld "ga" "Irish" 278 | , Locale_GD_IE ~> ld "gd-IE" "Gaelic (Irish)" 279 | , Locale_GD ~> ld "gd" "Gaelic (Scots)" 280 | , Locale_GL ~> ld "gl" "Galacian" 281 | , Locale_GU ~> ld "gu" "Gujurati" 282 | , Locale_HE ~> ld "he" "Hebrew" 283 | , Locale_HI ~> ld "hi" "Hindi" 284 | , Locale_HR ~> ld "hr" "Croatian" 285 | , Locale_HT ~> ld "ht" "Haitian" 286 | , Locale_HU ~> ld "hu" "Hungarian" 287 | , Locale_HY ~> ld "hy" "Armenian" 288 | , Locale_ID ~> ld "id" "Indonesian" 289 | , Locale_IS ~> ld "is" "Icelandic" 290 | , Locale_IT_CH ~> ld "it-CH" "Italian (Switzerland)" 291 | , Locale_IT ~> ld "it" "Italian (Standard)" 292 | , Locale_IU ~> ld "iu" "Inuktitut" 293 | , Locale_JA ~> ld "ja" "Japanese" 294 | , Locale_KA ~> ld "ka" "Georgian" 295 | , Locale_KK ~> ld "kk" "Kazakh" 296 | , Locale_KM ~> ld "km" "Khmer" 297 | , Locale_KN ~> ld "kn" "Kannada" 298 | , Locale_KO ~> ld "ko" "Korean" 299 | , Locale_KO_KP ~> ld "ko-KP" "Korean (North Korea)" 300 | , Locale_KO_KR ~> ld "ko-KR" "Korean (South Korea)" 301 | , Locale_KS ~> ld "ks" "Kashmiri" 302 | , Locale_KY ~> ld "ky" "Kirghiz" 303 | , Locale_LA ~> ld "la" "Latin" 304 | , Locale_LB ~> ld "lb" "Luxembourgish" 305 | , Locale_LT ~> ld "lt" "Lithuanian" 306 | , Locale_LV ~> ld "lv" "Latvian" 307 | , Locale_MI ~> ld "mi" "Maori" 308 | , Locale_MK ~> ld "mk" "FYRO Macedonian" 309 | , Locale_ML ~> ld "ml" "Malayalam" 310 | , Locale_MO ~> ld "mo" "Moldavian" 311 | , Locale_MR ~> ld "mr" "Marathi" 312 | , Locale_MS ~> ld "ms" "Malay" 313 | , Locale_MT ~> ld "mt" "Maltese" 314 | , Locale_MY ~> ld "my" "Burmese" 315 | , Locale_NB ~> ld "nb" "Norwegian (Bokmal)" 316 | , Locale_NE ~> ld "ne" "Nepali" 317 | , Locale_NG ~> ld "ng" "Ndonga" 318 | , Locale_NL ~> ld "nl" "Dutch (Standard)" 319 | , Locale_NL_BE ~> ld "nl-BE" "Dutch (Belgian)" 320 | , Locale_NN ~> ld "nn" "Norwegian (Nynorsk)" 321 | , Locale_NO ~> ld "no" "Norwegian" 322 | , Locale_NV ~> ld "nv" "Navajo" 323 | , Locale_OC ~> ld "oc" "Occitan" 324 | , Locale_OM ~> ld "om" "Oromo" 325 | , Locale_OR ~> ld "or" "Oriya" 326 | , Locale_SQ ~> ld "sq" "Albanian" 327 | , Locale_TLH ~> ld "tlh" "Klingon" 328 | , Locale_ZH_TW ~> ld "zh-TW" "Chinese (Taiwan)" 329 | , Locale_ZH ~> ld "zh" "Chinese" 330 | , Locale_ZH_CN ~> ld "zh-CN" "Chinese (PRC)" 331 | , Locale_ZH_HK ~> ld "zh-HK" "Chinese (Hong Kong)" 332 | , Locale_ZH_SG ~> ld "zh-SG" "Chinese (Singapore)" 333 | ] 334 | where 335 | locale ~> localeData = (locale, localeData) 336 | ld = MkLocaleData 337 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/Menu.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.Menu where 5 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/MenuItem.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.MenuItem where 5 | 6 | import JavaScript.Object 7 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/NativeImage.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.NativeImage where 5 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/Net.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.Net where 5 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/PowerMonitor.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.PowerMonitor where 5 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/PowerSaveBlocker.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | A wrapper over the Electron power-save blocking API, as documented 4 | -- . 5 | module GHCJS.Electron.PowerSaveBlocker 6 | ( PowerSaveBlocker (..) 7 | , BlockerID (..) 8 | , unsafeGetPowerSaveBlocker 9 | , unsafeStart 10 | , unsafeStop 11 | , unsafeIsStarted 12 | ) where 13 | 14 | import GHCJS.Types 15 | 16 | -- | An Electron @powerSaveBlocker@ object. 17 | newtype PowerSaveBlocker 18 | = MkPowerSaveBlocker JSVal 19 | 20 | -- | A power save blocker ID number. 21 | newtype BlockerID 22 | = MkBlockerID Int 23 | 24 | -- | Get the canonical 'PowerSaveBlocker' object, i.e.: the value of 25 | -- @require('electron').powerSaveBlocker@. 26 | foreign import javascript safe 27 | "$r = require('electron').powerSaveBlocker;" 28 | unsafeGetPowerSaveBlocker :: IO PowerSaveBlocker 29 | 30 | -- | Start a power save blocker of the given type. 31 | -- 32 | -- Returns a power save blocker ID (which is an integer). 33 | -- 34 | -- The type parameter is one of the following strings: 35 | -- 36 | -- * @"prevent-app-suspension"@ 37 | -- * Prevents the application from being suspended. 38 | -- * Keeps the system active but allows the screen to be turned off. 39 | -- * Example use cases: downloading a file or playing audio. 40 | -- * @"prevent-display-sleep"@ 41 | -- * Prevents the display from going to sleep. 42 | -- * Keeps the system and screen active. 43 | -- * Example use case: playing video. 44 | -- * Has higher precedence than @"prevent-app-suspension"@. 45 | -- 46 | -- Only the highest precedence type will have any effect. 47 | foreign import javascript safe 48 | "$r = $1.start($2);" 49 | unsafeStart :: PowerSaveBlocker 50 | -> JSString 51 | -- ^ The power save blocker type. 52 | -> IO BlockerID 53 | 54 | -- | Stops the specified power save blocker by its 'BlockerID'. 55 | foreign import javascript safe 56 | "$1.stop($2);" 57 | unsafeStop :: PowerSaveBlocker 58 | -> BlockerID 59 | -> IO () 60 | 61 | -- | Checks whether the given 'BlockerID' corresponds to a running power save 62 | -- blocker process. 63 | foreign import javascript safe 64 | "$r = $1.isStarted($2);" 65 | unsafeIsStarted :: PowerSaveBlocker 66 | -> BlockerID 67 | -> IO Bool 68 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/Process.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.Process where 5 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/Protocol.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.Protocol where 5 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/Remote.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.Remote where 5 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/Screen.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.Screen where 5 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/Session.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.Session where 5 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/Shell.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | A wrapper over the Electron shell API, as documented 4 | -- . 5 | module GHCJS.Electron.Shell 6 | ( ShortcutDetails (..), ShortcutIcon (..) 7 | , Shell (..) 8 | , unsafeGetShell 9 | , unsafeShowItemInFolder 10 | , unsafeOpenItem 11 | , unsafeOpenExternal 12 | , unsafeOpenExternalDarwin 13 | , unsafeMoveItemToTrash 14 | , unsafeBeep 15 | , unsafeWriteShortcutLink 16 | , unsafeReadShortcutLink 17 | ) where 18 | 19 | import Data.Text (Text) 20 | 21 | import GHCJS.Electron.Types 22 | 23 | import GHCJS.Nullable 24 | import JavaScript.Object 25 | 26 | -- FIXME: write high-level wrappers 27 | 28 | -- FIXME: write (de)serialization routines for ShortcutDetails 29 | 30 | -- | The data contained within a Windows @.lnk@ shortcut file. 31 | data ShortcutDetails 32 | = MkShortcutDetails 33 | { target :: Text 34 | -- ^ The target path to launch from this shortcut. 35 | , cwd :: Text 36 | -- ^ The working directory in which the @target@ will run. 37 | , args :: Text 38 | -- ^ The arguments to be applied to @target@ when launching the shortcut. 39 | , description :: Text 40 | -- ^ The description of the shortcut. 41 | , icon :: ShortcutIcon 42 | -- ^ The icon displayed for the shortcut. 43 | , appUserModelId :: Text 44 | -- ^ The Application User Model ID. 45 | -- Documented . 46 | } 47 | 48 | -- | The icon of a Windows shortcut. This is either a path to an icon file or 49 | -- a path to a PE file along with a resource ID. 50 | data ShortcutIcon 51 | = ShortcutIconICO 52 | { iconPath :: WindowsPathRef 53 | -- ^ The path of an ICO file. 54 | } 55 | | ShortcutIconPE 56 | { iconPath :: WindowsPathRef 57 | -- ^ The path of a PE (Portable Executable) file; i.e.: a DLL or EXE. 58 | , iconIndex :: Int 59 | -- ^ The resource ID of the icon. 60 | } 61 | 62 | -- | An Electron @shell@ object. 63 | newtype Shell 64 | = MkShell JSVal 65 | 66 | -- | Get the current global 'Shell' object as returned by 67 | -- @require("electron").shell@. 68 | foreign import javascript safe 69 | "$r = require('electron').shell;" 70 | unsafeGetShell :: IO Shell 71 | 72 | -- | Show the given file in a file manager. If possible, select the file. 73 | -- 74 | -- Returns a boolean representing whether the item was successfully shown. 75 | foreign import javascript safe 76 | "$r = $1.showItemInFolder($2);" 77 | unsafeShowItemInFolder :: Shell -> Path -> IO Bool 78 | 79 | -- | Open the given file in the desktop's default manner, e.g.: with @xdg-open@ 80 | -- on most Linux systems. 81 | -- 82 | -- Returns a boolean representing whether the item was successfully opened. 83 | foreign import javascript safe 84 | "$r = $1.openItem($2);" 85 | unsafeOpenItem :: Shell -> Path -> IO Bool 86 | 87 | -- | Open the given URL in the desktop's default manner, e.g.: with @xdg-open@ 88 | -- on most Linux systems. 89 | -- 90 | -- Returns a boolean representing whether the URL was successfully opened. 91 | foreign import javascript safe 92 | "$r = $1.openExternal($2);" 93 | unsafeOpenExternal :: Shell 94 | -> URL 95 | -- ^ The URL to open. 96 | -> IO Bool 97 | -- ^ True iff the URL was successfully opened. 98 | 99 | -- | Open the given URL in the desktop's default manner. 100 | -- This version of the function has extra options that are specific to Mac OS, 101 | -- and is also asynchronous. 102 | foreign import javascript safe 103 | "$1.openExternal($2, {activate: $3}, $4);" 104 | unsafeOpenExternalDarwin :: Shell 105 | -> URL 106 | -- ^ The URL to open. 107 | -> Bool 108 | -- ^ If true, the application will be pushed to the 109 | -- foreground once launched. 110 | -> Callback (Nullable Error -> IO ()) 111 | -- ^ A callback to run once the URL is opened. 112 | -> IO () 113 | 114 | -- | Move the file at the given path to the "trash". 115 | -- 116 | -- Returns a boolean representing whether or not the item was successfully 117 | -- moved to the trash. 118 | foreign import javascript safe 119 | "$r = $1.moveItemToTrash($2);" 120 | unsafeMoveItemToTrash :: Shell -> Path -> IO Bool 121 | 122 | -- | Play the beep sound. 123 | foreign import javascript safe 124 | "$1.beep();" 125 | unsafeBeep :: Shell -> IO () 126 | 127 | -- | Creates or updates a Windows shortcut (@.lnk@ file) at the given path. 128 | -- 129 | -- Returns a boolean representing whether or not the shortcut was created 130 | -- successfully. 131 | -- 132 | -- The @operation@ parameter specifies the action that will be taken and 133 | -- should be one of the following strings: 134 | -- 135 | -- * @"create"@ 136 | -- * Creates a new shortcut, overwriting if necessary. 137 | -- * @"update"@ 138 | -- * Updates specified properties only on an existing shortcut. 139 | -- * @"replace"@ 140 | -- * Overwrites an existing shortcut. 141 | -- * This action fails hard if the shortcut doesn't exist. 142 | -- 143 | -- NOTE: this function only works on Windows. 144 | foreign import javascript safe 145 | "$r = $1.writeShortcutLink($2, $3, $4);" 146 | unsafeWriteShortcutLink :: Shell 147 | -> Path 148 | -- ^ The path to write a shortcut file to. 149 | -> JSString 150 | -- ^ The @operation@ to perform. 151 | -> Object 152 | -- ^ The (serialized) 'ShortcutDetails' to use. 153 | -> IO Bool 154 | 155 | -- | Reads and parses a Windows shortcut (@.lnk@ file) at the given path. 156 | -- 157 | -- Returns the parsed 'ShortcutDetails' object. 158 | -- 159 | -- If any error occurs, an exception will be thrown. 160 | foreign import javascript safe 161 | "$r = $1.readShortcutLink($2);" 162 | unsafeReadShortcutLink :: Shell 163 | -> Path 164 | -- ^ The path of a shortcut file to read. 165 | -> IO Object 166 | -- ^ The (serialized) 'ShortcutDetails' read from 167 | -- the given path. 168 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/SystemPreferences.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.SystemPreferences where 5 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/Tray.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE ConstraintKinds #-} 2 | {-# LANGUAGE DataKinds #-} 3 | {-# LANGUAGE DeriveGeneric #-} 4 | {-# LANGUAGE ExistentialQuantification #-} 5 | {-# LANGUAGE GADTs #-} 6 | {-# LANGUAGE MultiParamTypeClasses #-} 7 | {-# LANGUAGE PolyKinds #-} 8 | {-# LANGUAGE Rank2Types #-} 9 | {-# LANGUAGE TypeFamilies #-} 10 | 11 | -- | FIXME: doc 12 | module GHCJS.Electron.Tray 13 | ( module Exported 14 | , module GHCJS.Electron.Tray 15 | ) where 16 | 17 | import Data.Ord 18 | import GHCJS.Electron.Types 19 | import GHCJS.Electron.Utility as Exported 20 | import GHCJS.Types 21 | 22 | import GHCJS.Node.EventEmitter 23 | 24 | -- | FIXME: doc 25 | data TrayIcon 26 | = TrayIconImage !Image 27 | | TrayIconPath !Path 28 | deriving (Generic) 29 | 30 | -- | FIXME: doc 31 | data TrayBalloonOptions 32 | = MkTrayBalloonOptions 33 | { icon :: Maybe TrayIcon 34 | , title :: Maybe JSString 35 | , content :: Maybe JSString 36 | } 37 | deriving (Generic) 38 | 39 | -- | FIXME: doc 40 | data TrayClickEvent 41 | = MkTrayClickEvent 42 | { altKey :: Bool 43 | , shiftKey :: Bool 44 | , ctrlKey :: Bool 45 | , metaKey :: Bool 46 | } 47 | deriving (Generic) 48 | 49 | -- | FIXME: doc 50 | data Point 51 | = MkPoint 52 | { pointX :: Int 53 | , pointY :: Int 54 | } 55 | deriving (Generic) 56 | 57 | -- | FIXME: doc 58 | data Rectangle 59 | = MkRectangle 60 | { rectangleX :: Int 61 | , rectangleY :: Int 62 | , rectangleWidth :: Int 63 | , rectangleHeight :: Int 64 | } 65 | deriving (Generic) 66 | 67 | -- | FIXME: doc 68 | data TrayEvent (platforms :: [Platform]) where 69 | TrayEventClick :: TrayClickEvent -- ^ event 70 | -> Rectangle -- ^ bounds 71 | -> TrayEvent '[Linux, Darwin, Win32] 72 | TrayEventRightClick :: TrayClickEvent -- ^ event 73 | -> Rectangle -- ^ bounds 74 | -> TrayEvent '[Darwin, Win32] 75 | TrayEventDoubleClick :: TrayClickEvent -- ^ event 76 | -> Rectangle -- ^ bounds 77 | -> TrayEvent '[Darwin, Win32] 78 | TrayEventBalloonShow :: TrayEvent '[Win32] 79 | TrayEventBalloonClick :: TrayEvent '[Win32] 80 | TrayEventBalloonClosed :: TrayEvent '[Win32] 81 | TrayEventDrop :: TrayEvent '[Darwin] 82 | TrayEventDropFiles :: Array Path -- ^ files 83 | -> TrayEvent '[Darwin] 84 | TrayEventDropText :: JSString -- ^ text 85 | -> TrayEvent '[Darwin] 86 | TrayEventDropEnter :: TrayEvent '[Darwin] 87 | TrayEventDropLeave :: TrayEvent '[Darwin] 88 | TrayEventDropEnd :: TrayEvent '[Darwin] 89 | 90 | -- | FIXME: doc 91 | data SomeTrayEvent 92 | = forall (platforms :: [Platform]). 93 | MkSomeTrayEvent (TrayEvent platforms) 94 | 95 | -- | Initialize a new 'Tray'. 96 | foreign import javascript safe 97 | "$r = new Tray($1);" 98 | trayNew :: Path -> IO Tray 99 | 100 | -- | Cast a 'Tray' to an 'EventEmitter TrayEvent'. 101 | foreign import javascript safe 102 | "$r = $1;" 103 | trayEventEmitter :: Tray -> IO (EventEmitter SomeTrayEvent) 104 | 105 | -- | Destroy the given 'Tray', freeing the associated resources. 106 | foreign import javascript safe 107 | "$1.destroy();" 108 | trayDestroy :: Tray -> IO () 109 | 110 | -- | Set the tray icon to the given 'Image'. 111 | foreign import javascript safe 112 | "$1.setImage($2);" 113 | traySetImage :: Tray -- ^ The tray to modify. 114 | -> Image -- ^ The image to set as the tray icon. 115 | -> IO () 116 | 117 | -- | Set the tray icon to the image file at the given 'Path'. 118 | foreign import javascript safe 119 | "$1.setImage($2);" 120 | traySetImagePath :: Tray -- ^ The tray to modify. 121 | -> Path -- ^ The path to an image to set as the tray icon. 122 | -> IO () 123 | 124 | -- | Set the "pressed" image for the tray to the given 'Image'. 125 | -- NOTE: this function only works on Mac OS 126 | foreign import javascript safe 127 | "$1.setPressedImage($2);" 128 | traySetPressedImage :: Tray -- ^ The tray to modify. 129 | -> Image -- ^ The image to set as the "pressed" image. 130 | -> IO () 131 | 132 | -- | Set the "title" to the given 'JSString'. 133 | -- NOTE: this function only works on Mac OS 134 | foreign import javascript safe 135 | "$1.setTitle($2);" 136 | traySetTitle :: Tray -- ^ The tray to modify. 137 | -> JSString -- ^ The title displayed next to the tray icon. 138 | -> IO () 139 | 140 | -- | Sets when the tray's icon background becomes highlighted (in blue). 141 | -- 142 | -- NOTE: You can use @highlightMode@ with a 'BrowserWindow' by toggling 143 | -- between @"never"@ and @"always"@ modes when the window visibility changes. 144 | -- 145 | -- NOTE: this function only works on Mac OS 146 | foreign import javascript safe 147 | "$1.setHighlightMode($2);" 148 | traySetHighlightMode :: Tray 149 | -- ^ The tray to modify. 150 | -> JSString 151 | -- ^ The mode to set. One of the following: 152 | -- * @"selection"@: Highlight the tray icon when it is 153 | -- clicked and also when its context menu is open. 154 | -- This is the default. 155 | -- * @"always"@: Always highlight the tray icon. 156 | -- * @"never"@: Never highlight the tray icon. 157 | -> IO () 158 | 159 | -- | Create a balloon popup ala Windows XP. 160 | -- NOTE: this function only works on Windows 161 | foreign import javascript safe 162 | "$1.displayBalloon();" 163 | trayDisplayBalloon :: Tray -- ^ The tray to modify. 164 | -> JSString -- ^ The title displayed next to the tray icon. 165 | -> IO () 166 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/Types.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DataKinds #-} 2 | {-# LANGUAGE DeriveGeneric #-} 3 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} 4 | {-# LANGUAGE PolyKinds #-} 5 | 6 | module GHCJS.Electron.Types 7 | ( module GHCJS.Electron.Types 8 | , module Exported 9 | ) where 10 | 11 | import GHCJS.Array as Exported 12 | import GHCJS.Foreign.Callback as Exported 13 | import GHCJS.Types as Exported 14 | 15 | import Data.String as Exported (IsString) 16 | import GHC.Generics as Exported (Generic) 17 | 18 | import Data.JSString (JSString) 19 | 20 | -------------------------------------------------------------------------------- 21 | 22 | -- | A constructor-less type for use in phantom type arguments. 23 | data Any 24 | 25 | -------------------------------------------------------------------------------- 26 | 27 | -- | FIXME: doc 28 | data Platform 29 | = PlatLinux -- ^ FIXME: doc 30 | | PlatMacOS -- ^ FIXME: doc 31 | | PlatWindows -- ^ FIXME: doc 32 | deriving (Eq, Generic) 33 | 34 | -- | FIXME: doc 35 | type Linux = 'PlatLinux 36 | 37 | -- | FIXME: doc 38 | type Win32 = 'PlatWindows 39 | 40 | -- | FIXME: doc 41 | type Darwin = 'PlatMacOS 42 | 43 | -------------------------------------------------------------------------------- 44 | 45 | -- | FIXME: doc 46 | newtype URL 47 | = MkURL JSString 48 | deriving (IsString, Generic) 49 | 50 | -- | FIXME: doc 51 | newtype Path 52 | = MkPath JSString 53 | deriving (IsString, Generic) 54 | 55 | -- | Text representing a Windows path reference. 56 | -- 57 | -- Path references differ from plain old paths insofar as they can include 58 | -- environment variables. 59 | newtype WindowsPathRef 60 | = MkWindowsPathRef JSString 61 | deriving (IsString, Generic) 62 | 63 | -- | FIXME: doc 64 | newtype HTML 65 | = MkHTML JSString 66 | deriving (IsString, Generic) 67 | 68 | -- | FIXME: doc 69 | newtype RTF 70 | = MkRTF JSString 71 | deriving (IsString, Generic) 72 | 73 | -------------------------------------------------------------------------------- 74 | 75 | -- | A string representing a key combination. 76 | newtype Accelerator 77 | = MkAccelerator JSString 78 | deriving (IsString) 79 | 80 | -- | FIXME: doc 81 | newtype App 82 | = MkApp JSVal 83 | 84 | -- | FIXME: doc 85 | newtype Bookmark 86 | = MkBookmark JSVal 87 | 88 | -- | FIXME: doc 89 | newtype BrowserWindow 90 | = MkBrowserWindow JSVal 91 | 92 | -- | FIXME: doc 93 | newtype BrowserWindowProxy 94 | = MkBrowserWindowProxy JSVal 95 | 96 | -- | FIXME: doc 97 | newtype Clipboard 98 | = MkClipboard JSVal 99 | 100 | -- | FIXME: doc 101 | newtype CommandLine 102 | = MkCommandLine JSVal 103 | 104 | -- | FIXME: doc 105 | newtype Dialog 106 | = MkDialog JSVal 107 | 108 | -- | FIXME: doc 109 | newtype Event 110 | = MkEvent JSVal 111 | 112 | -- | FIXME: doc 113 | newtype Error 114 | = MkError JSVal 115 | 116 | -- | FIXME: doc 117 | newtype GlobalShortcut 118 | = MkGlobalShortcut JSVal 119 | 120 | -- | FIXME: doc 121 | newtype Image 122 | = MkImage JSVal 123 | 124 | -- | FIXME: doc 125 | newtype IPCMain 126 | = MkIPCMain JSVal 127 | 128 | -- | FIXME: doc 129 | newtype IPCRenderer 130 | = MkIPCRenderer JSVal 131 | 132 | -- | FIXME: doc 133 | newtype Proxy 134 | = MkProxy JSVal 135 | 136 | -- | FIXME: doc 137 | newtype Tray 138 | = MkTray JSVal 139 | 140 | -------------------------------------------------------------------------------- 141 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/Utility.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE ExplicitNamespaces #-} 2 | 3 | module GHCJS.Electron.Utility 4 | ( module GHCJS.Electron.Utility 5 | , module Exported 6 | ) where 7 | 8 | import Data.Kind as Exported (type Type, Constraint) 9 | import GHC.TypeLits as Exported (Symbol) 10 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/WebContents.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.WebContents where 5 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/WebFrame.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.WebFrame where 5 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/WebRequest.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.WebRequest where 5 | -------------------------------------------------------------------------------- /src/GHCJS/Electron/Window.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | FIXME: doc 4 | module GHCJS.Electron.Window where 5 | 6 | import GHCJS.Electron.Types 7 | import GHCJS.Types 8 | 9 | -- | Open a new window with the URL set to the given string. 10 | foreign import javascript safe 11 | "$r = window.open($1);" 12 | open :: JSString -- ^ URL 13 | -> IO BrowserWindowProxy 14 | 15 | -- | Open a new window with the given URL, frame name, and features string. 16 | foreign import javascript safe 17 | "$r = window.open($1, $2, $3);" 18 | openFull :: JSString -- ^ URL 19 | -> JSString -- ^ Frame name 20 | -> JSString -- ^ Features 21 | -> IO BrowserWindowProxy 22 | -------------------------------------------------------------------------------- /src/GHCJS/Node/Buffer.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | An implementation of the NodeJS Buffer API, as documented 4 | -- . 5 | module GHCJS.Node.Buffer 6 | ( module GHCJS.Node.Buffer -- FIXME: specific export list 7 | ) where 8 | 9 | import GHCJS.Array 10 | import GHCJS.Foreign.Callback 11 | import GHCJS.Types 12 | 13 | -- | FIXME: doc 14 | newtype Buffer 15 | = MkBuffer JSVal 16 | 17 | -- | Allocate a 'Buffer' of the given size in bytes. The buffer will be filled 18 | -- with zeroes initially. 19 | foreign import javascript safe 20 | "$r = Buffer.alloc($1);" 21 | unsafeAlloc :: Int -- ^ The desired length of the new 'Buffer'. 22 | -> IO Buffer -- ^ The resulting 'Buffer'. 23 | 24 | -- | FIXME: doc 25 | foreign import javascript safe 26 | "$r = Buffer.byteLength($1, $2);" 27 | unsafeStringByteLength :: JSString -- ^ The input string. 28 | -> JSString -- ^ The encoding to use. 29 | -> IO Int -- ^ The number of bytes in the string. 30 | -- | FIXME: doc 31 | foreign import javascript safe 32 | "$r = Buffer.byteLength($1);" 33 | unsafeBufferByteLength :: Buffer -- ^ The input buffer. 34 | -> IO Int -- ^ The number of bytes in the buffer. 35 | -- | FIXME: doc 36 | foreign import javascript safe 37 | "$r = Buffer.compare($1, $2);" 38 | unsafeCompare :: Buffer -- ^ The first buffer. 39 | -> Buffer -- ^ The second buffer. 40 | -> IO JSVal -- ^ FIXME: doc 41 | 42 | -- | Concatenate all of the buffers in a given array. 43 | foreign import javascript safe 44 | "$r = Buffer.concat($1);" 45 | unsafeConcat :: Array Buffer -- ^ An array of buffers to concatenate. 46 | -> IO Buffer -- ^ The concatenated result. 47 | 48 | -- FIXME: wrap Buffer.from 49 | -- FIXME: wrap Buffer.isBuffer 50 | -- FIXME: wrap Buffer.isEncoding 51 | -- FIXME: wrap Buffer.poolSize 52 | -- FIXME: wrap .compare 53 | -- FIXME: wrap .copy 54 | -- FIXME: wrap .entries 55 | -- FIXME: wrap .equals 56 | -- FIXME: wrap .includes 57 | -- FIXME: wrap .indexOf 58 | -- FIXME: wrap .keys 59 | -- FIXME: wrap .lastIndexOf 60 | -- FIXME: wrap .length 61 | -- FIXME: wrap .readDoubleBE(offset[, noAssert]) 62 | -- FIXME: wrap .readDoubleLE(offset[, noAssert]) 63 | -- FIXME: wrap .readFloatBE(offset[, noAssert]) 64 | -- FIXME: wrap .readFloatLE(offset[, noAssert]) 65 | -- FIXME: wrap .readInt8(offset[, noAssert]) 66 | -- FIXME: wrap .readInt16BE(offset[, noAssert]) 67 | -- FIXME: wrap .readInt16LE(offset[, noAssert]) 68 | -- FIXME: wrap .readInt32BE(offset[, noAssert]) 69 | -- FIXME: wrap .readInt32LE(offset[, noAssert]) 70 | -- FIXME: wrap .readIntBE(offset, byteLength[, noAssert]) 71 | -- FIXME: wrap .readIntLE(offset, byteLength[, noAssert]) 72 | -- FIXME: wrap .readUInt8(offset[, noAssert]) 73 | -- FIXME: wrap .readUInt16BE(offset[, noAssert]) 74 | -- FIXME: wrap .readUInt16LE(offset[, noAssert]) 75 | -- FIXME: wrap .readUInt32BE(offset[, noAssert]) 76 | -- FIXME: wrap .readUInt32LE(offset[, noAssert]) 77 | -- FIXME: wrap .readUIntBE(offset, byteLength[, noAssert]) 78 | -- FIXME: wrap .readUIntLE(offset, byteLength[, noAssert]) 79 | -- FIXME: wrap .slice([start[, end]]) 80 | -- FIXME: wrap .swap16() 81 | -- FIXME: wrap .swap32() 82 | -- FIXME: wrap .swap64() 83 | -- FIXME: wrap .toJSON() 84 | -- FIXME: wrap .toString([encoding[, start[, end]]]) 85 | -- FIXME: wrap .values() 86 | -- FIXME: wrap .write(string[, offset[, length]][, encoding]) 87 | -- FIXME: wrap .writeDoubleBE(value, offset[, noAssert]) 88 | -- FIXME: wrap .writeDoubleLE(value, offset[, noAssert]) 89 | -- FIXME: wrap .writeFloatBE(value, offset[, noAssert]) 90 | -- FIXME: wrap .writeFloatLE(value, offset[, noAssert]) 91 | -- FIXME: wrap .writeInt8(value, offset[, noAssert]) 92 | -- FIXME: wrap .writeInt16BE(value, offset[, noAssert]) 93 | -- FIXME: wrap .writeInt16LE(value, offset[, noAssert]) 94 | -- FIXME: wrap .writeInt32BE(value, offset[, noAssert]) 95 | -- FIXME: wrap .writeInt32LE(value, offset[, noAssert]) 96 | -- FIXME: wrap .writeIntBE(value, offset, byteLength[, noAssert]) 97 | -- FIXME: wrap .writeIntLE(value, offset, byteLength[, noAssert]) 98 | -- FIXME: wrap .writeUInt8(value, offset[, noAssert]) 99 | -- FIXME: wrap .writeUInt16BE(value, offset[, noAssert]) 100 | -- FIXME: wrap .writeUInt16LE(value, offset[, noAssert]) 101 | -- FIXME: wrap .writeUInt32BE(value, offset[, noAssert]) 102 | -- FIXME: wrap .writeUInt32LE(value, offset[, noAssert]) 103 | -- FIXME: wrap .writeUIntBE(value, offset, byteLength[, noAssert]) 104 | -- FIXME: wrap .writeUIntLE(value, offset, byteLength[, noAssert]) 105 | 106 | -- | Fill the given target range in the given 'Buffer' with the contents of a 107 | -- given fill 'Buffer'. The target range is an inclusive-exclusive pair of 108 | -- integer offsets into the input buffer. If the target range is larger than 109 | -- the fill buffer, the fill buffer is repeated until it covers the entire 110 | -- input buffer, and this is then cropped to fit. 111 | -- 112 | -- The default start offset used in the bound function is @0@. 113 | -- The default end offset used in the bound function is the input buffer size. 114 | foreign import javascript safe 115 | "$1.fill($2, $3, $4);" 116 | unsafeFillBuffer :: Buffer -- ^ The input buffer. 117 | -> Buffer -- ^ The fill buffer. 118 | -> Int -- ^ The offset to start at (inclusive). 119 | -> Int -- ^ The offset to stop at (exclusive). 120 | -> IO () 121 | 122 | -- | Fill the given 'Buffer' with the given string, which is decoded using the 123 | -- given encoding. If the buffer is longer than the (encoded) fill string, the 124 | -- fill string will be repeated as many times as is necessary to cover the 125 | -- buffer, and is then cropped to fit. 126 | -- 127 | -- The default encoding used in the bound function is @"utf8"@. 128 | -- The default start offset used in the bound function is @0@. 129 | -- The default end offset used in the bound function is the input buffer size. 130 | foreign import javascript safe 131 | "$1.fill($2, $4, $5, $3);" 132 | unsafeFillString :: Buffer -- ^ The input buffer. 133 | -> JSString -- ^ The fill string. 134 | -> JSString -- ^ The fill string encoding. 135 | -> Int -- ^ The offset to start at (inclusive). 136 | -> Int -- ^ The offset to stop at (exclusive). 137 | -> IO () 138 | -------------------------------------------------------------------------------- /src/GHCJS/Node/Console.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | An implementation of the NodeJS Console API, as documented 4 | -- . 5 | module GHCJS.Node.Console 6 | ( module GHCJS.Node.Console -- FIXME: specific export list 7 | ) where 8 | 9 | import GHCJS.Array 10 | import GHCJS.Foreign 11 | import GHCJS.Foreign.Callback 12 | import GHCJS.Types 13 | 14 | -- | FIXME: doc 15 | newtype Console 16 | = MkConsole JSVal 17 | 18 | -- | FIXME: doc 19 | newtype StdoutStream 20 | = MkStdoutStream JSVal 21 | 22 | -- | FIXME: doc 23 | newtype StderrStream 24 | = MkStderrStream JSVal 25 | 26 | -- | FIXME: doc 27 | defaultStderrStream :: StderrStream 28 | defaultStderrStream = MkStderrStream jsUndefined 29 | 30 | -- | Returns the standard global 'Console' object, i.e.: the global variable 31 | -- named @console@ in a NodeJS execution context. 32 | foreign import javascript safe 33 | "$r = console;" 34 | unsafeDefaultConsole :: IO Console 35 | 36 | -- | Create a new 'Console' object using the given standard output and standard 37 | -- error stream objects. Pass 'defaultStderrStream' into this function if you 38 | -- want warning and error output to be send to the standard output stream. 39 | foreign import javascript safe 40 | "$r = new Console($1, $2);" 41 | unsafeMakeConsole :: StdoutStream 42 | -> StderrStream 43 | -> IO Console 44 | 45 | -- | If the given boolean is false, print the given message to the standard 46 | -- error stream of the given console and throw an @AssertionError@. 47 | -- If the given boolean is true, do nothing. 48 | foreign import javascript safe 49 | "$1.assert($2, $3);" 50 | unsafeAssert :: Console 51 | -> Bool 52 | -> JSString 53 | -> IO () 54 | 55 | -- FIXME: implement .dir 56 | 57 | -- | Print the given string to the standard output stream of the given console, 58 | -- with a newline appended. 59 | foreign import javascript safe 60 | "$1.log('%s', $2);" 61 | unsafeLog :: Console 62 | -> JSString 63 | -> IO () 64 | 65 | -- | Print the given string to the standard error stream of the given console, 66 | -- with a newline appended. 67 | foreign import javascript safe 68 | "$1.error('%s', $2);" 69 | unsafeError :: Console 70 | -> JSString 71 | -> IO () 72 | 73 | -- | Starts a timer that can be used to compute the duration of an operation. 74 | -- Timers are identified by a unique label string. Use the same label when 75 | -- you call 'unsafeTimeEnd' to stop the timer. Timer durations are accurate 76 | -- to the sub-millisecond. 77 | foreign import javascript safe 78 | "$1.time($2);" 79 | unsafeTimeStart :: Console 80 | -> JSString 81 | -> IO () 82 | 83 | -- | Stops a timer that was started with 'unsafeTimeStart'. The label string 84 | -- should match the one given when the timer was started. Once stopped, the 85 | -- time for the timer will be printed to the standard output stream of the 86 | -- given console. 87 | foreign import javascript safe 88 | "$1.timeEnd($2);" 89 | unsafeTimeEnd :: Console 90 | -> JSString 91 | -> IO () 92 | 93 | -- | Print the given message and stack trace to the standard error stream of 94 | -- the given console. 95 | foreign import javascript safe 96 | "$1.trace($2);" 97 | unsafeTrace :: Console 98 | -> JSString 99 | -> IO () 100 | -------------------------------------------------------------------------------- /src/GHCJS/Node/Crypto.hs: -------------------------------------------------------------------------------- 1 | -- | FIXME: doc 2 | module GHCJS.Node.Crypto 3 | ( module Exported 4 | ) where 5 | 6 | import GHCJS.Node.Crypto.Certificate as Exported 7 | import GHCJS.Node.Crypto.Cipher as Exported 8 | -- import GHCJS.Node.Crypto.Decipher as Exported 9 | import GHCJS.Node.Crypto.DiffieHellman as Exported 10 | import GHCJS.Node.Crypto.ECDH as Exported 11 | import GHCJS.Node.Crypto.Hash as Exported 12 | import GHCJS.Node.Crypto.HMAC as Exported 13 | import GHCJS.Node.Crypto.Sign as Exported 14 | import GHCJS.Node.Crypto.Verify as Exported 15 | -------------------------------------------------------------------------------- /src/GHCJS/Node/Crypto/Certificate.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | An implementation of the NodeJS Certificate API, as documented 4 | -- . 5 | module GHCJS.Node.Crypto.Certificate 6 | ( SPKAC (..), Challenge (..), PublicKey (..) 7 | , spkacChallenge, spkacPublicKey, spkacVerify 8 | ) where 9 | 10 | import GHCJS.Array 11 | import GHCJS.Foreign.Callback 12 | import GHCJS.Types 13 | 14 | import GHCJS.Node.Buffer 15 | 16 | -- | A SPKAC, or Signed Public Key and Challenge, is a buffer representing 17 | -- a certificate signing request. 18 | newtype SPKAC 19 | = MkSPKAC Buffer 20 | 21 | -- | A Challenge is a buffer representing the challenge component of a SPKAC. 22 | newtype Challenge 23 | = MkChallenge Buffer 24 | 25 | -- | A PublicKey is a buffer representing the public key component of a SPKAC. 26 | newtype PublicKey 27 | = MkPublicKey Buffer 28 | 29 | -- | Given a 'SPKAC', returns the challenge component. 30 | foreign import javascript safe 31 | "$r = crypto.Certificate().exportChallenge($1);" 32 | spkacChallenge :: SPKAC 33 | -> IO Challenge 34 | 35 | -- | Given a 'SPKAC', returns the public key component. 36 | foreign import javascript safe 37 | "$r = crypto.Certificate().exportPublicKey($1);" 38 | spkacPublicKey :: SPKAC 39 | -> IO PublicKey 40 | 41 | -- | Given a 'SPKAC', return @True@ if it is valid and @False@ otherwise. 42 | foreign import javascript safe 43 | "$r = crypto.Certificate().verifySpkac($1);" 44 | spkacVerify :: SPKAC 45 | -> IO Bool 46 | -------------------------------------------------------------------------------- /src/GHCJS/Node/Crypto/Cipher.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | An implementation of the NodeJS Cipher API, as documented 4 | -- . 5 | module GHCJS.Node.Crypto.Cipher 6 | ( module GHCJS.Node.Crypto.Cipher -- FIXME: specific export list 7 | ) where 8 | 9 | import GHCJS.Array 10 | import GHCJS.Foreign.Callback 11 | import GHCJS.Types 12 | 13 | import GHCJS.Node.Buffer 14 | import GHCJS.Node.Stream 15 | 16 | -- | FIXME: doc 17 | newtype Cipher 18 | = MkCipher JSVal 19 | 20 | instance IsReadStream Cipher where 21 | toReadStream (MkCipher val) = MkReadStream val 22 | 23 | instance IsWriteStream Cipher where 24 | toWriteStream (MkCipher val) = MkWriteStream val 25 | 26 | -- | Create a cipher object using the given algorithm, key, and initialization 27 | -- vector, each of which is a UTF-8 encoded string. 28 | -- 29 | -- Valid values for the @algorithm@ argument can be seen by running 30 | -- @openssl list-cipher-algorithm@. 31 | foreign import javascript safe 32 | "$r = crypto.createCipheriv($1, $2, $3);" 33 | unsafeCreateCipherIV :: JSString -- ^ @algorithm@ 34 | -> JSString -- ^ @key@ 35 | -> JSString -- ^ @iv@ 36 | -> IO Cipher -- ^ Resultant cipher object. 37 | 38 | -- | Returns any remaining enciphered contents from the given 'Cipher'. 39 | foreign import javascript safe 40 | "$r = $1.final();" 41 | unsafeFinal :: Cipher 42 | -> IO Buffer 43 | 44 | -- | Update the cipher with the given data. 45 | foreign import javascript safe 46 | "$r = $1.update($2);" 47 | unsafeUpdate :: Cipher 48 | -> Buffer 49 | -> IO Buffer 50 | 51 | -- | When using an authenticated encryption mode (only @GCM@ is currently 52 | -- supported), this function sets the value used for the additional 53 | -- authenticated data (AAD) input parameter. 54 | foreign import javascript safe 55 | "$1.setAAD($2);" 56 | unsafeSetAAD :: Cipher 57 | -> Buffer 58 | -> IO () 59 | 60 | -- | When using an authenticated encryption mode (only @GCM@ is currently 61 | -- supported), this function returns a 'Buffer' containing the authentication 62 | -- tag that has been computed from the input data. 63 | -- 64 | -- This function should only be called after encryption has been completed 65 | -- using the @cipher.final()@ method (called by 'unsafeFinal' and friends). 66 | foreign import javascript safe 67 | "$r = $1.getAuthTag();" 68 | unsafeGetAuthTag :: Cipher 69 | -> IO Buffer 70 | 71 | -- | Sets the value of the @auto_padding@ boolean attribute on a 'Cipher'. 72 | -- 73 | -- When using block encryption algorithms, a 'Cipher' will automatically add 74 | -- padding to the input data to the appropriate block size. 75 | -- 76 | -- When @auto_padding@ is false, the length of the entire input data must be a 77 | -- multiple of the cipher's block size or cipher.final() will throw an error. 78 | -- Disabling automatic padding is useful for non-standard padding, for 79 | -- instance using @0x0@ instead of PKCS padding. 80 | -- 81 | -- This function should only be called before encryption has been completed 82 | -- using the @cipher.final()@ method (called by 'unsafeFinal' and friends). 83 | foreign import javascript safe 84 | "$1.setAutoPadding($2);" 85 | unsafeSetAutoPadding :: Cipher 86 | -> Bool 87 | -> IO () 88 | -------------------------------------------------------------------------------- /src/GHCJS/Node/Crypto/Decipher.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | An implementation of the NodeJS Decipher API, as documented 4 | -- . 5 | module GHCJS.Node.Crypto.Decipher 6 | ( module GHCJS.Node.Crypto.Decipher -- FIXME: specific export list 7 | ) where 8 | 9 | import GHCJS.Array 10 | import GHCJS.Foreign.Callback 11 | import GHCJS.Types 12 | 13 | import GHCJS.Node.Buffer 14 | import GHCJS.Node.Stream 15 | 16 | -- FIXME: figure out a reasonable way to avoid the duplication between this 17 | -- module and GHCJS.Node.Crypto.Cipher 18 | 19 | -- | FIXME: doc 20 | newtype Decipher 21 | = MkDecipher JSVal 22 | 23 | instance IsReadStream Decipher where 24 | toReadStream (MkDecipher val) = MkReadStream val 25 | 26 | instance IsWriteStream Decipher where 27 | toWriteStream (MkDecipher val) = MkWriteStream val 28 | 29 | -- | Create a 'Decipher' object using the given algorithm, key, and IV 30 | -- (initialization vector), each of which is a UTF-8 encoded string. 31 | -- 32 | -- Valid values for the @algorithm@ argument can be seen by running 33 | -- @openssl list-cipher-algorithm@. 34 | foreign import javascript safe 35 | "$r = crypto.createDecipheriv($1, $2, $3);" 36 | unsafeCreateDecipherIV :: JSString -- ^ @algorithm@ 37 | -> JSString -- ^ @key@ 38 | -> JSString -- ^ @iv@ 39 | -> IO Decipher -- ^ Resultant 'Decipher' object. 40 | 41 | -- | Returns any remaining deciphered contents from the given 'Decipher'. 42 | foreign import javascript safe 43 | "$r = $1.final();" 44 | unsafeFinal :: Decipher 45 | -> IO Buffer 46 | 47 | -- | Update the 'Decipher' with the given data. 48 | foreign import javascript safe 49 | "$r = $1.update($2);" 50 | unsafeUpdate :: Decipher 51 | -> Buffer 52 | -> IO Buffer 53 | 54 | -- | When using an authenticated encryption mode (only @GCM@ is currently 55 | -- supported), this function sets the value used for the additional 56 | -- authenticated data (AAD) input parameter. 57 | foreign import javascript safe 58 | "$1.setAAD($2);" 59 | unsafeSetAAD :: Decipher 60 | -> Buffer 61 | -> IO () 62 | 63 | -- | When using an authenticated encryption mode (only @GCM@ is currently 64 | -- supported), this function returns a 'Buffer' containing the authentication 65 | -- tag that has been computed from the input data. 66 | -- 67 | -- This function should only be called after encryption has been completed 68 | -- using the @decipher.final()@ method (called by 'unsafeFinal' and friends). 69 | foreign import javascript safe 70 | "$r = $1.getAuthTag();" 71 | unsafeGetAuthTag :: Decipher 72 | -> IO Buffer 73 | 74 | -- | Sets the value of the @auto_padding@ boolean attribute on a 'Decipher'. 75 | -- 76 | -- When using block encryption algorithms, a 'Decipher' will automatically add 77 | -- padding to the input data to the appropriate block size. 78 | -- 79 | -- When @auto_padding@ is false, the length of the entire input data must be a 80 | -- multiple of the cipher block size or decipher.final() will throw an error. 81 | -- Disabling automatic padding is useful for non-standard padding, for 82 | -- instance using @0x0@ instead of PKCS padding. 83 | -- 84 | -- This function should only be called before encryption has been completed 85 | -- using the @decipher.final()@ method (called by 'unsafeFinal' and friends). 86 | foreign import javascript safe 87 | "$1.setAutoPadding($2);" 88 | unsafeSetAutoPadding :: Decipher 89 | -> Bool 90 | -> IO () 91 | -------------------------------------------------------------------------------- /src/GHCJS/Node/Crypto/DiffieHellman.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | An implementation of the NodeJS DiffieHellman API, as documented 4 | -- . 5 | module GHCJS.Node.Crypto.DiffieHellman 6 | ( module GHCJS.Node.Crypto.DiffieHellman -- FIXME: specific export list 7 | ) where 8 | 9 | import GHCJS.Array 10 | import GHCJS.Foreign.Callback 11 | import GHCJS.Types 12 | 13 | import GHCJS.Node.Buffer 14 | import GHCJS.Node.Stream 15 | 16 | -- | FIXME: doc 17 | newtype DiffieHellman 18 | = MkDiffieHellman JSVal 19 | 20 | -- | FIXME: doc 21 | foreign import javascript safe 22 | "$r = crypto.createDiffieHellman($1, $2);" 23 | unsafeCreateDiffieHellman :: Int -- ^ @prime_length@ 24 | -> Buffer -- ^ @generator@ 25 | -> IO DiffieHellman 26 | 27 | -- | FIXME: doc 28 | foreign import javascript safe 29 | "$r = crypto.createDiffieHellman($1, 'buffer', $2, 'buffer');" 30 | unsafeCreateDiffieHellmanWithPrime :: Buffer -- ^ @prime@ 31 | -> Buffer -- ^ @generator@ 32 | -> IO DiffieHellman 33 | 34 | -- FIXME: implement .computeSecret 35 | -- FIXME: implement .generateKeys 36 | -- FIXME: implement .getGenerator 37 | -- FIXME: implement .getPrime 38 | -- FIXME: implement .getPrivateKey 39 | -- FIXME: implement .getPublicKey 40 | -- FIXME: implement .setPrivateKey 41 | -- FIXME: implement .setPublicKey 42 | -- FIXME: implement .verifyError 43 | -------------------------------------------------------------------------------- /src/GHCJS/Node/Crypto/ECDH.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | An implementation of the NodeJS elliptic-curve Diffie-Hellman API, as 4 | -- documented . 5 | module GHCJS.Node.Crypto.ECDH 6 | ( module GHCJS.Node.Crypto.ECDH -- FIXME: specific export list 7 | ) where 8 | 9 | import GHCJS.Array 10 | import GHCJS.Foreign.Callback 11 | import GHCJS.Types 12 | 13 | -- | An Elliptic Curve Diffie-Hellman (ECDH) key exchange object. 14 | newtype ECDH 15 | = MkECDH JSVal 16 | 17 | -- | Creates an Elliptic Curve Diffie-Hellman (ECDH) key exchange object using a 18 | -- predefined curve specified by the given string. Use 'unsafeGetCurves' to 19 | -- obtain a list of available curve names. 20 | -- 21 | -- On recent OpenSSL releases, @openssl ecparam -list_curves@ will also 22 | -- display the name and description of each available elliptic curve. 23 | foreign import javascript safe 24 | "$r = crypto.createECDH($1);" 25 | unsafeCreateECDH :: JSString -- ^ @curve_name@ 26 | -> IO ECDH 27 | 28 | -- | Get a list of supported elliptic curve names. 29 | foreign import javascript safe 30 | "$r = crypto.getCurves();" 31 | unsafeGetCurves :: IO (Array JSString) 32 | 33 | -- FIXME: implement .computeSecret 34 | -- FIXME: implement .generateKeys 35 | -- FIXME: implement .getPrivateKey 36 | -- FIXME: implement .getPublicKey 37 | -- FIXME: implement .setPrivateKey 38 | -------------------------------------------------------------------------------- /src/GHCJS/Node/Crypto/HMAC.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | An implementation of the NodeJS HMAC API, as documented 4 | -- . 5 | module GHCJS.Node.Crypto.HMAC 6 | ( module GHCJS.Node.Crypto.HMAC -- FIXME: specific export list 7 | ) where 8 | 9 | import GHCJS.Array 10 | import GHCJS.Foreign.Callback 11 | import GHCJS.Types 12 | 13 | -- FIXME: implement crypto.createHmac 14 | -- FIXME: implement .digest 15 | -- FIXME: implement .update 16 | -------------------------------------------------------------------------------- /src/GHCJS/Node/Crypto/Hash.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | An implementation of the NodeJS hashing API, as documented 4 | -- . 5 | module GHCJS.Node.Crypto.Hash 6 | ( module GHCJS.Node.Crypto.Hash -- FIXME: specific export list 7 | ) where 8 | 9 | import GHCJS.Array 10 | import GHCJS.Foreign.Callback 11 | import GHCJS.Types 12 | 13 | -- FIXME: implement crypto.createHash 14 | -- FIXME: implement .digest 15 | -- FIXME: implement .update 16 | -------------------------------------------------------------------------------- /src/GHCJS/Node/Crypto/Sign.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | An implementation of the NodeJS signing API, as documented 4 | -- . 5 | module GHCJS.Node.Crypto.Sign 6 | ( module GHCJS.Node.Crypto.Sign -- FIXME: specific export list 7 | ) where 8 | 9 | import GHCJS.Array 10 | import GHCJS.Foreign.Callback 11 | import GHCJS.Types 12 | 13 | -- FIXME: implement crypto.createSign 14 | -- FIXME: implement .sign 15 | -- FIXME: implement .update 16 | -------------------------------------------------------------------------------- /src/GHCJS/Node/Crypto/Verify.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | An implementation of the NodeJS signature verification API, as documented 4 | -- . 5 | module GHCJS.Node.Crypto.Verify 6 | ( module GHCJS.Node.Crypto.Verify -- FIXME: specific export list 7 | ) where 8 | 9 | import GHCJS.Array 10 | import GHCJS.Foreign.Callback 11 | import GHCJS.Types 12 | 13 | -- FIXME: implement crypto.createVerify 14 | -- FIXME: implement .verify 15 | -- FIXME: implement .update 16 | -------------------------------------------------------------------------------- /src/GHCJS/Node/DNS.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | An implementation of the NodeJS DNS API, as documented 4 | -- . 5 | -- 6 | -- Note that there are special factors that must be taken into account when 7 | -- using this API; these considerations are documented 8 | -- . 9 | module GHCJS.Node.DNS 10 | ( module GHCJS.Node.DNS -- FIXME: specific export list 11 | ) where 12 | 13 | import GHCJS.Array 14 | import GHCJS.Callback 15 | import GHCJS.Foreign 16 | import GHCJS.Nullable 17 | import GHCJS.Types 18 | 19 | import JavaScript.Object 20 | 21 | import GHCJS.Node.Error 22 | 23 | import Data.Coerce 24 | 25 | -------------------------------------------------------------------------------- 26 | 27 | import Data.Text (Text) 28 | import Data.Set (Set) 29 | 30 | -------------------------------------------------------------------------------- 31 | 32 | -- | FIXME: doc 33 | data DNSRecord 34 | = DNSRecordA !DNSRecordA 35 | | DNSRecordAAAA !DNSRecordAAAA 36 | | DNSRecordCNAME !DNSRecordCNAME 37 | | DNSRecordMX !DNSRecordMX 38 | | DNSRecordNAPTR !DNSRecordNAPTR 39 | | DNSRecordNS !DNSRecordNS 40 | | DNSRecordPTR !DNSRecordPTR 41 | | DNSRecordSOA !DNSRecordSOA 42 | | DNSRecordSRV !DNSRecordSRV 43 | | DNSRecordTXT !DNSRecordTXT 44 | 45 | -- | FIXME: doc 46 | data DNSRecordType 47 | = DNSRecordTypeA 48 | | DNSRecordTypeAAAA 49 | | DNSRecordTypeCNAME 50 | | DNSRecordTypeMX 51 | | DNSRecordTypeNAPTR 52 | | DNSRecordTypeNS 53 | | DNSRecordTypePTR 54 | | DNSRecordTypeSOA 55 | | DNSRecordTypeSRV 56 | | DNSRecordTypeTXT 57 | 58 | -- | FIXME: doc 59 | data DNSRecordA 60 | = MkDNSRecordA 61 | { _DNSRecordA_address :: !Address 62 | , _DNSRecordA_ttl :: !Int 63 | } 64 | 65 | -- | FIXME: doc 66 | data DNSRecordAAAA 67 | = MkDNSRecordAAAA 68 | { _DNSRecordAAAA_address :: !Address 69 | , _DNSRecordAAAA_ttl :: !Int 70 | } 71 | 72 | -- | FIXME: doc 73 | data DNSRecordCNAME 74 | = MkDNSRecordCNAME 75 | { _DNSRecordCNAME_hostname :: !HostName 76 | } 77 | 78 | -- | FIXME: doc 79 | toDNSRecordCNAME :: RecordCNAME -> DNSRecordCNAME 80 | toDNSRecordCNAME (MkRecordCNAME hostname) = MkDNSRecordCNAME hostname 81 | 82 | -- | FIXME: doc 83 | data DNSRecordMX 84 | = MkDNSRecordMX 85 | { _DNSRecordMX_priority :: !Int 86 | , _DNSRecordMX_exchange :: !HostName 87 | } 88 | 89 | -- | An NAPTR record flag as defined in 90 | -- . 91 | data NAPTRFlag 92 | = NAPTRFlagS 93 | | NAPTRFlagA 94 | | NAPTRFlagU 95 | | NAPTRFlagP 96 | 97 | -- | A regular expression for NAPTR records as defined in 98 | -- . 99 | -- 100 | -- Grammar: 101 | -- subst_expr = delim-char ere delim-char repl delim-char *flags 102 | -- delim-char = "/" / "!" / ... 105 | -- ere = POSIX Extended Regular Expression 106 | -- repl = 1 * ( OCTET / backref ) 107 | -- backref = "\" 1POS_DIGIT 108 | -- flags = "i" 109 | -- POS_DIGIT = %x31-39 ; 0 is not an allowed backref 110 | -- 111 | -- FIXME: improve type safety 112 | type NAPTRRegex = Text 113 | 114 | -- | FIXME: doc 115 | data DNSRecordNAPTR 116 | = MkDNSRecordNAPTR 117 | { _DNSRecordNAPTR_flags :: !(Set NAPTRFlag) 118 | , _DNSRecordNAPTR_service :: !Service 119 | , _DNSRecordNAPTR_regexp :: !NAPTRRegex 120 | , _DNSRecordNAPTR_replacement :: !Text 121 | , _DNSRecordNAPTR_order :: !Int 122 | , _DNSRecordNAPTR_preference :: !Int 123 | } 124 | 125 | -- | FIXME: doc 126 | data DNSRecordNS 127 | = MkDNSRecordNS 128 | { _DNSRecordNS_hostname :: !HostName 129 | } 130 | 131 | -- | FIXME: doc 132 | toDNSRecordNS :: RecordNS -> DNSRecordNS 133 | toDNSRecordNS (MkRecordNS hostname) = MkDNSRecordNS hostname 134 | 135 | -- | FIXME: doc 136 | data DNSRecordPTR 137 | = MkDNSRecordPTR 138 | { _DNSRecordPTR_hostname :: !HostName 139 | } 140 | 141 | -- | FIXME: doc 142 | toDNSRecordPTR :: RecordPTR -> DNSRecordPTR 143 | toDNSRecordPTR (MkRecordPTR hostname) = MkDNSRecordPTR hostname 144 | 145 | -- | FIXME: doc 146 | data DNSRecordSOA 147 | = MkDNSRecordSOA 148 | { _DNSRecordSOA_nsname :: !HostName 149 | , _DNSRecordSOA_hostmaster :: !HostName 150 | , _DNSRecordSOA_serial :: !Int 151 | , _DNSRecordSOA_refresh :: !Int 152 | , _DNSRecordSOA_retry :: !Int 153 | , _DNSRecordSOA_expire :: !Int 154 | , _DNSRecordSOA_minttl :: !Int 155 | } 156 | 157 | -- | FIXME: doc 158 | data DNSRecordSRV 159 | = MkDNSRecordSRV 160 | { _DNSRecordSRV_priority :: !Int 161 | , _DNSRecordSRV_weight :: !Int 162 | , _DNSRecordSRV_port :: !Int 163 | , _DNSRecordSRV_name :: !HostName 164 | } 165 | 166 | -- | FIXME: doc 167 | data DNSRecordTXT 168 | = MkDNSRecordTXT 169 | { _DNSRecordTXT_chunks :: ![Text] 170 | } 171 | 172 | -------------------------------------------------------------------------------- 173 | 174 | -- | FIXME: doc 175 | newtype HostName 176 | = MkHostName JSString 177 | 178 | -- | FIXME: doc 179 | fromHostName :: HostName -> Text 180 | fromHostName = undefined -- FIXME: implement 181 | 182 | -- | FIXME: doc 183 | toHostName :: Text -> HostName 184 | toHostName = undefined -- FIXME: implement 185 | 186 | -------------------------------------------------------------------------------- 187 | 188 | -- | FIXME: doc 189 | newtype Address 190 | = MkAddress JSString 191 | 192 | -- | FIXME: doc 193 | fromAddress :: Address -> Text 194 | fromAddress = undefined -- FIXME: implement 195 | 196 | -- | FIXME: doc 197 | toAddress :: Text -> Address 198 | toAddress = undefined -- FIXME: implement 199 | 200 | -------------------------------------------------------------------------------- 201 | 202 | -- | FIXME: doc 203 | newtype Service 204 | = MkService JSString 205 | 206 | -- | FIXME: doc 207 | fromService :: Service -> Text 208 | fromService = undefined -- FIXME: implement 209 | 210 | -- | FIXME: doc 211 | toService :: Text -> Service 212 | toService = undefined -- FIXME: implement 213 | 214 | -------------------------------------------------------------------------------- 215 | 216 | -- | FIXME: doc 217 | type Port = Int 218 | 219 | -------------------------------------------------------------------------------- 220 | 221 | -- | FIXME: doc 222 | newtype Hints 223 | = MkHints JSVal 224 | 225 | -- | FIXME: doc 226 | foreign import javascript unsafe 227 | "$r = dns.ADDRCONFIG;" 228 | hintADDRCONFIG :: Hints 229 | 230 | -- | FIXME: doc 231 | foreign import javascript unsafe 232 | "$r = dns.V4MAPPED;" 233 | hintV4MAPPED :: Hints 234 | 235 | -- | FIXME: doc 236 | foreign import javascript unsafe 237 | "$r = (($1) | ($2));" 238 | hintCombine :: Hints -> Hints -> Hints 239 | 240 | -------------------------------------------------------------------------------- 241 | 242 | -- | The type of IP address families (i.e.: IPv4 versus IPv6). 243 | newtype Family 244 | = MkFamily JSVal 245 | 246 | -- | The address family representing IPv4 addresses. 247 | foreign import javascript unsafe "$r = 4;" 248 | familyIPv4 :: Family 249 | 250 | -- | The address family representing IPv6 addresses. 251 | foreign import javascript unsafe "$r = 6;" 252 | familyIPv6 :: Family 253 | 254 | -- -- | Parse an arbitrary 'JSVal' into a 'Family'. 255 | -- parseFamily :: JSVal -> Maybe Family 256 | -- parseFamily val = if val == ip4 257 | -- then Just familyIPv4 258 | -- else if val == ip6 259 | -- then Just familyIPv6 260 | -- else Nothing 261 | -- where 262 | -- ip4 = (pToJSVal familyIPv4) :: JSVal 263 | -- ip6 = (pToJSVal familyIPv6) :: JSVal 264 | -- FIXME: reimplement properly 265 | 266 | -------------------------------------------------------------------------------- 267 | 268 | -- | FIXME: doc 269 | newtype Resolved 270 | = MkResolved Object 271 | 272 | -- | FIXME: doc 273 | fromResolved :: Resolved -> (Address, Family) 274 | fromResolved = undefined -- FIXME: implement 275 | 276 | -- | FIXME: doc 277 | toResolved :: (Address, Family) -> Resolved 278 | toResolved = undefined -- FIXME: implement 279 | 280 | -------------------------------------------------------------------------------- 281 | 282 | -- | FIXME: doc 283 | -- @{address: "1.2.3.4", ttl: 60}@ 284 | newtype RecordA 285 | = MkRecordA Object 286 | 287 | -- | FIXME: doc 288 | -- @{address: "1.2.3.4", ttl: 60}@ 289 | newtype RecordAAAA 290 | = MkRecordAAAA Object 291 | 292 | -- | FIXME: doc 293 | -- @"bar.example.com"@ 294 | newtype RecordCNAME 295 | = MkRecordCNAME HostName 296 | 297 | -- | FIXME: doc 298 | -- @{priority: 10, exchange: "mx.example.com"}@ 299 | newtype RecordMX 300 | = MkRecordMX Object 301 | 302 | -- | FIXME: doc 303 | -- { 304 | -- flags: "s", 305 | -- service: "SIP+D2U", 306 | -- regexp: "", 307 | -- replacement: "_sip._udp.example.com", 308 | -- order: 30, 309 | -- preference: 100 310 | -- } 311 | newtype RecordNAPTR 312 | = MkRecordNAPTR Object 313 | 314 | -- | FIXME: doc 315 | -- @"ns1.example.com"@ 316 | newtype RecordNS 317 | = MkRecordNS HostName 318 | 319 | -- | FIXME: doc 320 | -- @"mail.example.com"@ 321 | newtype RecordPTR 322 | = MkRecordPTR HostName 323 | 324 | -- | FIXME: doc 325 | -- { 326 | -- nsname: "ns.example.com", 327 | -- hostmaster: "root.example.com", 328 | -- serial: 2013101809, 329 | -- refresh: 10000, 330 | -- retry: 2400, 331 | -- expire: 604800, 332 | -- minttl: 3600 333 | -- } 334 | newtype RecordSOA 335 | = MkRecordSOA Object 336 | 337 | -- | FIXME: doc 338 | -- { 339 | -- priority: 10, 340 | -- weight: 5, 341 | -- port: 21223, 342 | -- name: "service.example.com" 343 | -- } 344 | newtype RecordSRV 345 | = MkRecordSRV Object 346 | 347 | -- | FIXME: doc 348 | -- @["v=spf1 ip4:0.0.0.0 ", "~all"]@ 349 | newtype RecordTXT 350 | = MkRecordTXT (Array JSString) 351 | 352 | -------------------------------------------------------------------------------- 353 | 354 | -- | Returns an array of all the IP addresses, encoded as strings, that are 355 | -- being used for name resolution. 356 | foreign import javascript safe 357 | "$r = dns.getServers();" 358 | unsafeGetServers :: IO (Array Address) 359 | 360 | -- | Resolves the given hostname (e.g.: @"nodejs.org"@) into the first found 361 | -- A (IPv4) or AAAA (IPv6) record. 362 | -- 363 | -- This function is equivalent to @dns.lookup(…, {…, all: false}, …)@. 364 | -- 365 | -- In the returned value, either the 'Error' object is defined or the rest of 366 | -- the values are. 367 | foreign import javascript interruptible 368 | "dns.lookup($1, {family: $2, hints: $3, all: false}, function(e, a, f) { $c(e, a, f); });" 369 | unsafeLookup :: HostName 370 | -> Family 371 | -> Hints 372 | -> IO (Nullable Error, Nullable Address, Nullable Family) 373 | 374 | -- | Resolves the given hostname (e.g.: @"nodejs.org"@) into the first found 375 | -- A (IPv4) or AAAA (IPv6) record. 376 | -- 377 | -- This function is equivalent to @dns.lookup(…, {…, all: true}, …)@. 378 | foreign import javascript interruptible 379 | "dns.lookup($1, {family: $2, hints: $3, all: true}, function(e, r) { $c(e, r); });" 380 | unsafeLookupAll :: HostName 381 | -> Family 382 | -> Hints 383 | -> IO (Nullable Error, Nullable (Array Resolved)) 384 | 385 | -- | Resolves the given address and port into a hostname and service using the 386 | -- operating system's underlying @getnameinfo@ implementation. 387 | -- 388 | -- In the returned value, either the 'Error' object is defined or the rest of 389 | -- the values are. 390 | foreign import javascript interruptible 391 | "dns.lookupService($1, $2, function(e, h, s) { $c(e, h, s); });" 392 | unsafeLookupService :: HostName 393 | -> Port 394 | -> IO (Nullable Error, Nullable HostName, Nullable Service) 395 | 396 | -- | Uses the DNS protocol to resolve the A records for the given hostname. 397 | -- 398 | -- In the returned value, either the 'Error' object is defined or the rest of 399 | -- the values are. 400 | foreign import javascript interruptible 401 | "dns.resolve4($1, {ttl: true}, function(e, a) { $c(e, a); });" 402 | unsafeResolveA :: HostName 403 | -> IO (Nullable Error, Nullable (Array RecordA)) 404 | 405 | -- | Uses the DNS protocol to resolve the AAAA records for the given hostname. 406 | -- 407 | -- In the returned value, either the 'Error' object is defined or the rest of 408 | -- the values are. 409 | foreign import javascript interruptible 410 | "dns.resolve6($1, {ttl: true}, function(e, a) { $c(e, a); });" 411 | unsafeResolveAAAA :: HostName 412 | -> IO (Nullable Error, Nullable (Array RecordAAAA)) 413 | 414 | -- | Uses the DNS protocol to resolve the CNAME records for the given hostname. 415 | -- 416 | -- In the returned value, either the 'Error' object is defined or the rest of 417 | -- the values are. 418 | foreign import javascript interruptible 419 | "dns.resolveCname($1, function(e, a) { $c(e, a); });" 420 | unsafeResolveCNAME :: HostName 421 | -> IO (Nullable Error, Nullable (Array RecordCNAME)) 422 | 423 | -- | Uses the DNS protocol to resolve the MX records for the given hostname. 424 | -- 425 | -- In the returned value, either the 'Error' object is defined or the rest of 426 | -- the values are. 427 | foreign import javascript interruptible 428 | "dns.resolveMx($1, function(e, a) { $c(e, a); });" 429 | unsafeResolveMX :: HostName 430 | -> IO (Nullable Error, Nullable (Array RecordMX)) 431 | 432 | -- | Uses the DNS protocol to resolve the NAPTR records for the given hostname. 433 | -- 434 | -- In the returned value, either the 'Error' object is defined or the rest of 435 | -- the values are. 436 | foreign import javascript interruptible 437 | "dns.resolveNaptr($1, function(e, a) { $c(e, a); });" 438 | unsafeResolveNAPTR :: HostName 439 | -> IO (Nullable Error, Nullable (Array RecordNAPTR)) 440 | 441 | -- | Uses the DNS protocol to resolve the NS records for the given hostname. 442 | -- 443 | -- In the returned value, either the 'Error' object is defined or the rest of 444 | -- the values are. 445 | foreign import javascript interruptible 446 | "dns.resolveNs($1, function(e, a) { $c(e, a); });" 447 | unsafeResolveNS :: HostName 448 | -> IO (Nullable Error, Nullable (Array RecordNS)) 449 | 450 | -- | Uses the DNS protocol to resolve the PTR records for the given hostname. 451 | -- 452 | -- In the returned value, either the 'Error' object is defined or the rest of 453 | -- the values are. 454 | foreign import javascript interruptible 455 | "dns.resolvePtr($1, function(e, a) { $c(e, a); });" 456 | unsafeResolvePTR :: HostName 457 | -> IO (Nullable Error, Nullable (Array RecordPTR)) 458 | 459 | -- | Uses the DNS protocol to resolve the SOA records for the given hostname. 460 | -- 461 | -- In the returned value, either the 'Error' object is defined or the rest of 462 | -- the values are. 463 | foreign import javascript interruptible 464 | "dns.resolveSoa($1, function(e, a) { $c(e, a); });" 465 | unsafeResolveSOA :: HostName 466 | -> IO (Nullable Error, Nullable (Array RecordSOA)) 467 | 468 | -- | Uses the DNS protocol to resolve the SRV records for the given hostname. 469 | -- 470 | -- In the returned value, either the 'Error' object is defined or the rest of 471 | -- the values are. 472 | foreign import javascript interruptible 473 | "dns.resolveSrv($1, function(e, a) { $c(e, a); });" 474 | unsafeResolveSRV :: HostName 475 | -> IO (Nullable Error, Nullable (Array RecordSRV)) 476 | 477 | -- | Uses the DNS protocol to resolve the TXT records for the given hostname. 478 | -- 479 | -- In the returned value, either the 'Error' object is defined or the rest of 480 | -- the values are. 481 | foreign import javascript interruptible 482 | "dns.resolveTxt($1, function(e, a) { $c(e, a); });" 483 | unsafeResolveTXT :: HostName 484 | -> IO (Nullable Error, Nullable (Array RecordTXT)) 485 | 486 | -- | Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an 487 | -- array of hostnames. 488 | -- 489 | -- The 'Error' object contains a field named @code@ of type 'DNSError'. 490 | -- 491 | -- In the returned value, either the 'Error' object is defined or the rest of 492 | -- the values are. 493 | foreign import javascript interruptible 494 | "dns.reverse($1, function(e, h) { $c(e, h); });" 495 | unsafeReverse :: Address 496 | -> IO (Nullable Error, Nullable (Array HostName)) 497 | 498 | -- | Sets the IP addresses of the servers to be used when resolving. 499 | -- The @servers@ argument is an array of IPv4 or IPv6 addresses. 500 | -- 501 | -- If a port is specified on the address, it will be removed. 502 | -- 503 | -- An error will be thrown if an invalid address is provided. 504 | -- 505 | -- This function must not be called while a DNS query is in progress. 506 | foreign import javascript safe 507 | "dns.setServers($1);" 508 | unsafeSetServers :: Array Address 509 | -> IO () 510 | 511 | -------------------------------------------------------------------------------- 512 | 513 | -- | A DNS error code. 514 | newtype DNSError 515 | = MkDNSError JSString 516 | 517 | -- | DNS error: "DNS server returned answer with no data." 518 | foreign import javascript unsafe "$r = dns.NODATA;" 519 | dnsNODATA :: DNSError 520 | 521 | -- | DNS error: "DNS server claims query was misformatted." 522 | foreign import javascript unsafe "$r = dns.FORMERR;" 523 | dnsFORMERR :: DNSError 524 | 525 | -- | DNS error: "DNS server returned general failure." 526 | foreign import javascript unsafe "$r = dns.SERVFAIL;" 527 | dnsSERVFAIL :: DNSError 528 | 529 | -- | DNS error: "Domain name not found." 530 | foreign import javascript unsafe "$r = dns.NOTFOUND;" 531 | dnsNOTFOUND :: DNSError 532 | 533 | -- | DNS error: "DNS server does not implement this operation." 534 | foreign import javascript unsafe "$r = dns.NOTIMP;" 535 | dnsNOTIMP :: DNSError 536 | 537 | -- | DNS error: "DNS server refused query." 538 | foreign import javascript unsafe "$r = dns.REFUSED;" 539 | dnsREFUSED :: DNSError 540 | 541 | -- | DNS error: "Misformatted DNS query." 542 | foreign import javascript unsafe "$r = dns.BADQUERY;" 543 | dnsBADQUERY :: DNSError 544 | 545 | -- | DNS error: "Misformatted hostname." 546 | foreign import javascript unsafe "$r = dns.BADNAME;" 547 | dnsBADNAME :: DNSError 548 | 549 | -- | DNS error: "Unsupported address family." 550 | foreign import javascript unsafe "$r = dns.BADFAMILY;" 551 | dnsBADFAMILY :: DNSError 552 | 553 | -- | DNS error: "Misformatted DNS reply." 554 | foreign import javascript unsafe "$r = dns.BADRESP;" 555 | dnsBADRESP :: DNSError 556 | 557 | -- | DNS error: "Could not contact DNS servers." 558 | foreign import javascript unsafe "$r = dns.CONNREFUSED;" 559 | dnsCONNREFUSED :: DNSError 560 | 561 | -- | DNS error: "Timeout while contacting DNS servers." 562 | foreign import javascript unsafe "$r = dns.TIMEOUT;" 563 | dnsTIMEOUT :: DNSError 564 | 565 | -- | DNS error: "End of file." 566 | foreign import javascript unsafe "$r = dns.EOF;" 567 | dnsEOF :: DNSError 568 | 569 | -- | DNS error: "Error reading file." 570 | foreign import javascript unsafe "$r = dns.FILE;" 571 | dnsFILE :: DNSError 572 | 573 | -- | DNS error: "Out of memory." 574 | foreign import javascript unsafe "$r = dns.NOMEM;" 575 | dnsNOMEM :: DNSError 576 | 577 | -- | DNS error: "Channel is being destroyed." 578 | foreign import javascript unsafe "$r = dns.DESTRUCTION;" 579 | dnsDESTRUCTION :: DNSError 580 | 581 | -- | DNS error: "Misformatted string." 582 | foreign import javascript unsafe "$r = dns.BADSTR;" 583 | dnsBADSTR :: DNSError 584 | 585 | -- | DNS error: "Illegal flags specified." 586 | foreign import javascript unsafe "$r = dns.BADFLAGS;" 587 | dnsBADFLAGS :: DNSError 588 | 589 | -- | DNS error: "Given hostname is not numeric." 590 | foreign import javascript unsafe "$r = dns.NONAME;" 591 | dnsNONAME :: DNSError 592 | 593 | -- | DNS error: "Illegal hints flags specified." 594 | foreign import javascript unsafe "$r = dns.BADHINTS;" 595 | dnsBADHINTS :: DNSError 596 | 597 | -- | DNS error: "@c-ares@ initialization not yet performed." 598 | foreign import javascript unsafe "$r = dns.NOTINITIALIZED;" 599 | dnsNOTINITIALIZED :: DNSError 600 | 601 | -- | DNS error: "Error loading @iphlpapi.dll@." 602 | foreign import javascript unsafe "$r = dns.LOADIPHLPAPI;" 603 | dnsLOADIPHLPAPI :: DNSError 604 | 605 | -- | DNS error: "Could not find @GetNetworkParams@ function." 606 | foreign import javascript unsafe "$r = dns.ADDRGETNETWORKPARAMS;" 607 | dnsADDRGETNETWORKPARAMS :: DNSError 608 | 609 | -- | DNS error: "DNS query cancelled." 610 | foreign import javascript unsafe "$r = dns.CANCELLED;" 611 | dnsCANCELLED :: DNSError 612 | 613 | -------------------------------------------------------------------------------- 614 | -------------------------------------------------------------------------------- /src/GHCJS/Node/Error.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | An implementation of the NodeJS Error API, as documented 4 | -- . 5 | module GHCJS.Node.Error 6 | ( module GHCJS.Node.Error -- FIXME: specific export list 7 | ) where 8 | 9 | import GHCJS.Array 10 | import GHCJS.Foreign.Callback 11 | import GHCJS.Types 12 | 13 | -- | FIXME: doc 14 | newtype Error 15 | = MkError JSVal 16 | -------------------------------------------------------------------------------- /src/GHCJS/Node/EventEmitter.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FunctionalDependencies #-} 2 | {-# LANGUAGE JavaScriptFFI #-} 3 | {-# LANGUAGE MultiParamTypeClasses #-} 4 | 5 | -- | An implementation of the NodeJS EventEmitter API, as documented 6 | -- . 7 | module GHCJS.Node.EventEmitter 8 | ( module GHCJS.Node.EventEmitter -- FIXME: specific export list 9 | ) where 10 | 11 | import GHCJS.Array 12 | import GHCJS.Foreign.Callback 13 | import GHCJS.Types 14 | 15 | import JavaScript.JSON.Types (Value) 16 | 17 | -- FIXME: maybe move this stuff to GHCJS.Electron.Event? 18 | 19 | -- | FIXME: doc 20 | newtype Event 21 | = MkEvent JSVal 22 | 23 | -- | FIXME: doc 24 | foreign import javascript safe 25 | "$1.returnValue = $2;" 26 | unsafeSetReturnValue :: Event 27 | -> Value 28 | -> IO () 29 | 30 | -- | FIXME: doc 31 | foreign import javascript safe 32 | "$r = $1.sender;" 33 | unsafeGetSender :: Event 34 | -> IO JSVal 35 | 36 | -- | FIXME: doc 37 | foreign import javascript safe 38 | "(function(obj) { obj.send.apply(obj, [$2] + $3); })($1.sender);" 39 | unsafeReply :: Event 40 | -> JSString -- should be GHCJS.Electron.Types.Channel instead 41 | -> Array Value 42 | -> IO () 43 | 44 | -- | The name of an IPC channel. 45 | newtype Channel 46 | = MkChannel JSString 47 | 48 | -- | An instance of the NodeJS EventEmitter class. 49 | newtype EventEmitter event 50 | = MkEventEmitter JSVal 51 | 52 | -- | A typeclass representing types that can be converted to an 'EventEmitter' 53 | -- for a given event type. 54 | class IsEventEmitter event emitter | emitter -> event where 55 | -- | Convert the given value to an 'EventEmitter'. 56 | toEventEmitter :: emitter -> IO (EventEmitter event) 57 | 58 | -- FIXME: functions not yet implemented: 59 | -- - @removeListener(event: string, listener: Function): App;@ 60 | -- - @removeAllListeners(event?: string): App;@ 61 | -- - @listeners(event: string): Function[];@ 62 | -- - @emit(event: string, ...args: any[]): boolean;@ 63 | -- - @listenerCount(type: string): number;@ 64 | 65 | -- | Listen for the given event and run the given callback whenever it occurs. 66 | foreign import javascript safe 67 | "$1.on($2, $3);" 68 | unsafeListenerOn :: EventEmitter event 69 | -> JSString 70 | -> Callback (JSString -> IO ()) 71 | -> IO () 72 | 73 | -- | Listen for the given event and run the given callback exactly once; 74 | -- i.e.: the callback will be run precisely the first time the event occurs 75 | -- after this function is run. 76 | foreign import javascript safe 77 | "$1.once($2, (function() { return $3(arguments); }));" 78 | unsafeListenerOnce :: EventEmitter event 79 | -> JSString 80 | -> Callback (Array JSVal -> IO ()) 81 | -> IO () 82 | 83 | -- | Remove all listeners on the given 'EventEmitter'. 84 | foreign import javascript safe 85 | "$1.removeAllListeners();" 86 | unsafeRemoveAllListeners :: EventEmitter event -> IO () 87 | 88 | -- | Remove all listeners for the given event on the given 'EventEmitter'. 89 | foreign import javascript safe 90 | "$1.removeAllListeners($2);" 91 | unsafeRemoveAllListenersOnEvent :: EventEmitter event -> JSString -> IO () 92 | 93 | -- | Set the maximum number of listeners for events on the given 'EventEmitter' 94 | -- to the given natural number. 95 | foreign import javascript safe 96 | "$1.setMaxListeners($2);" 97 | unsafeSetMaxListeners :: EventEmitter event -> Int -> IO () 98 | 99 | -- | Get the maximum number of listeners for events on the given 'EventEmitter', 100 | -- as set by 'appSetMaxListeners'. 101 | foreign import javascript safe 102 | "$r = $1.getMaxListeners();" 103 | unsafeGetMaxListeners :: EventEmitter event -> IO Int 104 | 105 | -- | Get the number of listeners for an event on the given 'EventEmitter'. 106 | foreign import javascript safe 107 | "$r = $1.listenerCount($2);" 108 | unsafeListenerCount :: EventEmitter event -> JSString -> IO Int 109 | -------------------------------------------------------------------------------- /src/GHCJS/Node/Stream.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE JavaScriptFFI #-} 2 | 3 | -- | An implementation of the NodeJS Stream API, as documented 4 | -- . 5 | module GHCJS.Node.Stream 6 | ( module GHCJS.Node.Stream -- FIXME: specific export list 7 | ) where 8 | 9 | import GHCJS.Array 10 | import GHCJS.Foreign.Callback 11 | import GHCJS.Types 12 | 13 | -- | FIXME: doc 14 | newtype ReadStream 15 | = MkReadStream JSVal 16 | 17 | -- | FIXME: doc 18 | newtype WriteStream 19 | = MkWriteStream JSVal 20 | 21 | -- | FIXME: doc 22 | newtype DuplexStream 23 | = MkDuplexStream JSVal 24 | 25 | -- | FIXME: doc 26 | newtype TransformStream 27 | = MkTransformStream 28 | { fromTransformStream :: DuplexStream 29 | -- ^ FIXME: doc 30 | } 31 | 32 | -- | FIXME: doc 33 | class IsWriteStream stream where 34 | -- | FIXME: doc 35 | toWriteStream :: stream -> WriteStream 36 | 37 | -- | FIXME: doc 38 | class IsReadStream stream where 39 | -- | FIXME: doc 40 | toReadStream :: stream -> ReadStream 41 | 42 | instance IsWriteStream WriteStream where 43 | toWriteStream = id 44 | 45 | instance IsWriteStream DuplexStream where 46 | toWriteStream (MkDuplexStream val) = MkWriteStream val 47 | 48 | instance IsReadStream ReadStream where 49 | toReadStream = id 50 | 51 | instance IsReadStream DuplexStream where 52 | toReadStream (MkDuplexStream val) = MkReadStream val 53 | -------------------------------------------------------------------------------- /src/Tests.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE OverloadedStrings #-} 2 | 3 | module Main where 4 | 5 | import Control.Monad (void) 6 | 7 | import Data.JSString 8 | 9 | import qualified GHCJS.Electron.Accelerator as Accelerator 10 | import qualified GHCJS.Electron.BrowserWindowProxy as BrowserWindowProxy 11 | import qualified GHCJS.Electron.Clipboard as Clipboard 12 | import qualified GHCJS.Electron.GlobalShortcut as GlobalShortcut 13 | import qualified GHCJS.Electron.Shell as Shell 14 | import qualified GHCJS.Electron.Tray as Tray 15 | import qualified GHCJS.Electron.Window as Window 16 | 17 | testWindow :: IO () 18 | testWindow = void $ do 19 | bwp <- Window.open "https://google.com" 20 | BrowserWindowProxy.browserBlur bwp 21 | BrowserWindowProxy.browserEval bwp "alert(\"DEBUG!\");" 22 | BrowserWindowProxy.browserClose bwp 23 | 24 | -- testTray :: IO () 25 | -- testTray = void $ do 26 | -- Tray.trayNew "" 27 | 28 | testClipboard :: IO () 29 | testClipboard = void $ do 30 | cb <- Clipboard.unsafeGetClipboard "clipboard" 31 | -- Clipboard.unsafeAvailableFormats cb >>= print 32 | Clipboard.unsafeWriteText cb "DEBUG" 33 | Clipboard.unsafeReadText cb >>= print 34 | 35 | testGlobalShortcut :: IO () 36 | testGlobalShortcut = void $ do 37 | gs <- GlobalShortcut.unsafeGetGlobalShortcut 38 | GlobalShortcut.unsafeRegister gs "Shift+5" undefined 39 | 40 | testShell :: IO () 41 | testShell = void $ do 42 | sh <- Shell.unsafeGetShell 43 | Shell.unsafeBeep sh 44 | -- Shell.unsafeShowItemInFolder sh "/etc/nixos/configuration.nix" 45 | Shell.unsafeOpenItem sh "/etc/nixos/configuration.nix" 46 | Shell.unsafeOpenExternal sh "https://archive.org" 47 | -- FIXME: test Shell.unsafeOpenExternalDarwin 48 | -- FIXME: test Shell.unsafeMoveItemToTrash 49 | -- FIXME: test Shell.unsafeWriteShortcutLink 50 | -- FIXME: test Shell.unsafeReadShortcutLink 51 | 52 | main :: IO () 53 | main = do 54 | testWindow 55 | -- testTray 56 | testClipboard 57 | testGlobalShortcut 58 | testShell 59 | --------------------------------------------------------------------------------