on master help sign in
It initializes
commitc177ad13898fc0e2b2ed1b4347c6b73e64310d13 authoriko <ilyakooo0@gmail.com> dateSat 23 Jul 2022, 17:19 (4 years ago) parent0793483
4 files changed+39−68
backend/Main.purs+11 bw/src/BW.js+14−67 bw/src/BW.purs+13−1 spago.dhall+1
backend/Main.purs+11
@@ -4,6 +4,7 @@ import Prelude
44
55import BW as WB
66import Bridge (Sub(..))
7+import Data.Nullable (null)
78import Effect (Effect)
89import Effect.Console (log)
910import Elm as Elm
@@ -13,6 +14,16 @@ import FFI as FFI
1314main :: Effect Unit
1415main = do
1516 bwAPI <- WB.getAPI
17+ { base : null,
18+ webVault : null,
19+ api : null,
20+ identity : null,
21+ icons : null,
22+ notifications : null,
23+ events : null,
24+ keyConnector : null
25+ }
26+
1627 app <- FFI.startElm "elm"
1728 Elm.subscribe app \c -> log $ "Got cmd"
1829 Elm.send app Hello
bw/src/BW.js+14−67
@@ -7,16 +7,19 @@ import { EnvironmentService } from "../../deps/bw/libs/shared/dist/src/services/
77import { StateMigrationService } from "../../deps/bw/libs/shared/dist/src/services/stateMigration.service";
88import { TokenService } from "../../deps/bw/libs/shared/dist/src/services/token.service";
99import { WebCryptoFunctionService } from "../../deps/bw/libs/shared/dist/src/services/webCryptoFunction.service";
10+import { Account, AccountSettings } from "../../deps/bw/libs/shared/dist/src/models/domain/account";
1011
1112// import BrowserStorageService from "../../deps/bw/libs/shared/dist/src/services/browserStorage.service";
1213import { CryptoService } from "../../deps/bw/libs/shared/dist/src/abstractions/crypto.service";
1314import { I18nService } from "../../deps/bw/libs/shared/dist/src/services/i18n.service";
1415import { StateService } from "../../deps/bw/libs/shared/dist/src/services/state.service";
1516
16−export function getAPI() {
17+export function getAPI(urls) {
1718 return function () {
1819 const bg = new MainBackground()
1920
21+ bg.environmentService.setUrls(urls)
22+
2023 return bg.apiService
2124 }
2225}
@@ -38,11 +41,9 @@ class MainBackground {
3841 stateMigrationService; //: StateMigrationService;
3942
4043
41− constructor(isPrivateMode = false) {
44+ constructor() {
4245
43− this.messagingService = isPrivateMode
44− ? new BrowserMessagingPrivateModeBackgroundService()
45− : new BrowserMessagingService();
46+ this.messagingService = new BrowserMessagingService();
4647 this.storageService = new BrowserStorageService();
4748 this.logService = new ConsoleLogService(false);
4849 this.stateMigrationService = new StateMigrationService(
@@ -79,7 +80,7 @@ class MainBackground {
7980 }
8081 }
8182 );
82− this.i18nService = new I18nService(BrowserApi.getUILanguage(window));
83+ this.i18nService = new I18nService("en");
8384 this.cryptoFunctionService = new WebCryptoFunctionService(window);
8485 this.cryptoService = new BrowserCryptoService(
8586 this.cryptoFunctionService,
@@ -135,7 +136,7 @@ class BrowserStorageService {
135136 }
136137
137138 async get(key) {
138− return resolve(JSON.parse(this.storage.getItem(key)));
139+ return JSON.parse(this.storage.getItem(key));
139140 }
140141
141142 async has(key) {
@@ -175,13 +176,6 @@ class BrowserMessagingService {
175176 }
176177}
177178
178−class BrowserMessagingPrivateModeBackgroundService {
179− send(subscriber, arg = {}) {
180− const message = Object.assign({}, { command: subscriber }, arg);
181− window.bitwardenPopupMainMessageListener(message);
182− }
183−}
184−
185179class BrowserPlatformUtilsService {
186180 constructor(messagingService, stateService, clipboardWriteCallback, biometricCallback) {
187181 this.messagingService = messagingService;
@@ -194,31 +188,7 @@ class BrowserPlatformUtilsService {
194188 this.prefersColorSchemeDark = window.matchMedia("(prefers-color-scheme: dark)");
195189 }
196190 getDevice() {
197− if (this.deviceCache) {
198− return this.deviceCache;
199− }
200− if (navigator.userAgent.indexOf(" Firefox/") !== -1 ||
201− navigator.userAgent.indexOf(" Gecko/") !== -1) {
202− this.deviceCache = DeviceType.FirefoxExtension;
203− }
204− else if ((!!window.opr && !!opr.addons) ||
205− !!window.opera ||
206− navigator.userAgent.indexOf(" OPR/") >= 0) {
207− this.deviceCache = DeviceType.OperaExtension;
208− }
209− else if (navigator.userAgent.indexOf(" Edg/") !== -1) {
210− this.deviceCache = DeviceType.EdgeExtension;
211− }
212− else if (navigator.userAgent.indexOf(" Vivaldi/") !== -1) {
213− this.deviceCache = DeviceType.VivaldiExtension;
214− }
215− else if (window.chrome && navigator.userAgent.indexOf(" Chrome/") !== -1) {
216− this.deviceCache = DeviceType.ChromeExtension;
217− }
218− else if (navigator.userAgent.indexOf(" Safari/") !== -1) {
219− this.deviceCache = DeviceType.SafariExtension;
220− }
221− return this.deviceCache;
191+ return 9; // Chrome
222192 }
223193 getDeviceString() {
224194 const device = DeviceType[this.getDevice()].toLowerCase();
@@ -252,33 +222,19 @@ class BrowserPlatformUtilsService {
252222 return false;
253223 }
254224 isViewOpen() {
255− return __awaiter(this, void 0, void 0, function* () {
256− if (yield BrowserApi.isPopupOpen()) {
257− return true;
258− }
259− if (this.isSafari()) {
260− return false;
261− }
262− const sidebarView = this.sidebarViewName();
263− const sidebarOpen = sidebarView != null && chrome.extension.getViews({ type: sidebarView }).length > 0;
264− if (sidebarOpen) {
265− return true;
266− }
267− const tabOpen = chrome.extension.getViews({ type: "tab" }).length > 0;
268− return tabOpen;
269− });
225+ return true;
270226 }
271227 lockTimeout() {
272228 return null;
273229 }
274230 launchUri(uri, options) {
275− BrowserApi.createNewTab(uri, options && options.extensionPage === true);
231+ // BrowserApi.createNewTab(uri, options && options.extensionPage === true);
276232 }
277233 saveFile(win, blobData, blobOptions, fileName) {
278− BrowserApi.downloadFile(win, blobData, blobOptions, fileName);
234+ // BrowserApi.downloadFile(win, blobData, blobOptions, fileName);
279235 }
280236 getApplicationVersion() {
281− return Promise.resolve(BrowserApi.getApplicationVersion());
237+ // return Promise.resolve(BrowserApi.getApplicationVersion());
282238 }
283239 supportsWebAuthn(win) {
284240 return typeof PublicKeyCredential !== "undefined";
@@ -452,16 +408,7 @@ class BrowserPlatformUtilsService {
452408 });
453409 }
454410 supportsBiometric() {
455− return __awaiter(this, void 0, void 0, function* () {
456− const platformInfo = yield BrowserApi.getPlatformInfo();
457− if (platformInfo.os === "android") {
458− return false;
459− }
460− if (this.isFirefox()) {
461− return parseInt((yield browser.runtime.getBrowserInfo()).version.split(".")[0], 10) >= 87;
462− }
463− return true;
464− });
411+ return false;
465412 }
466413 authenticateBiometric() {
467414 return this.biometricCallback();
bw/src/BW.purs+13−1
@@ -6,6 +6,7 @@ import Control.Promise (Promise)
66import Data.Argonaut.Core (Json)
77import Data.Date (Date)
88import Data.List (List)
9+import Data.Nullable (Nullable)
910import Effect (Effect)
1011
1112type PreloginResponse = {
@@ -137,9 +138,20 @@ type ProviderUserType = Int
137138
138139type ProfileProviderOrganizationResponse = {}
139140
141+type Urls = {
142+ base :: Nullable String,
143+ webVault :: Nullable String,
144+ api :: Nullable String,
145+ identity :: Nullable String,
146+ icons :: Nullable String,
147+ notifications :: Nullable String,
148+ events :: Nullable String,
149+ keyConnector :: Nullable String
150+}
151+
140152type ApiService = {
141153 postPrelogin :: PreloginRequest -> Promise PreloginResponse,
142154 getProfile :: Unit -> Promise ProfileResponse
143155 }
144156
145−foreign import getAPI :: Effect ApiService
157+foreign import getAPI :: Urls -> Effect ApiService
spago.dhall+1
@@ -23,6 +23,7 @@ to generate this file without the comments in this block.
2323 , "either"
2424 , "maybe"
2525 , "newtype"
26+ , "nullable"
2627 , "prelude"
2728 ]
2829, packages = ./packages.dhall